dba 2.2.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES.md +14 -0
- data/README.md +2 -1
- data/dba.gemspec +7 -6
- data/lib/dba/database.rb +1 -5
- data/lib/dba/dbml_printer.rb +19 -0
- data/lib/dba/diagram.rb +28 -0
- data/lib/dba/diagram_printer.rb +67 -0
- data/lib/dba/dot_printer.rb +37 -0
- data/lib/dba/plant_uml_printer.rb +28 -0
- data/lib/dba/shell.rb +2 -1
- data/lib/dba.rb +5 -2
- metadata +29 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74ad1c9318dc8528558d79b8e4705689f883c109724a6f184a392bfab3c3996f
|
4
|
+
data.tar.gz: f344a83c6abd29713f6975ab50fc524cdfa618a2df9be9de990ed8dd3a371ebf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98370ebd4bc8ee85bd617dbe6bf91d9e641d08ad29a3bc833625f1f3f0f527f622ed5620c43f8c174faa7c57527a38ea2d8ffcf74eef9708f7c33d04d9bd95ac
|
7
|
+
data.tar.gz: 255c954574e9545968238a5c7ddb2fd6fc11bad9379792f1b58dc0ee2e4d15591134d7be85f77b2d17d32d62b5e598261935a4cbc65d16d0796a93b4b2d2a0cd
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
# 2.4.0
|
2
|
+
|
3
|
+
* **Required ruby version is now 3.1.0**
|
4
|
+
|
5
|
+
* Added bigdecimal gem dependency
|
6
|
+
|
7
|
+
|
8
|
+
# 2.3.0
|
9
|
+
|
10
|
+
* Added diagram command for generating diagrams with Graphviz, DBML, or PlantUML
|
11
|
+
|
12
|
+
* Usage is now printed to STDOUT instead of STDERR
|
13
|
+
|
14
|
+
|
1
15
|
# 2.2.0
|
2
16
|
|
3
17
|
* Fixed compatibility with psych 4+
|
data/README.md
CHANGED
@@ -18,6 +18,7 @@ You can connect to any database supported by [sequel](https://rubygems.org/gems/
|
|
18
18
|
$ dba
|
19
19
|
Usage: dba COMMAND
|
20
20
|
|
21
|
+
dba diagram [PATH]
|
21
22
|
dba diff URL
|
22
23
|
dba dump TABLE EXTENSION
|
23
24
|
dba edit TABLE IDENTIFIER
|
@@ -28,7 +29,7 @@ You can connect to any database supported by [sequel](https://rubygems.org/gems/
|
|
28
29
|
dba sample TABLE [COLUMN]
|
29
30
|
dba schema [TABLE]
|
30
31
|
dba select TABLE COLUMN VALUE
|
31
|
-
dba tables
|
32
|
+
dba tables
|
32
33
|
|
33
34
|
|
34
35
|
## ERROR: could not find database
|
data/dba.gemspec
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'dba'
|
3
|
-
s.version = '2.
|
3
|
+
s.version = '2.4.0'
|
4
4
|
s.license = 'GPL-3.0'
|
5
5
|
s.platform = Gem::Platform::RUBY
|
6
6
|
s.authors = ['Tim Craft']
|
7
|
-
s.email = ['
|
7
|
+
s.email = ['email@timcraft.com']
|
8
8
|
s.homepage = 'https://github.com/readysteady/dba'
|
9
9
|
s.description = 'Ruby command line tool for working with development databases'
|
10
10
|
s.summary = 'See description'
|
11
11
|
s.files = Dir.glob('lib/**/*.rb') + %w[CHANGES.md LICENSE.txt README.md dba.gemspec]
|
12
|
-
s.required_ruby_version = '>=
|
13
|
-
s.add_dependency
|
14
|
-
s.add_dependency
|
15
|
-
s.add_dependency
|
12
|
+
s.required_ruby_version = '>= 3.1.0'
|
13
|
+
s.add_dependency 'bigdecimal', '~> 3'
|
14
|
+
s.add_dependency 'pastel', '~> 0'
|
15
|
+
s.add_dependency 'sequel', '~> 5'
|
16
|
+
s.add_dependency 'zeitwerk', '~> 2'
|
16
17
|
s.require_path = 'lib'
|
17
18
|
s.executables = ['dba']
|
18
19
|
end
|
data/lib/dba/database.rb
CHANGED
@@ -75,11 +75,7 @@ module DBA::Database
|
|
75
75
|
def database_config
|
76
76
|
source = ERB.new(File.read(database_config_path)).result
|
77
77
|
|
78
|
-
|
79
|
-
YAML.unsafe_load(source)
|
80
|
-
else
|
81
|
-
YAML.load(source)
|
82
|
-
end
|
78
|
+
YAML.unsafe_load(source)
|
83
79
|
end
|
84
80
|
|
85
81
|
def development_database_args
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class DBA::DBMLPrinter < DBA::DiagramPrinter
|
4
|
+
def print_table_start(name)
|
5
|
+
@io.puts "Table #{name} {"
|
6
|
+
end
|
7
|
+
|
8
|
+
def print_table_end(name)
|
9
|
+
@io.puts '}'
|
10
|
+
end
|
11
|
+
|
12
|
+
def print_column(name, type)
|
13
|
+
@io.puts " #{name} #{type}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def print_foreign_key(table, column, other_table, other_column)
|
17
|
+
@io.puts %{Ref: #{table}.#{column} > #{other_table}.#{other_column}}
|
18
|
+
end
|
19
|
+
end
|
data/lib/dba/diagram.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class DBA::Diagram < DBA::Command
|
4
|
+
PRINTERS = {
|
5
|
+
'.dbml' => :DBMLPrinter,
|
6
|
+
'.dot' => :DOTPrinter,
|
7
|
+
'.gv' => :DOTPrinter,
|
8
|
+
'.pu' => :PlantUMLPrinter,
|
9
|
+
'.puml' => :PlantUMLPrinter,
|
10
|
+
}
|
11
|
+
|
12
|
+
def call(path = nil)
|
13
|
+
if path.nil?
|
14
|
+
printer = DBA::DOTPrinter.new
|
15
|
+
printer.print_diagram(database)
|
16
|
+
else
|
17
|
+
extension = File.extname(path)
|
18
|
+
|
19
|
+
printer = PRINTERS.fetch(extension) { raise DBA::Error, 'unsupported file extension' }
|
20
|
+
printer = DBA.const_get(printer)
|
21
|
+
|
22
|
+
File.open(path, 'w+') do |file|
|
23
|
+
printer = printer.new(file)
|
24
|
+
printer.print_diagram(database)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
class DBA::DiagramPrinter
|
2
|
+
def initialize(io = STDOUT)
|
3
|
+
@io = io
|
4
|
+
end
|
5
|
+
|
6
|
+
def print_diagram(database)
|
7
|
+
print_start
|
8
|
+
|
9
|
+
@primary_keys = {}
|
10
|
+
|
11
|
+
table_names = database.tables
|
12
|
+
|
13
|
+
table_names.each do |name|
|
14
|
+
schema_hash = database.schema(name)
|
15
|
+
|
16
|
+
print_table(name, schema_hash)
|
17
|
+
end
|
18
|
+
|
19
|
+
table_names.each do |table|
|
20
|
+
database.foreign_key_list(table).each do |hash|
|
21
|
+
column = hash.fetch(:columns).first
|
22
|
+
|
23
|
+
other_table = hash.fetch(:table)
|
24
|
+
|
25
|
+
other_column = @primary_keys.fetch(other_table)
|
26
|
+
|
27
|
+
print_foreign_key(table, column, other_table, other_column)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
print_end
|
32
|
+
end
|
33
|
+
|
34
|
+
def print_start
|
35
|
+
end
|
36
|
+
|
37
|
+
def print_end
|
38
|
+
end
|
39
|
+
|
40
|
+
def print_table(name, schema_hash)
|
41
|
+
print_table_start(name)
|
42
|
+
|
43
|
+
schema_hash.each do |column_name, info_hash|
|
44
|
+
column_type = info_hash[:type] || info_hash[:db_type]
|
45
|
+
|
46
|
+
if info_hash[:primary_key]
|
47
|
+
@primary_keys[name] = column_name
|
48
|
+
end
|
49
|
+
|
50
|
+
print_column(column_name, column_type)
|
51
|
+
end
|
52
|
+
|
53
|
+
print_table_end(name)
|
54
|
+
end
|
55
|
+
|
56
|
+
def print_table_start(name)
|
57
|
+
end
|
58
|
+
|
59
|
+
def print_table_end(name)
|
60
|
+
end
|
61
|
+
|
62
|
+
def print_column(name, type)
|
63
|
+
end
|
64
|
+
|
65
|
+
def print_foreign_key(table, column, other_table, other_column)
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class DBA::DOTPrinter < DBA::DiagramPrinter
|
4
|
+
def print_start
|
5
|
+
@io.puts 'digraph database {'
|
6
|
+
@io.puts ' graph[rankdir="LR",ranksep=1.5,nodesep=0.5];'
|
7
|
+
@io.puts ' node[shape="Mrecord",fontname="Helvetica,Arial,sans-serif"];'
|
8
|
+
end
|
9
|
+
|
10
|
+
def print_end
|
11
|
+
@io.puts '}'
|
12
|
+
end
|
13
|
+
|
14
|
+
def print_table(name, schema_hash)
|
15
|
+
label = [name]
|
16
|
+
|
17
|
+
schema_hash.each do |column_name, info_hash|
|
18
|
+
column_type = info_hash[:type] || info_hash[:db_type]
|
19
|
+
|
20
|
+
if info_hash[:primary_key]
|
21
|
+
@primary_keys[name] = column_name
|
22
|
+
|
23
|
+
label << "{<#{column_name}>#{column_name}|#{column_type}}"
|
24
|
+
else
|
25
|
+
label << "{#{column_name}|<#{column_name}>#{column_type}}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
label = label.join('|')
|
30
|
+
|
31
|
+
@io.puts %{ #{name}[label="#{label}"];}
|
32
|
+
end
|
33
|
+
|
34
|
+
def print_foreign_key(table, column, other_table, other_column)
|
35
|
+
@io.puts %{ #{table}:#{column} -> #{other_table}:#{other_column};}
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class DBA::PlantUMLPrinter < DBA::DiagramPrinter
|
4
|
+
def print_start
|
5
|
+
@io.puts '@startuml'
|
6
|
+
@io.puts 'left to right direction'
|
7
|
+
end
|
8
|
+
|
9
|
+
def print_end
|
10
|
+
@io.puts '@enduml'
|
11
|
+
end
|
12
|
+
|
13
|
+
def print_table_start(name)
|
14
|
+
@io.puts "map #{name} {"
|
15
|
+
end
|
16
|
+
|
17
|
+
def print_table_end(name)
|
18
|
+
@io.puts '}'
|
19
|
+
end
|
20
|
+
|
21
|
+
def print_column(name, type)
|
22
|
+
@io.puts " #{name} => #{type}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def print_foreign_key(table, column, other_table, other_column)
|
26
|
+
@io.puts %{#{table}::#{column} *-> #{other_table}::#{other_column}}
|
27
|
+
end
|
28
|
+
end
|
data/lib/dba/shell.rb
CHANGED
@@ -30,6 +30,7 @@ module DBA::Shell
|
|
30
30
|
|
31
31
|
def commands
|
32
32
|
{
|
33
|
+
'diagram' => :Diagram,
|
33
34
|
'diff' => :Diff,
|
34
35
|
'dump' => :Dump,
|
35
36
|
'edit' => :Edit,
|
@@ -55,7 +56,7 @@ module DBA::Shell
|
|
55
56
|
end
|
56
57
|
|
57
58
|
def print_usage
|
58
|
-
printer = DBA::Printer.new
|
59
|
+
printer = DBA::Printer.new
|
59
60
|
printer.print_usage(program_name, command_parameters)
|
60
61
|
|
61
62
|
Kernel::exit(1)
|
data/lib/dba.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2019-
|
1
|
+
# Copyright (c) 2019-2025 TIMCRAFT
|
2
2
|
#
|
3
3
|
# This program is free software: you can redistribute it and/or modify
|
4
4
|
# it under the terms of the GNU General Public License as published by
|
@@ -18,9 +18,12 @@ module DBA
|
|
18
18
|
loader = Zeitwerk::Loader.new
|
19
19
|
loader.tag = File.basename(__FILE__, '.rb')
|
20
20
|
loader.inflector.inflect({
|
21
|
-
'dba' => 'DBA',
|
22
21
|
'csv' => 'CSV',
|
22
|
+
'dba' => 'DBA',
|
23
|
+
'dbml_printer' => 'DBMLPrinter',
|
24
|
+
'dot_printer' => 'DOTPrinter',
|
23
25
|
'ldjson' => 'LDJSON',
|
26
|
+
'plant_uml_printer' => 'PlantUMLPrinter',
|
24
27
|
'yaml' => 'YAML'
|
25
28
|
})
|
26
29
|
loader.push_dir(__dir__)
|
metadata
CHANGED
@@ -1,35 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Craft
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: bigdecimal
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '2.2'
|
19
|
+
version: '3'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
30
|
-
|
26
|
+
version: '3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pastel
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
31
32
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
33
41
|
- !ruby/object:Gem::Dependency
|
34
42
|
name: sequel
|
35
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -45,22 +53,22 @@ dependencies:
|
|
45
53
|
- !ruby/object:Gem::Version
|
46
54
|
version: '5'
|
47
55
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
56
|
+
name: zeitwerk
|
49
57
|
requirement: !ruby/object:Gem::Requirement
|
50
58
|
requirements:
|
51
59
|
- - "~>"
|
52
60
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
61
|
+
version: '2'
|
54
62
|
type: :runtime
|
55
63
|
prerelease: false
|
56
64
|
version_requirements: !ruby/object:Gem::Requirement
|
57
65
|
requirements:
|
58
66
|
- - "~>"
|
59
67
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
68
|
+
version: '2'
|
61
69
|
description: Ruby command line tool for working with development databases
|
62
70
|
email:
|
63
|
-
-
|
71
|
+
- email@timcraft.com
|
64
72
|
executables:
|
65
73
|
- dba
|
66
74
|
extensions: []
|
@@ -75,13 +83,18 @@ files:
|
|
75
83
|
- lib/dba/command.rb
|
76
84
|
- lib/dba/csv.rb
|
77
85
|
- lib/dba/database.rb
|
86
|
+
- lib/dba/dbml_printer.rb
|
87
|
+
- lib/dba/diagram.rb
|
88
|
+
- lib/dba/diagram_printer.rb
|
78
89
|
- lib/dba/diff.rb
|
90
|
+
- lib/dba/dot_printer.rb
|
79
91
|
- lib/dba/dump.rb
|
80
92
|
- lib/dba/edit.rb
|
81
93
|
- lib/dba/find.rb
|
82
94
|
- lib/dba/indexes.rb
|
83
95
|
- lib/dba/ldjson.rb
|
84
96
|
- lib/dba/load.rb
|
97
|
+
- lib/dba/plant_uml_printer.rb
|
85
98
|
- lib/dba/printer.rb
|
86
99
|
- lib/dba/pull.rb
|
87
100
|
- lib/dba/row_command.rb
|
@@ -107,14 +120,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
120
|
requirements:
|
108
121
|
- - ">="
|
109
122
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
123
|
+
version: 3.1.0
|
111
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
125
|
requirements:
|
113
126
|
- - ">="
|
114
127
|
- !ruby/object:Gem::Version
|
115
128
|
version: '0'
|
116
129
|
requirements: []
|
117
|
-
rubygems_version: 3.
|
130
|
+
rubygems_version: 3.5.22
|
118
131
|
signing_key:
|
119
132
|
specification_version: 4
|
120
133
|
summary: See description
|