dba 1.1.0 → 2.0.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 +16 -0
- data/README.md +1 -0
- data/dba.gemspec +2 -2
- data/lib/dba.rb +1 -1
- data/lib/dba/database.rb +4 -16
- data/lib/dba/diff.rb +3 -3
- data/lib/dba/printer.rb +13 -4
- data/lib/dba/select.rb +14 -0
- data/lib/dba/shell.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a165d5ff98a815002bea9e1d54744639aba99bb1e678d66afe8743ffcb2fe30
|
4
|
+
data.tar.gz: dadb161b89dde586047a0a8b6aded72be9499db6c48a27c2e9c57c7172a9c1a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f8033d0911e384525fb846228840d4ff5c7527df5c5e0d64fedc6fc158e6e809b5d88ab57483592954e8313961cd23696ae030efe97b7f06a342bfbd40c8c7e
|
7
|
+
data.tar.gz: 461b1d4e5eb81151aa5350c2f09362da3d6a31a42c959edb48a5dbd97206a239c3f6b4ad8e166e4185df2e6569f63445443af30a41d1064f9679c8dae7aa2a0f
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
# 2.0.0
|
2
|
+
|
3
|
+
* **Required ruby version is now 2.5.0**
|
4
|
+
|
5
|
+
* Fixed diff command
|
6
|
+
|
7
|
+
* Added select command
|
8
|
+
|
9
|
+
* The indexes command now shows which indexes are unique
|
10
|
+
|
11
|
+
* The schema command now shows which columns have array types
|
12
|
+
|
13
|
+
* The postgres database is now used by default; use `.env` or `config/database.yml` to specify a different database name
|
14
|
+
|
15
|
+
|
1
16
|
# 1.1.0
|
2
17
|
|
3
18
|
* Fixed sample command for postgres
|
@@ -6,6 +21,7 @@
|
|
6
21
|
|
7
22
|
* Added load command for loading data from CSV, LDJSON, or YAML
|
8
23
|
|
24
|
+
|
9
25
|
# 1.0.0
|
10
26
|
|
11
27
|
* First version!
|
data/README.md
CHANGED
data/dba.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'dba'
|
3
|
-
s.version = '
|
3
|
+
s.version = '2.0.0'
|
4
4
|
s.license = 'GPL-3.0'
|
5
5
|
s.platform = Gem::Platform::RUBY
|
6
6
|
s.authors = ['Tim Craft']
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
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 = '>= 2.
|
12
|
+
s.required_ruby_version = '>= 2.5.0'
|
13
13
|
s.add_dependency('zeitwerk', '~> 2', '>= 2.2')
|
14
14
|
s.add_dependency('sequel', '~> 5')
|
15
15
|
s.add_dependency('pastel', '~> 0')
|
data/lib/dba.rb
CHANGED
data/lib/dba/database.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'sequel'
|
4
4
|
require 'yaml'
|
5
5
|
require 'erb'
|
6
|
+
require 'socket'
|
6
7
|
|
7
8
|
module DBA::Database
|
8
9
|
extend self
|
@@ -31,7 +32,7 @@ module DBA::Database
|
|
31
32
|
end
|
32
33
|
|
33
34
|
if postgres_running?
|
34
|
-
return
|
35
|
+
return 'postgres://localhost:5432/postgres'
|
35
36
|
end
|
36
37
|
|
37
38
|
if path = Dir['*.sqlite3'].first
|
@@ -78,21 +79,8 @@ module DBA::Database
|
|
78
79
|
args
|
79
80
|
end
|
80
81
|
|
81
|
-
def postgres_database_name
|
82
|
-
heroku_app_name || working_directory_name
|
83
|
-
end
|
84
|
-
|
85
|
-
def heroku_app_name
|
86
|
-
if `git config --get remote.heroku.url`.chomp =~ %r{(?<=[:/])([^:/]+)\.git\z}
|
87
|
-
$1
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def working_directory_name
|
92
|
-
File.basename(Dir.pwd)
|
93
|
-
end
|
94
|
-
|
95
82
|
def postgres_running?
|
96
|
-
|
83
|
+
Socket.tcp('localhost', 5432) { :connected }
|
84
|
+
rescue Errno::ECONNREFUSED
|
97
85
|
end
|
98
86
|
end
|
data/lib/dba/diff.rb
CHANGED
@@ -8,7 +8,7 @@ class DBA::Diff < DBA::Command
|
|
8
8
|
|
9
9
|
other_tables = other_database.tables
|
10
10
|
|
11
|
-
|
11
|
+
printer.print_diff tables, other_tables
|
12
12
|
|
13
13
|
tables &= other_tables # only diff columns/indexes for tables that exist in both databases
|
14
14
|
|
@@ -21,7 +21,7 @@ class DBA::Diff < DBA::Command
|
|
21
21
|
|
22
22
|
def list_columns(database, tables)
|
23
23
|
tables.inject([]) do |columns, table_name|
|
24
|
-
columns + database.schema(table_name).map { |name, info| format_column(name, info) }
|
24
|
+
columns + database.schema(table_name).map { |name, info| format_column(name, info, table_name) }
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -31,7 +31,7 @@ class DBA::Diff < DBA::Command
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
def format_column(name, info_hash)
|
34
|
+
def format_column(name, info_hash, table_name)
|
35
35
|
"#{table_name}.#{name} (#{info_hash.fetch(:type)})"
|
36
36
|
end
|
37
37
|
|
data/lib/dba/printer.rb
CHANGED
@@ -57,8 +57,8 @@ class DBA::Printer
|
|
57
57
|
schema_hash.each do |column_name, info_hash|
|
58
58
|
fields = []
|
59
59
|
fields << "#{table_name}.#{column_name}"
|
60
|
-
fields << muted(info_hash
|
61
|
-
fields << muted('
|
60
|
+
fields << muted(format_column_type(info_hash))
|
61
|
+
fields << muted('{primary}') if info_hash[:primary_key]
|
62
62
|
|
63
63
|
io.puts fields.join(' ')
|
64
64
|
end
|
@@ -68,9 +68,12 @@ class DBA::Printer
|
|
68
68
|
|
69
69
|
def print_indexes(indexes)
|
70
70
|
indexes.each do |index_name, info_hash|
|
71
|
-
|
71
|
+
fields = []
|
72
|
+
fields << index_name
|
73
|
+
fields << muted('(' + info_hash.fetch(:columns).map(&:to_s).join(', ') + ')')
|
74
|
+
fields << muted('{unique}') if info_hash[:unique]
|
72
75
|
|
73
|
-
io.puts
|
76
|
+
io.puts fields.join(' ')
|
74
77
|
end
|
75
78
|
end
|
76
79
|
|
@@ -96,6 +99,12 @@ class DBA::Printer
|
|
96
99
|
end
|
97
100
|
end
|
98
101
|
|
102
|
+
def format_column_type(info_hash)
|
103
|
+
return info_hash[:db_type] unless info_hash[:type]
|
104
|
+
return info_hash[:type] unless info_hash[:db_type]&.end_with?('[]')
|
105
|
+
info_hash[:type].to_s + '[]'
|
106
|
+
end
|
107
|
+
|
99
108
|
def null
|
100
109
|
@null ||= muted('NULL')
|
101
110
|
end
|
data/lib/dba/select.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
class DBA::Select < DBA::Command
|
2
|
+
def call(table, column, value)
|
3
|
+
self.table_name = table
|
4
|
+
|
5
|
+
column_name = column.to_sym
|
6
|
+
|
7
|
+
rows = database[table_name].where(column_name => value)
|
8
|
+
|
9
|
+
rows.each do |row|
|
10
|
+
printer.print(row)
|
11
|
+
printer.print_line
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/dba/shell.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.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: 2021-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- lib/dba/row_parser.rb
|
90
90
|
- lib/dba/sample.rb
|
91
91
|
- lib/dba/schema.rb
|
92
|
+
- lib/dba/select.rb
|
92
93
|
- lib/dba/shell.rb
|
93
94
|
- lib/dba/table_command.rb
|
94
95
|
- lib/dba/table_schema.rb
|
@@ -106,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
107
|
requirements:
|
107
108
|
- - ">="
|
108
109
|
- !ruby/object:Gem::Version
|
109
|
-
version: 2.
|
110
|
+
version: 2.5.0
|
110
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
112
|
requirements:
|
112
113
|
- - ">="
|