Mam schemat w którym mam kilka tabelek i jakieś tam constrainty na nich pozakładane. Chciała bym sobie do dokumentacji wygenerować schemat tak abym mogła pokazać laikowi która tabela z którą się łączy. W MS SQL i w Oracle jest taka możliwość generując Logical model. Na ile mogę liczyć w postgresie na coś takiego i czy w ogóle jest taka możliwość? Czy lepiej sobie wydziergać w Data modelerze i pokazać coś z DM?

- Rejestracja:około 15 lat
- Ostatnio:około 3 lata

- Rejestracja:ponad 13 lat
- Ostatnio:prawie 3 lata
0
Moje dość chyba kosztowne rozwiązanie:
https://www.visual-paradigm.com/support/documents/vpuserguide/3563/3587/85406_reverseengin.html

- Rejestracja:około 15 lat
- Ostatnio:około 3 lata
0
@vpiotr Visual Paradgim znam, miałam go na studiach, ale chyba lepszym rozwiązaniem jest darmowy Data Modeler. Zwłaszcza że potrzebuję tylko odwzorować to co mam w bazie, ale dzięki za podpowiedź zapomniałam zupełnie o tym narzędziu. :)
Generalnie zależy mi na tym żeby po prostu wyklikać model logiczny bezpośrednio z bazy a nie w drugą stronę.
edytowany 1x, ostatnio: kate87
- Rejestracja:prawie 10 lat
- Ostatnio:40 minut
- Postów:2367
0
Metoda dla ubogich, ale zdesperowanych:
- Tworzymy sobie opis grafu w języku graphviza
- Wchodzimy na http://www.webgraphviz.com/
- Wklejamy definicję grafu i klikamy Generuj
Proof of concept:
- Tworzymy tabelki w postgresie
create table parent1(parent_id serial primary key);
create table child1(child_id serial primary key, parent_id integer references parent1 );
create table grand_child1(grand_child_id serial primary key, child_id integer references child1 );
create table grand_child2(grand_child_id serial primary key, child_id integer references child1 );
create table child2(child_id serial primary key, parent_id integer references parent1 );
create table parent2(parent_id serial primary key);
create table child3(child_id serial primary key, parent_id integer references parent1 );
create table grand_child3(grand_child_id serial primary key, child_id integer references child2 );
create table grand_child4(grand_child_id serial primary key, child_id integer references child2 );
create table child4(child_id serial primary key, parent_id integer references parent1 );
- Wyciągamy z information_schema dane w postaci zrozumiałej przez graphviza (w tym przypadku tylko proste infor: nodeA -> nodeB )
(ja mam postgresa z dockera, więc w publicznym schemacie jest mało co...)
SELECT
'"'||tc.table_schema||'.'||tc.table_name||'" -> '||
'"'||ccu.table_schema||'.'||ccu.table_name||'"'
FROM
information_schema.table_constraints AS tc
JOIN information_schema.key_column_usage AS kcu
ON tc.constraint_name = kcu.constraint_name
AND tc.table_schema = kcu.table_schema
JOIN information_schema.constraint_column_usage AS ccu
ON ccu.constraint_name = tc.constraint_name
AND ccu.table_schema = tc.table_schema
WHERE constraint_type = 'FOREIGN KEY' and tc.table_schema='public'
;
- Wypluwa coś takiego:
"public.child1" -> "public.parent1"
"public.grand_child1" -> "public.child1"
"public.grand_child2" -> "public.child1"
"public.child2" -> "public.parent1"
"public.child3" -> "public.parent1"
"public.grand_child3" -> "public.child2"
"public.grand_child4" -> "public.child2"
"public.child4" -> "public.parent1"
- Wklejam to w znaczniki graphviza:
digraph g{
"public.child1" -> "public.parent1"
"public.grand_child1" -> "public.child1"
"public.grand_child2" -> "public.child1"
"public.child2" -> "public.parent1"
"public.child3" -> "public.parent1"
"public.grand_child3" -> "public.child2"
"public.grand_child4" -> "public.child2"
"public.child4" -> "public.parent1"
}
I generuje sobie prosty graf zależności...
Z information schema można wyciągnąć nazwy FK i mieć jako etykietki w grafie. Można dodać kolorki i inne pierdoły, jednak to już zabawa ;-)