Giter Club home page Giter Club logo

plant_erd's Introduction

PlantERD

ERD exporter with PlantUML and mermaid format

Build Status Build Status Coverage Status Maintainability Go Report Card

Example (PlantUML)

$ ./plant_erd sqlite3 --database /path/to/test_db.sqlite3

entity articles {
  * id : integer
  --
  * user_id : integer
  --
  index_user_id_on_articles (user_id)
}

entity users {
  * id : integer
  --
  name : text
}

articles }-- users

example-plantuml

Example (mermaid)

$ ./plant_erd sqlite3 --database /path/to/test_db.sqlite3 --format=mermaid --show-comment

erDiagram

articles {
  INTEGER id PK
  INTEGER user_id FK
}

users {
  INTEGER id PK
  TEXT name
}

users ||--o{ articles : owns
erDiagram

articles {
  INTEGER id PK
  INTEGER user_id FK
}

users {
  INTEGER id PK
  TEXT name
}

users ||--o{ articles : owns
Loading

Features

  • Output ERD from real database
  • Output ERD to stdout or file
  • Output only tables within a certain distance adjacent to each other with foreign keys from a specific table

Supported databases

  • SQLite3
  • MySQL: 5.6, 5.7, 8
  • PostgreSQL: 9, 10, 11, 12, 13, 14, 15
  • Oracle

Supported output formats

Setup

Download latest binary from https://github.com/sue445/plant_erd/releases and chmod 755

  • plant_erd : for SQLite3, MySQL and PostgreSQL
  • plant_erd-oracle : for Oracle

Setup for plant_erd-oracle

plant_erd-oracle requires Basic Package or Basic Light Package in Oracle Instant Client

Example (Linux)

mkdir -p /opt/oracle
wget --quiet --tries=0 https://download.oracle.com/otn_software/linux/instantclient/193000/instantclient-basiclite-linux.x64-19.3.0.0.0dbru.zip
unzip -q instantclient-basiclite-linux.x64-19.3.0.0.0dbru.zip -d /opt/oracle
export LD_LIBRARY_PATH=/opt/oracle/instantclient_19_3

# for Ubuntu
apt-get update
apt-get install -y libaio1

Example (Mac)

See https://github.com/kubo/ruby-oci8/blob/master/docs/install-on-osx.md and install instantclient-basic or instantclient-basiclite

Example (Windows)

  1. Go to https://www.oracle.com/database/technologies/instant-client/winx64-64-downloads.html
  2. Download instantclient-basic-windows.x64-19.5.0.0.0dbru.zip or instantclient-basiclite-windows.x64-19.5.0.0.0dbru.zip
  3. Extract zip
  4. Move plant_erd-oracle to same directory as oci.dll

Usage

SQLite3

$ ./plant_erd sqlite3 --help
NAME:
   plant_erd sqlite3 - Generate ERD from sqlite3

USAGE:
   plant_erd sqlite3 [command options] [arguments...]

OPTIONS:
   -d DISTANCE, --distance DISTANCE  Output only tables within a certain DISTANCE adjacent to each other with foreign keys from a specific table (default: 0)
   --database DATABASE               SQLite3 DATABASE file
   -f FILE, --file FILE              FILE for output (default: stdout)
   --format value                    Output format (plant_uml, mermaid. default:plant_uml)
   -i, --skip-index                  Whether don't print index to ERD. This option is used only --format=plant_uml
   -s value, --skip-table value      Skip generating table by using regex patterns
   --show-comment                    Show column comment. This option is used only --format=mermaid
   -t TABLE, --table TABLE           Output only tables within a certain distance adjacent to each other with foreign keys from a specific TABLE

MySQL

$ ./plant_erd mysql --help
NAME:
   plant_erd mysql - Generate ERD from mysql

USAGE:
   plant_erd mysql [command options] [arguments...]

OPTIONS:
   --collation COLLATION             MySQL COLLATION (default: "utf8_general_ci")
   -d DISTANCE, --distance DISTANCE  Output only tables within a certain DISTANCE adjacent to each other with foreign keys from a specific table (default: 0)
   --database DATABASE               MySQL DATABASE name
   -f FILE, --file FILE              FILE for output (default: stdout)
   --format value                    Output format (plant_uml, mermaid. default:plant_uml)
   --host HOST                       MySQL HOST (default: "localhost")
   -i, --skip-index                  Whether don't print index to ERD. This option is used only --format=plant_uml
   --password PASSWORD               MySQL PASSWORD [$MYSQL_PASSWORD]
   --port PORT                       MySQL PORT (default: 3306)
   -s value, --skip-table value      Skip generating table by using regex patterns
   --show-comment                    Show column comment. This option is used only --format=mermaid
   -t TABLE, --table TABLE           Output only tables within a certain distance adjacent to each other with foreign keys from a specific TABLE
   --user USER                       MySQL USER (default: "root")

PostgreSQL

$ ./plant_erd postgresql --help
NAME:
   plant_erd postgresql - Generate ERD from PostgreSQL

USAGE:
   plant_erd postgresql [command options] [arguments...]

OPTIONS:
   -d DISTANCE, --distance DISTANCE  Output only tables within a certain DISTANCE adjacent to each other with foreign keys from a specific table (default: 0)
   --database DATABASE               PostgreSQL DATABASE name
   -f FILE, --file FILE              FILE for output (default: stdout)
   --format value                    Output format (plant_uml, mermaid. default:plant_uml)
   --host HOST                       PostgreSQL HOST (default: "localhost")
   -i, --skip-index                  Whether don't print index to ERD. This option is used only --format=plant_uml
   --password PASSWORD               PostgreSQL PASSWORD [$POSTGRES_PASSWORD]
   --port PORT                       PostgreSQL PORT (default: 5432)
   -s value, --skip-table value      Skip generating table by using regex patterns
   --show-comment                    Show column comment. This option is used only --format=mermaid
   --sslmode SSLMODE                 PostgreSQL SSLMODE. c.f. https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS (default: "disable")
   -t TABLE, --table TABLE           Output only tables within a certain distance adjacent to each other with foreign keys from a specific TABLE
   --user USER                       PostgreSQL USER

Oracle

$ ./plant_erd-oracle --help
NAME:
   plant_erd-oracle - ERD exporter with PlantUML and Mermaid format (for oracle)

USAGE:
   plant_erd-oracle [global options] command [command options] [arguments...]

VERSION:
   vX.X.X (build. xxxxxxx)

COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   -f FILE, --file FILE              FILE for output (default: stdout)
   -t TABLE, --table TABLE           Output only tables within a certain distance adjacent to each other with foreign keys from a specific TABLE
   -d DISTANCE, --distance DISTANCE  Output only tables within a certain DISTANCE adjacent to each other with foreign keys from a specific table (default: 0)
   -i, --skip-index                  Whether don't print index to ERD. This option is used only --format=plant_uml
   -s value, --skip-table value      Skip generating table by using regex patterns
   --format value                    Output format (plant_uml, mermaid. default:plant_uml)
   --show-comment                    Show column comment. This option is used only --format=mermaid
   --user USER                       Oracle USER
   --password PASSWORD               Oracle PASSWORD [$ORACLE_PASSWORD]
   --host HOST                       Oracle HOST (default: "localhost")
   --port PORT                       Oracle PORT (default: 1521)
   --service SERVICE                 Oracle SERVICE name
   --help, -h                        show help
   --version, -v                     print the version

About --table and --distance

When --table and --distance are passed, output only tables within a certain distance adjacent to each other with foreign keys from a specific table.

Example 1: Output all tables

$ ./plant_erd sqlite3

example all

Example 2: Output only tables within a distance of 1 from the articles

$ ./plant_erd sqlite3 --table articles --distance 1

example distance 1 from articles

Testing

with all databases

Run test in container

docker-compose up --build --abort-on-container-exit

with only SQLite3

Run test on local

make test

License

The program is available as open source under the terms of the MIT License.

But plant_erd-oracle contains Oracle Instant Client. Oracle Instant Client is under OTN License.

plant_erd's People

Contributors

autopp avatar dependabot-preview[bot] avatar dependabot[bot] avatar javedashraf avatar nminhquan avatar shoumoji avatar sue445 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

plant_erd's Issues

In case of SQLite3 database on Mac, it doesn't work

On macOS, when the database is SQLite3, an error occurs as below.

$ ./plant_erd sqlite3 --database development.sqlite3
2019/12/17 09:45:05 Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub

So I built on Ubuntu with CGO_ENABLED=1 but an error message was shown.

$ GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build
# os/user
../../../../.goenv/versions/1.13.0/src/os/user/getgrouplist_darwin.go: In function ‘mygetgrouplist’:
../../../../.goenv/versions/1.13.0/src/os/user/getgrouplist_darwin.go:16:11: warning: implicit declaration of function ‘getgrouplist’; did you mean ‘mygetgrouplist’? [-Wimplicit-function-declaration]
  int rv = getgrouplist(user, (int) group, buf, ngroups);
           ^~~~~~~~~~~~
           mygetgrouplist
# net
../../../../.goenv/versions/1.13.0/src/net/cgo_bsd.go:15:72: could not determine kind of name for C.AI_MASK

I suppose that though a cross-compile is required to build go-sqlite3 for darwin, Ubuntu cannot do cross-compile for darwin (or doing so is very difficult).

References

I referenced below articles.

Note

  • When I built on macOS, it works correcctly

Environment

macOS

Darwin XXX 19.0.0 Darwin Kernel Version 19.0.0: Thu Oct 17 16:17:15 PDT 2019; root:xnu-6153.41.3~29/RELEASE_X86_64 x86_64

Ubuntu

Linux XXX 5.0.0-36-generic #39~18.04.1-Ubuntu SMP Tue Nov 12 11:09:50 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

SQLite3: panic: interface conversion: interface {} is nil, not string

Hey, thanks for such a cool project. I'm having an issue while running it on my database, though:

$ plant_erd sqlite3 --database navidrome.db

panic: interface conversion: interface {} is nil, not string

goroutine 1 [running]:
github.com/sue445/plant_erd/adapter/sqlite3.(*Adapter).getForeignKeys(0xc0000a8110, {0xc0000acb60?, 0x100512a3c?})
        /Users/runner/work/plant_erd/plant_erd/adapter/sqlite3/adapter.go:115 +0x3eb
github.com/sue445/plant_erd/adapter/sqlite3.(*Adapter).GetTable(0xc0000a8110, {0xc0000acb60, 0xc})
        /Users/runner/work/plant_erd/plant_erd/adapter/sqlite3/adapter.go:80 +0x454
github.com/sue445/plant_erd/lib.LoadSchema({0x1005b1e48, 0xc0000a8110})
        /Users/runner/work/plant_erd/plant_erd/lib/schema.go:17 +0x12c
main.main.func1(0xc00014a160?)
        /Users/runner/work/plant_erd/plant_erd/cmd/plant_erd/main.go:64 +0x86
github.com/urfave/cli.HandleAction({0x1004b0e20?, 0xc0000a2270?}, 0x7?)
        /Users/runner/go/pkg/mod/github.com/urfave/[email protected]/app.go:524 +0x50
github.com/urfave/cli.Command.Run({{0x100516141, 0x7}, {0x0, 0x0}, {0xc000099910, 0x1, 0x1}, {0x10051f9c8, 0x19}, {0x0, ...}, ...}, ...)
        /Users/runner/go/pkg/mod/github.com/urfave/[email protected]/command.go:173 +0x65b
github.com/urfave/cli.(*App).Run(0xc000146000, {0xc0000b4000, 0x5, 0x5})
        /Users/runner/go/pkg/mod/github.com/urfave/[email protected]/app.go:277 +0x8c7
main.main()
        /Users/runner/work/plant_erd/plant_erd/cmd/plant_erd/main.go:213 +0x1132

This is the file I'm trying to read (no worries, data is dummy):
navidrome.db.zip

I'm using macOS amd64 and this happens with both the latest release 0.4.2 and building it from master.

Hopefully this is a simple fix :)

Dependabot can't resolve your Go dependency files

Dependabot can't resolve your Go dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

go: github.com/urfave/[email protected]: go.mod has post-v1 module path "github.com/urfave/cli/v2" at revision v1.22.5

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

plant_erd_linux_amd64 doesn't work on Ubuntu 18.04

Ubuntu 20.04 LTS

$ cat /etc/issue
Ubuntu 20.04.2 LTS \n \l

$ wget https://github.com/sue445/plant_erd/releases/download/v0.2.1/plant_erd_linux_amd64 -O plant_erd

$ chmod 755 plant_erd

$ ./plant_erd --version
plant_erd version v0.2.1 (build. 580ad03)

Ubuntu 18.04 LTS

$ cat /etc/issue
Ubuntu 18.04.5 LTS \n \l

$ wget https://github.com/sue445/plant_erd/releases/download/v0.2.1/plant_erd_linux_amd64 -O plant_erd

$ chmod 755 plant_erd

$ ./plant_erd --version
./plant_erd: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by ./plant_erd)

Oracle: make number of max open cursors exceeded

When running the tool against our Oracle database, we receive an "ORA-01000: maximum open cursors exceeded" (300 in our Oracle config). I couldn't find an option to configure the max open cursor count in plant_erd, which I would prefer. Alternatively I need to talk to the DB admins to extend the Oracle DB limit.

Any idea what determines the number of open cursors?

thanks a lot for your help

plant_erd_darwin_arm64 doesn't work on Apple M1

plant_erd_darwin_arm64 sqlite3 doesn't works on Mac (M1), but plant_erd_darwin_amd64 sqlite3 works on Mac (M1) 😇

$ uname -m
arm64

$ ./plant_erd_darwin_amd64 sqlite3 --database test-sqlite3.db

$ ./plant_erd_darwin_arm64 sqlite3 --database test-sqlite3.db
2021/09/09 15:39:43 Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub

I want to use Apple M1 on CI build, but GitHub Actions doesn't support yet.

actions/runner-images#2187

Workarround

  • Use plant_erd_darwin_amd64
  • Build on your pc (use make)

Views are included in output only MySQL mode

Currently, The output of plant_erd mysql includes views, but other command do not include by explicit query to exclude.
Is it expected behavior?

Examples

Both DB has 2 tables and 1 view.

mysql

Schema:

CREATE TABLE job (
  id int NOT NULL,
  name varchar(256),
  PRIMARY KEY (id)
);

CREATE TABLE person (
  id int NOT NULL,
  name varchar(256),
  job_id int NOT NULL,
  INDEX job_idx (job_id),
  FOREIGN KEY (job_id) REFERENCES job(id) ON DELETE CASCADE
);

CREATE VIEW personal_job AS SELECT person.name AS person_name, job.name AS job_name FROM person INNER JOIN job ON person.job_id = job.id;

Output:

entity job {
  * id : int(11)
  --
  name : varchar(256)
}

entity person {
  * id : int(11)
  name : varchar(256)
  * job_id : int(11)
  --
  job_idx (job_id)
}

entity personal_job {
  person_name : varchar(256)
  job_name : varchar(256)
}

person }-- job

postgresql

CREATE TABLE job (
  id int NOT NULL,
  name varchar(256),
  PRIMARY KEY (id)
);

CREATE TABLE person (
  id int NOT NULL,
  name varchar(256),
  job_id int NOT NULL,
  FOREIGN KEY (job_id) REFERENCES job(id) ON DELETE CASCADE
);

CREATE INDEX ON person(job_id);

CREATE VIEW personal_job AS SELECT person.name AS person_name, job.name AS job_name FROM person INNER JOIN job ON person.job_id = job.id;

Output:

$ plant_erd postgresql --database erd_test
entity job {
  * id : integer
  --
  name : character varying
}

entity person {
  * id : integer
  name : character varying
  * job_id : integer
  --
  person_job_id_idx (job_id)
}

person }-- job

Support mysql ssl connection

Hi there,
I would like to request a new feature that support Mysql connection with ssl. It would really helpful.
Thanks

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.