erdf 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +46 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/erdf +8 -0
- data/bin/setup +8 -0
- data/erdf.gemspec +26 -0
- data/lib/erdf.rb +5 -0
- data/lib/erdf/cli.rb +143 -0
- data/lib/erdf/template.dot.erb +18 -0
- data/lib/erdf/version.rb +3 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bc7111c52d6abd8c597198f420a84749ec783279
|
4
|
+
data.tar.gz: b262ed592a85ec3d0d0a2717f2e3d3e427e083a0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e171a035da75419e8eaa5ace0013f5add1232ccba456f1b5455dafdd6fea8c4a0d4dc684b47cdebe2687baf6f48391880978d617d8a8c8389bc778ecb7f44f2b
|
7
|
+
data.tar.gz: ee86906232b9f1baf58e0814c26acc37672a269b4c6a8d6cc6bfa7852f0e68ec36807a7f612d5c8a1b53adb8258efe97666a9054161d8b241997228f3853948e
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
## 0.6.0
|
2
|
+
- Help text
|
3
|
+
- Track errors just so we could have a make target in our Makefile in the rust api server aran.
|
4
|
+
- Format template.dot to different colors.
|
5
|
+
|
6
|
+
## 0.3.0
|
7
|
+
- Add basic style
|
8
|
+
- Support database as schema source.
|
9
|
+
|
10
|
+
## 0.2.0
|
11
|
+
- Support text schemas.
|
12
|
+
- Output the diagram as PNG.
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 David Strauß
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Entity-Relationship-Diagramm-Erzeuger
|
2
|
+
A simple tool to generate Entity-Relationship-Diagrams based on text input or directly from a PostgreSQL database. The format of the text schema is inspired and based on ["erd" by Andrew Gallant](https://github.com/BurntSushi/erd).
|
3
|
+
|
4
|
+
Fork of [edgycircle/erde](https://github.com/edgycircle/erde) with fixes added to suit our development.
|
5
|
+
|
6
|
+
## Motivation : Auto generating ERD from database
|
7
|
+
|
8
|
+
There are online tools like [genmymodel](https://genmymodel.com) which allows to build ERD diagrams.
|
9
|
+
|
10
|
+
We wanted a way where from a database we could draw a picture. This helps an instant update of schema and not making it stale.
|
11
|
+
|
12
|
+
Hence we would create make targets that gets triggered which generates schema, from the *Makefile* in our rust aran api server.
|
13
|
+
|
14
|
+
## Install
|
15
|
+
Make sure you have [Graphviz](http://graphviz.org/) installed and available in your `$PATH`.
|
16
|
+
|
17
|
+
Install the gem with `gem install erdf`.
|
18
|
+
|
19
|
+
## CLI Usage
|
20
|
+
|
21
|
+
~~~txt
|
22
|
+
erdf version
|
23
|
+
~~~
|
24
|
+
|
25
|
+
~~~txt
|
26
|
+
erdf file docs/schema.txt docs/schema.png
|
27
|
+
~~~
|
28
|
+
|
29
|
+
~~~txt
|
30
|
+
bin/erdf database postgres://user:password@localhost/your_database docs/schema.png
|
31
|
+
~~~
|
32
|
+
|
33
|
+
## Text Schema Format
|
34
|
+
~~~txt
|
35
|
+
[identities]
|
36
|
+
id
|
37
|
+
password
|
38
|
+
email
|
39
|
+
|
40
|
+
[players]
|
41
|
+
id
|
42
|
+
name
|
43
|
+
identity_id
|
44
|
+
|
45
|
+
players:identity_id -- identities:id
|
46
|
+
~~~
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "erdf"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/erdf
ADDED
data/bin/setup
ADDED
data/erdf.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'erdf/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "erdf"
|
8
|
+
spec.version = Erdf::VERSION
|
9
|
+
spec.authors = ["David Strauß", "Kishorekumar Neelamegam"]
|
10
|
+
spec.email = ["david@strauss.io", "nkishore@megam.io"]
|
11
|
+
|
12
|
+
spec.summary = %q{Entity-Relationship-Diagramm-Erzeuger}
|
13
|
+
spec.description = %q{Generate good looking Entity-Relationship-Diagrams from text files or a PostgreSQL database.}
|
14
|
+
spec.homepage = "https://github.com/megamsys/erde"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.executables = "erdf"
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
22
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
23
|
+
spec.add_development_dependency "minitest", "~> 5.10"
|
24
|
+
|
25
|
+
spec.add_dependency "sequel", "~> 4.0"
|
26
|
+
end
|
data/lib/erdf.rb
ADDED
data/lib/erdf/cli.rb
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
require "erdf"
|
2
|
+
require "pathname"
|
3
|
+
require "open3"
|
4
|
+
require "sequel"
|
5
|
+
require "erb"
|
6
|
+
|
7
|
+
class Erdf::CLI
|
8
|
+
def self.start(*args)
|
9
|
+
|
10
|
+
if ARGV.empty?
|
11
|
+
puts 'Error: Args missing'
|
12
|
+
puts ' > Help'
|
13
|
+
puts ' > ----'
|
14
|
+
puts ' erdf file <filename> <output_file.png>'
|
15
|
+
puts ' erdf database erde database postgres://postgres:postgres@localhost/rioosdb?search_path=shard_0,public ./schema.png <output_file.png>'
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
|
19
|
+
command = args.shift.strip
|
20
|
+
|
21
|
+
case command
|
22
|
+
when "version"
|
23
|
+
puts 'erdf 0.6.1'
|
24
|
+
exit
|
25
|
+
when "file"
|
26
|
+
file = Pathname(args.shift.strip)
|
27
|
+
input = file.read
|
28
|
+
text_transformer = Erdf::TextTransformer.new(input)
|
29
|
+
hash_schema = text_transformer.to_hash
|
30
|
+
when "database"
|
31
|
+
url = args.shift.strip
|
32
|
+
database_transformer = Erdf::DatabaseTransformer.new(url)
|
33
|
+
hash_schema = database_transformer.to_hash
|
34
|
+
else
|
35
|
+
printf('Error: "%s" - command not found', command)
|
36
|
+
puts ''
|
37
|
+
puts ' > Help'
|
38
|
+
puts ' > ----'
|
39
|
+
puts ' erdf file <filename> <output_file.png>'
|
40
|
+
puts ' erdf database erde database postgres://postgres:postgres@localhost/rioosdb?search_path=shard_0,public ./schema.png <output_file.png>'
|
41
|
+
exit
|
42
|
+
end
|
43
|
+
|
44
|
+
hash_transformer = Erdf::HashTransformer.new(hash_schema)
|
45
|
+
dot_schema = hash_transformer.to_dot
|
46
|
+
|
47
|
+
output_file = args.shift.strip
|
48
|
+
|
49
|
+
layouted_graph, dot_log = Open3.capture3("dot -Tpng -o #{output_file}", stdin_data: dot_schema)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class Erdf::HashTransformer
|
54
|
+
def initialize(hash)
|
55
|
+
@hash = hash
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_dot
|
59
|
+
template = File.read(File.expand_path("../template.dot.erb", __FILE__))
|
60
|
+
|
61
|
+
schema_string = ""
|
62
|
+
schema_string << "digraph tables {"
|
63
|
+
schema_string << "node [shape=plaintext rankdir=LR];"
|
64
|
+
|
65
|
+
@hash.each_pair do |table_name, table_schema|
|
66
|
+
renderer = ERB.new(template)
|
67
|
+
schema_string << renderer.result(binding)
|
68
|
+
|
69
|
+
table_schema['relations'].each_pair do |column, target|
|
70
|
+
schema_string << "#{table_name}:#{column} -> #{target['table']}:#{target['column']};"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
schema_string << "}"
|
75
|
+
|
76
|
+
schema_string
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class Erdf::DatabaseTransformer
|
81
|
+
def initialize(url)
|
82
|
+
@url = url
|
83
|
+
end
|
84
|
+
|
85
|
+
def to_hash
|
86
|
+
generated_hash = {}
|
87
|
+
|
88
|
+
Sequel.connect(@url) do |db|
|
89
|
+
db.tables.each do |table|
|
90
|
+
generated_hash[table] = {}
|
91
|
+
generated_hash[table]['columns'] = []
|
92
|
+
generated_hash[table]['relations'] = {}
|
93
|
+
|
94
|
+
generated_hash[table]['columns'] = db.schema(table).map(&:first)
|
95
|
+
|
96
|
+
db.foreign_key_list(table).each do |foreign_key|
|
97
|
+
generated_hash[table]['relations'][foreign_key[:columns].first] = {
|
98
|
+
'table' => foreign_key[:table],
|
99
|
+
'column' => foreign_key[:key].first
|
100
|
+
}
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
generated_hash
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
class Erdf::TextTransformer
|
110
|
+
def initialize(text)
|
111
|
+
@lines = text.lines
|
112
|
+
end
|
113
|
+
|
114
|
+
def to_hash
|
115
|
+
generated_hash = {}
|
116
|
+
current_table = nil
|
117
|
+
|
118
|
+
@lines.each do |line|
|
119
|
+
cleaned_line = line.strip
|
120
|
+
|
121
|
+
if current_table && cleaned_line.length > 0
|
122
|
+
generated_hash[current_table]['columns'] << cleaned_line
|
123
|
+
end
|
124
|
+
|
125
|
+
if cleaned_line.length == 0
|
126
|
+
current_table = nil
|
127
|
+
end
|
128
|
+
|
129
|
+
if match = cleaned_line.match(/^\[(\w+)\]/)
|
130
|
+
current_table = match[1]
|
131
|
+
generated_hash[current_table] = {}
|
132
|
+
generated_hash[current_table]['columns'] = []
|
133
|
+
generated_hash[current_table]['relations'] = {}
|
134
|
+
end
|
135
|
+
|
136
|
+
if match = cleaned_line.match(/^(\w+):(\w+) -- (\w+):(\w+)/)
|
137
|
+
generated_hash[match[1]]['relations'][match[2]] = { 'table' => match[3], 'column' => match[4] }
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
generated_hash
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<%= table_name %> [label=<
|
2
|
+
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
|
3
|
+
<TR>
|
4
|
+
<TD BGCOLOR="steelblue"><%= table_name %></TD>
|
5
|
+
</TR>
|
6
|
+
<TR>
|
7
|
+
<TD>
|
8
|
+
<TABLE BORDER="0" CELLBORDER="0" CELLSPACING="0" CELLPADDING="4">
|
9
|
+
<% for @column in table_schema['columns'] %>
|
10
|
+
<TR BGCOLOR="goldenrod" BORDER="1">
|
11
|
+
<TD PORT="<%= @column %>"><%= @column %></TD>
|
12
|
+
</TR>
|
13
|
+
<% end %>
|
14
|
+
</TABLE>
|
15
|
+
</TD>
|
16
|
+
</TR>
|
17
|
+
</TABLE>
|
18
|
+
>];
|
data/lib/erdf/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: erdf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Strauß
|
8
|
+
- Kishorekumar Neelamegam
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2017-08-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.15'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.15'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '12.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '12.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: minitest
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '5.10'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '5.10'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: sequel
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '4.0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '4.0'
|
70
|
+
description: Generate good looking Entity-Relationship-Diagrams from text files or
|
71
|
+
a PostgreSQL database.
|
72
|
+
email:
|
73
|
+
- david@strauss.io
|
74
|
+
- nkishore@megam.io
|
75
|
+
executables:
|
76
|
+
- erdf
|
77
|
+
extensions: []
|
78
|
+
extra_rdoc_files: []
|
79
|
+
files:
|
80
|
+
- ".gitignore"
|
81
|
+
- ".travis.yml"
|
82
|
+
- CHANGELOG.md
|
83
|
+
- Gemfile
|
84
|
+
- LICENSE.txt
|
85
|
+
- README.md
|
86
|
+
- Rakefile
|
87
|
+
- bin/console
|
88
|
+
- bin/erdf
|
89
|
+
- bin/setup
|
90
|
+
- erdf.gemspec
|
91
|
+
- lib/erdf.rb
|
92
|
+
- lib/erdf/cli.rb
|
93
|
+
- lib/erdf/template.dot.erb
|
94
|
+
- lib/erdf/version.rb
|
95
|
+
homepage: https://github.com/megamsys/erde
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
metadata: {}
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.6.12
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: Entity-Relationship-Diagramm-Erzeuger
|
119
|
+
test_files: []
|