PgAdmin a generowanie Logical Model.

1

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?

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ę.

0

Metoda dla ubogich, ale zdesperowanych:

  1. Tworzymy sobie opis grafu w języku graphviza
  2. Wchodzimy na http://www.webgraphviz.com/
  3. Wklejamy definicję grafu i klikamy Generuj

Proof of concept:

  1. 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 );
  1. 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'
;
  1. 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"
  1. 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 ;-)

0

@yarel dzięki nie znałam tego rozwiązania, popatrzę może to będzie to czego mi potrzeba.:)

1 użytkowników online, w tym zalogowanych: 0, gości: 1