Giter VIP home page Giter VIP logo

planter's Introduction

planter

test GitHub license Go Report Card

Generate PlantUML ER diagram textual description from PostgreSQL tables

Why created

A team with only software engineers doesn't need ER diagram that much as long as they have decent experience in Relational Database modeling. However, it becomes very helpful to have always-up-to-date ER diagram when marketing/promotion/operation teams consisting of those who are fluent in writing/reading SQL, join to the game.

PlantUML supports ER diagram in the latest version with this awesome pull request. The tool, planter, generates textual description of PlantUML ER diagram from pre-existing PostgreSQL tables, and makes it easy to share visual structure of relations with other teams.

Installation

go get -u github.com/achiku/planter

Quick Start

$ planter postgres://planter@localhost/planter?sslmode=disable -o example.uml
$ java -jar plantuml.jar -verbose example.uml

er diagram

Specify table names

planter postgres://planter@localhost/planter?sslmode=disable \ 
    -t order_detail \
    -t sku \
    -t product

Help

$ planter --help
usage: planter [<flags>] <conn>

Flags:
      --help                 Show context-sensitive help (also try --help-long and --help-man).
  -s, --schema="public"      PostgreSQL schema name
  -o, --output=OUTPUT        output file path
  -t, --table=TABLE ...      target tables
  -x, --exclude=EXCLUDE ...  target tables
  -T, --title=TITLE          Diagram title

Args:
  <conn>  PostgreSQL connection string in URL format

Test

Run on docker

make

or setup manually and run test

create database planter;
create user planter;

run go test ./... -v

planter's People

Contributors

achiku avatar apple314159 avatar hiroakis avatar mattn avatar mkorolyov avatar mmauger avatar skissane avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

planter's Issues

Not working column | ad.adsrc does not exist

exception
planter postgres://user:123@localhost/adatabase?sslmode=disable
2019/11/30 16:16:48 failed to get columns of chat: failed to load table def: pq: column ad.adsrc does not exist

environment
I am running PostgreSQL inside docker from the official docker image version 12.1-alpine
I have discovered it local and tried it inside the container so docker is probably not the issue.

Database structure
It also happens in the example from the repo.

Docker image?

Hello, is there a docker image available for this somewhere?

Would like to see more info about columns

Would like to see more info about columns

  • Type
  • If field[s] is indexed
  • Comment

My personal rules:

  • column definition: {name} {SQL type} [-- {comment}]
  • Primary keys should be in the header of each table
  • Foreign keys should be marked with + (will be displayed as green dot) with reference in comment
  • Indexed fields should be marked as bold
  • Comments starts with --
  • Comments for table should be put in header of each table
  • Relationships should be placed

Extracting cross-schema tables

Hi!

Great project, I'm really liking it! I just used to to run it on our live system and it's absolutely fantastic, specially for onboarding new folks :)

I just just wanted to flag with this ticket that I wasn't able to extract diagrams for tables that reference tables in other schemas. Not sure if the is a way or not? Nonetheless, still enjoying it a lot!

Best,
Javier

Duplicate relations if multiple indexes on foreign key

Many thanks for this super handy project!

I noticed a small bug: If there are two indexes on a foreign key, the relation is duplicated even though there is only one foreign key column. Here a minimal example to reproduce the issue:

For the following table definition

create table foo
(
    id serial primary key
);

create table bar
(
    id     serial primary key,
    foo_id int references foo,
    name   int
);

create index on bar (foo_id);
create unique index on bar (name, foo_id);

planter creates the following output

@startuml
hide circle
skinparam linetype ortho

entity "**bar**" {
  + ""id"": //serial [PK]//
  --
  ""foo_id"": //integer [FK]//
  ""name"": //integer //
}

entity "**foo**" {
  + ""id"": //serial [PK]//
  --
}

"**bar**"   }--  "**foo**"

"**bar**"   }--  "**foo**"
@enduml

whereas the correct output would be

@startuml
hide circle
skinparam linetype ortho

entity "**bar**" {
  + ""id"": //serial [PK]//
  --
  ""foo_id"": //integer [FK]//
  ""name"": //integer //
}

entity "**foo**" {
  + ""id"": //serial [PK]//
  --
}

"**bar**"   }--  "**foo**"
@enduml

Docker support

Hi, thanks for the great tool. I made a docker file which packages planter and plantuml in one docker image: https://github.com/kimmobrunfeldt/planter-docker. This makes using the tool a one-liner assuming docker is installed.

It exposes planter and plantuml directly, but also implements er command which allows selecting tables with a matching pattern. Useful for databases with tens or hundreds of tables.

won't work without foreign key

like the title said, if i don't use foreign key, this tool won't work, is there any idea we can make this work without foreign key

Partitions are included as entities (should skip)

Partitions of a table are included as entities.
This can result in extremly long output, repeating the same entity with a new name (partition name) again and again.

Can partitions be skipped please.

All relations are duplicated

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:

  • I have a table TAG, with a PK tag_key
  • I have a table CTG (= categories), with a PK ctg_key
  • There is a relationship of many to 0/1 between TAG and CTG, defined using a foreign key tag_fk: each tag belongs or not to a category
  • both table belong to a schema kuq

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

Can not install solution

Hey!

I try to install the solution by command, without success.

go get -u github.com/achiku/planter
# github.com/alecthomas/kingpin
go-1/src/github.com/alecthomas/kingpin/values.go:142:25: undefined: str2duration.Str2Duration

Option to generate high-level diagram

For large schemas, it would be useful to generate the ERD without the list of columns to just show the relationships.
Perhaps with an additional option to just show PKs and FKs
Would this be considered?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.