Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/syucream/hakagi
HAKAGI(葉鍵, Leaf and Key) is a RDB analyzer that detects implicit foreign key constraints and others
https://github.com/syucream/hakagi
er-diagram mysql
Last synced: 24 days ago
JSON representation
HAKAGI(葉鍵, Leaf and Key) is a RDB analyzer that detects implicit foreign key constraints and others
- Host: GitHub
- URL: https://github.com/syucream/hakagi
- Owner: syucream
- License: mit
- Created: 2018-05-02T14:18:16.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-16T14:33:08.000Z (about 6 years ago)
- Last Synced: 2024-10-03T12:24:46.556Z (about 1 month ago)
- Topics: er-diagram, mysql
- Language: Go
- Homepage:
- Size: 78.1 KB
- Stars: 42
- Watchers: 5
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hakagi
[![CircleCI](https://circleci.com/gh/syucream/hakagi.svg?style=svg)](https://circleci.com/gh/syucream/hakagi)
HAKAGI(葉鍵, Leaf and Key) is RDB analyzer that detects implicit foreign key constraints and others to support ER diagram auto-generation
## Installation
```
$ go get -u github.com/syucream/hakagi/cmd/hakagi
```## Usage
```
$ ./hakagi -dbuser -dbpass -dbhost -dbport -targets
```## Example
- This query doesn't have foreign key constraints:
```
$ cat examples/example.sql
CREATE TABLE IF NOT EXISTS users (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
age INT UNSIGNED NOT NULL,
email VARCHAR(255) NOT NULL,
PRIMARY KEY(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;CREATE TABLE IF NOT EXISTS contents (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
text TEXT NOT NULL,
user_id INT UNSIGNED NOT NULL,
PRIMARY KEY(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;CREATE TABLE IF NOT EXISTS content_comments (
content_comment_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
text TEXT NOT NULL,
content_id INT UNSIGNED NOT NULL,
user_id INT UNSIGNED NOT NULL,
PRIMARY KEY(content_comment_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;CREATE TABLE IF NOT EXISTS content_comment_reactions (
content_comment_id INT UNSIGNED NOT NULL,
user_id INT UNSIGNED NOT NULL,
reaction_id INT UNSIGNED NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;CREATE TABLE IF NOT EXISTS reactions (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
image_url VARCHAR(255) NOT NULL,
PRIMARY KEY(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
```- So you might not generate ER diagram automatically
![ER diagram before](./images/before_er.png)
- `hakagi` guesses the relations based on table/column names:
```
$ ./hakagi -dbuser root -targets hakagi_example
ALTER TABLE content_comment_reactions ADD CONSTRAINT FOREIGN KEY (content_comment_id) REFERENCES content_comments(content_comment_id);
ALTER TABLE content_comment_reactions ADD CONSTRAINT FOREIGN KEY (user_id) REFERENCES users(id);
ALTER TABLE content_comment_reactions ADD CONSTRAINT FOREIGN KEY (reaction_id) REFERENCES reactions(id);
ALTER TABLE content_comments ADD CONSTRAINT FOREIGN KEY (content_id) REFERENCES contents(id);
ALTER TABLE content_comments ADD CONSTRAINT FOREIGN KEY (user_id) REFERENCES users(id);
ALTER TABLE contents ADD CONSTRAINT FOREIGN KEY (user_id) REFERENCES users(id);
```- You might get auto-generated diagram with the relations:
```
$ ./hakagi -dbuser root -targets hakagi_example > migration01.sql
$ mysql -u root hakagi_example < migration01.sql
```![ER diagram after](./images/after_er.png)
## TODO
- Support more guess roles
- Support more output formats(e.g. plantuml?)