dbviz 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/README.org +52 -0
  4. data/bin/dbviz +78 -0
  5. data/dbviz.gemspec +19 -0
  6. metadata +129 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8a137715889672e9bdd071e92188ca9b5f9d2c7e
4
+ data.tar.gz: 1ed7b4a28487c239f5a7b4a8cf1ce69cf8f6bb9b
5
+ SHA512:
6
+ metadata.gz: 2221d1ca2203f9d79caf2a1f702d3e6da8ea9492e3c52f0016c96ba548de47aeccb07b469f6aeec0a06f8d8d0ace43e888ed9c3f64d871830b37aa2426d5a975
7
+ data.tar.gz: eb5ac019f762027a874a86dbad6638cc9d5361ca757f0865f7da9928c13bba8ada92024b15aac5553e64ccb8686a0b25f5ca86bf4a15a2db0db17d49a3be417f
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+
2
+ The MIT License (MIT)
3
+ Copyright © 2016 Chris Olstrom <chris@olstrom.com>
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.org ADDED
@@ -0,0 +1,52 @@
1
+ #+TITLE: dbviz - A tool for visualizing database relations
2
+ #+LATEX: \pagebreak
3
+
4
+ * Overview
5
+
6
+ ~dbviz~ is a tool to visualize relations in a database. Point it at your DB,
7
+ and it will produce a graph on =STDOUT= in a format suitable for processing or
8
+ rendering with =graphviz=.
9
+
10
+ * Installation
11
+
12
+ #+BEGIN_SRC shell
13
+ gem install dbviz
14
+ #+END_SRC
15
+
16
+ * Configuration
17
+
18
+ ~dbviz~ needs to know which database to visualize. Unless told otherwise, it
19
+ looks for a configuration file at =~/.config/dbviz.yaml=. To tell it
20
+ otherwise, either define =DBVIZ_CONFIG= in the environment, or provide it as
21
+ the first argument to ~dbviz~.
22
+
23
+ Environment is recommended, but using arguments is supported for convenience
24
+ when working with multiple configurations.
25
+
26
+ ** Example
27
+
28
+ #+BEGIN_SRC yaml
29
+ ---
30
+ adapter: postgres
31
+ database: my-awesome-database
32
+ host: localhost
33
+ password: MyVerySecurePasswordStoredUnencryptedOnDisk
34
+ port: 5432
35
+ user: me
36
+ #+END_SRC
37
+
38
+ * Usage
39
+
40
+ The following command will produce a visualization saved at =db.png=.
41
+
42
+ #+BEGIN_SRC shell
43
+ dbviz | dot -Tpng -o db.png
44
+ #+END_SRC
45
+
46
+ * License
47
+
48
+ ~dbviz~ is available under the [[https://tldrlegal.com/license/mit-license][MIT License]]. See ~LICENSE.txt~ for the full text.
49
+
50
+ * Contributors
51
+
52
+ - [[https://colstrom.github.io/][Chris Olstrom]] | [[mailto:chris@olstrom.com][e-mail]] | [[https://twitter.com/ChrisOlstrom][Twitter]]
data/bin/dbviz ADDED
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'contracts'
4
+ require 'facets'
5
+ require 'graphviz'
6
+ require 'sequel'
7
+ require 'yaml'
8
+
9
+ class DBViz
10
+ include ::Contracts::Core
11
+ include ::Contracts::Builtin
12
+
13
+ Contract None => String
14
+ def config_path
15
+ @config_path ||= ARGV.first || ENV['DBVIZ_CONFIG'] || File.expand_path('~/.config/dbviz.yaml')
16
+ end
17
+
18
+ Contract None => HashOf[Symbol, Or[String, Num]]
19
+ def config
20
+ @config ||= YAML.load_file(config_path).symbolize_keys
21
+ end
22
+
23
+ Contract None => RespondTo[:tables, :foreign_key_list]
24
+ def db
25
+ @db ||= Sequel.connect(config)
26
+ end
27
+
28
+ Contract None => ArrayOf[Symbol]
29
+ def tables
30
+ @tables ||= db.tables
31
+ end
32
+
33
+ Contract None => HashOf[Symbol, ArrayOf[HashOf[Symbol, Or[Symbol, Array, Bool]]]]
34
+ def foreign_keys
35
+ @foreign_keys ||= tables
36
+ .map { |t| { t => db.foreign_key_list(t) } }
37
+ .reduce(&:merge)
38
+ .reject { |_, v| v.empty? }
39
+ end
40
+
41
+ Contract None => HashOf[Symbol, ArrayOf[Symbol]]
42
+ def columns
43
+ @columns ||= tables
44
+ .map { |t| { t => db[t].columns } }
45
+ .reduce(&:merge)
46
+ end
47
+
48
+ def interesting
49
+ columns.select { |k, _| foreign_keys.keys.include? k }
50
+ end
51
+ end
52
+
53
+ GraphViz.new(:G, type: :digraph, rankdir: 'LR').tap do |graph|
54
+ DBViz.new.tap do |db|
55
+ db.interesting.each do |table, columns|
56
+ table.to_s.tap do |table|
57
+ graph.add_node table
58
+ columns
59
+ .map { |column| "#{table}.#{column}" }
60
+ .each { |column| graph.add_node column }
61
+ .each { |column| graph.add_edges table, column }
62
+ end
63
+ end
64
+
65
+ db.foreign_keys.each do |table, relations|
66
+ table.to_s.tap do |table|
67
+ relations.each do |relation|
68
+ relation[:columns]
69
+ .map { |c| "#{table}.#{c}" }
70
+ .product(relation[:key]
71
+ .map { |k| "#{relation[:table]}.#{k}" })
72
+ .each { |r| graph.add_edges(*r) }
73
+ end
74
+ end
75
+ end
76
+ end
77
+ puts graph.to_s
78
+ end
data/dbviz.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = 'dbviz'
3
+ gem.version = `git describe --tags --abbrev=0`.chomp
4
+ gem.licenses = 'MIT'
5
+ gem.authors = ['Chris Olstrom']
6
+ gem.email = 'chris@olstrom.com'
7
+ gem.homepage = 'https://github.com/colstrom/dbviz'
8
+ gem.summary = 'Visualizes Database Relations'
9
+
10
+ gem.files = `git ls-files`.split("\n")
11
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
12
+ gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
13
+ gem.require_paths = ['lib']
14
+
15
+ gem.add_runtime_dependency 'contracts', '~> 0.14', '>= 0.14.0'
16
+ gem.add_runtime_dependency 'facets', '~> 3.1', '>= 3.1.0'
17
+ gem.add_runtime_dependency 'ruby-graphviz', '~> 1.2', '>= 1.2.2'
18
+ gem.add_runtime_dependency 'sequel', '~> 4.36', '>= 4.36.0'
19
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dbviz
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Chris Olstrom
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: contracts
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.14'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.14.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.14'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.14.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: facets
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.1'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 3.1.0
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '3.1'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 3.1.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: ruby-graphviz
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.2'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 1.2.2
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.2'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 1.2.2
73
+ - !ruby/object:Gem::Dependency
74
+ name: sequel
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '4.36'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 4.36.0
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.36'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 4.36.0
93
+ description:
94
+ email: chris@olstrom.com
95
+ executables:
96
+ - dbviz
97
+ extensions: []
98
+ extra_rdoc_files: []
99
+ files:
100
+ - LICENSE.txt
101
+ - README.org
102
+ - bin/dbviz
103
+ - dbviz.gemspec
104
+ homepage: https://github.com/colstrom/dbviz
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.5.1
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Visualizes Database Relations
128
+ test_files: []
129
+ has_rdoc: