achiku / planter

Generate PlantUML ER diagram textual description from PostgreSQL tables
MIT License
546 stars 53 forks source link

All relations are duplicated #12

Closed asitemade4u closed 3 years ago

asitemade4u commented 4 years ago

Hi, Thank you so very much for this very useful program!

Everything works well with one exception: all relations are duplicated and I cannot figure why. Here is a simple example from a much larger PostgreSQL database:

Here is the TAG DDL for TAG:


CREATE TABLE kuq.tag (
    tag_key int4 NOT NULL,
    ctg_key int4 NULL,
    tag varchar(60) NULL,
    CONSTRAINT tag_pk PRIMARY KEY (tag_key),
    CONSTRAINT tag_un UNIQUE (tag_key)
);
CREATE INDEX tag_tag_idx ON kuq.tag USING btree (tag);

ALTER TABLE kuq.tag ADD CONSTRAINT tag_fk FOREIGN KEY (ctg_key) REFERENCES kuq.ctg(ctg_key);

When I execute:

planter postgres://<connection>?sslmode=disable \
-s kuq    \
-t tag    \
-t ctg    \
-o test.uml

I get this PlantUML schema where the many to one link between TAG and CTG is duplicated:

image

And, in effect, the link is duplicated in the UML definition file:

@startuml

entity "ctg" {
  Tag Categories
  ..
  + ctg_key [PK]
  --
  ctg_key
  nam
  cmt
}

entity "tag" {
  Tags
  ..
  + tag_key [PK]
  --
  tag_key
  ctg_key
  tag
}

tag }-- ctg
tag }-- ctg

@enduml

What am I doing wrong? Best, Stephen

hiroakis commented 3 years ago

@asitemade4u I tried it with the current master branch at commit at commit c43fae77b770c653959dd2a0b3611dc89eddb19a , but couldn't reproduce it. Could you give me a full procedure?

# Run postgresql v12
docker run --rm -d -p 35432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust postgres:12-alpine

# connect
psql -U postgres -h localhost -p 35432 -d postgres

# create kuq schema
CREATE SCHEMA kuq;

# create tables
CREATE TABLE kuq.tag (
    tag_key int4 NOT NULL,
    ctg_key int4 NULL,
    tag varchar(60) NULL,
    CONSTRAINT tag_pk PRIMARY KEY (tag_key),
    CONSTRAINT tag_un UNIQUE (tag_key)
);
CREATE INDEX tag_tag_idx ON kuq.tag USING btree (tag);
CREATE TABLE kuq.ctg (
    ctg_key int4 NOT NULL,
    CONSTRAINT ctg_pk PRIMARY KEY (ctg_key)
);
ALTER TABLE kuq.tag ADD CONSTRAINT tag_fk FOREIGN KEY (ctg_key) REFERENCES kuq.ctg(ctg_key);
planter 'postgres://postgres@localhost:35432/postgres?sslmode=disable' -s kuq -t 'tag' -t 'ctg' -o test.html
@startuml
hide circle
skinparam linetype ortho

entity "ctg" {
  + ctg_key:integer [PK]
  --
}

entity "tag" {
  + tag_key:integer [PK]
  --
  ctg_key:integer [FK]
  tag:character varying(60)
}

 tag }-- ctg
@enduml
achiku commented 3 years ago

It seems like it's not happening in current version, so I'll close this issue. Thanks!

kurotych commented 2 years ago

Dirty fix https://github.com/minterest-finance/planter/commit/c8e10b3662c2c1cc692b3560eb9c489d0be24466