convergence 1.0.0 → 1.0.5
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 +5 -5
- data/.gitignore +3 -0
- data/.travis.yml +2 -0
- data/CHANGELOG.md +34 -0
- data/Gemfile.lock +54 -53
- data/README.md +36 -2
- data/convergence.gemspec +3 -4
- data/lib/convergence/cli.rb +9 -53
- data/lib/convergence/column.rb +1 -0
- data/lib/convergence/command.rb +2 -10
- data/lib/convergence/command/apply.rb +21 -15
- data/lib/convergence/command/diff.rb +0 -7
- data/lib/convergence/command/dryrun.rb +3 -7
- data/lib/convergence/command/export.rb +0 -7
- data/lib/convergence/command/rollback_dryrun.rb +28 -0
- data/lib/convergence/config.rb +31 -1
- data/lib/convergence/database_connector/mysql_connector.rb +14 -10
- data/lib/convergence/diff.rb +1 -1
- data/lib/convergence/dumper.rb +1 -1
- data/lib/convergence/version.rb +1 -1
- metadata +11 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e270165d78af1a4c6020d42e9fd9465295bdb271218056a116227de9032aa191
|
4
|
+
data.tar.gz: 15fb16f3de75b1da47295933b5173b03b9080c3aadd9b52e3991117c39291885
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4977200385a68c85d65e3db870aab8c5f2db2ad37e3fb196e167f4f926a40cc6031316606da8b1005767de6b295ce0c171e71414a74a00e38b93b77518f275fe
|
7
|
+
data.tar.gz: 1252a85992eb3e6151f0b5205e36771125fccd712364e94a259a1c7f7555b760ca71ad2462e336a214af39ea4a1700c68b0c76cd2d49a72e8b5fb8c43d392a86
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,37 @@
|
|
1
|
+
## Convergence 1.0.5 (December 31, 2020) ##
|
2
|
+
|
3
|
+
* Update dependent gem (PR: #80)
|
4
|
+
|
5
|
+
*nishio-dens*
|
6
|
+
|
7
|
+
## Convergence 1.0.4 (September 8, 2020) ##
|
8
|
+
|
9
|
+
* Support diff-lcs 1.4 (PR: #75 #76)
|
10
|
+
|
11
|
+
*yujideveloper*
|
12
|
+
|
13
|
+
* Fix warning on Ruby 2.6 and later (PR: #77)
|
14
|
+
|
15
|
+
*yujideveloper*
|
16
|
+
|
17
|
+
## Convergence 1.0.3 (January 8, 2020) ##
|
18
|
+
|
19
|
+
* Support json column (PR: #70)
|
20
|
+
|
21
|
+
*nishio-dens*
|
22
|
+
|
23
|
+
## Convergence 1.0.2 (May 24, 2019) ##
|
24
|
+
|
25
|
+
* Support ssl connections (PR: #69)
|
26
|
+
|
27
|
+
*yujideveloper*
|
28
|
+
|
29
|
+
## Convergence 1.0.1 (September 27, 2018) ##
|
30
|
+
|
31
|
+
* Add Rollback Dryrun command (PR: #64)
|
32
|
+
|
33
|
+
*nishio-dens*
|
34
|
+
|
1
35
|
## Convergence 1.0.0 (August 28, 2018) ##
|
2
36
|
|
3
37
|
* [BREAKING CHANGE] Change flag style command to sub-command style (PR: #60)
|
data/Gemfile.lock
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
convergence (1.0.
|
4
|
+
convergence (1.0.5)
|
5
5
|
diff-lcs
|
6
6
|
diffy
|
7
7
|
mysql2
|
8
|
-
thor
|
8
|
+
thor
|
9
9
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
ast (2.
|
14
|
-
coderay (1.1.
|
15
|
-
diff-lcs (1.
|
16
|
-
diffy (3.
|
17
|
-
ffi (1.
|
13
|
+
ast (2.4.1)
|
14
|
+
coderay (1.1.3)
|
15
|
+
diff-lcs (1.4.4)
|
16
|
+
diffy (3.4.0)
|
17
|
+
ffi (1.14.2)
|
18
18
|
formatador (0.2.5)
|
19
|
-
guard (2.
|
19
|
+
guard (2.16.2)
|
20
20
|
formatador (>= 0.2.4)
|
21
21
|
listen (>= 2.7, < 4.0)
|
22
|
-
lumberjack (
|
22
|
+
lumberjack (>= 1.0.12, < 2.0)
|
23
23
|
nenv (~> 0.1)
|
24
24
|
notiffany (~> 0.0)
|
25
25
|
pry (>= 0.9.12)
|
@@ -30,68 +30,69 @@ GEM
|
|
30
30
|
guard (~> 2.1)
|
31
31
|
guard-compat (~> 1.1)
|
32
32
|
rspec (>= 2.99.0, < 4.0)
|
33
|
-
listen (3.
|
34
|
-
rb-fsevent (~> 0.
|
35
|
-
rb-inotify (~> 0.9, >= 0.9.
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
mysql2 (0.5.2)
|
33
|
+
listen (3.3.3)
|
34
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
35
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
36
|
+
lumberjack (1.2.8)
|
37
|
+
method_source (1.0.0)
|
38
|
+
mysql2 (0.5.3)
|
40
39
|
nenv (0.3.0)
|
41
|
-
notiffany (0.1.
|
40
|
+
notiffany (0.1.3)
|
42
41
|
nenv (~> 0.1)
|
43
42
|
shellany (~> 0.0)
|
44
|
-
parallel (1.
|
45
|
-
parser (
|
46
|
-
ast (~> 2.
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
rspec (3.
|
58
|
-
rspec-core (~> 3.
|
59
|
-
rspec-expectations (~> 3.
|
60
|
-
rspec-mocks (~> 3.
|
61
|
-
rspec-core (3.
|
62
|
-
rspec-support (~> 3.
|
63
|
-
rspec-expectations (3.
|
43
|
+
parallel (1.20.1)
|
44
|
+
parser (3.0.0.0)
|
45
|
+
ast (~> 2.4.1)
|
46
|
+
pry (0.13.1)
|
47
|
+
coderay (~> 1.1)
|
48
|
+
method_source (~> 1.0)
|
49
|
+
rainbow (3.0.0)
|
50
|
+
rake (13.0.3)
|
51
|
+
rb-fsevent (0.10.4)
|
52
|
+
rb-inotify (0.10.1)
|
53
|
+
ffi (~> 1.0)
|
54
|
+
regexp_parser (2.0.3)
|
55
|
+
rexml (3.2.4)
|
56
|
+
rspec (3.10.0)
|
57
|
+
rspec-core (~> 3.10.0)
|
58
|
+
rspec-expectations (~> 3.10.0)
|
59
|
+
rspec-mocks (~> 3.10.0)
|
60
|
+
rspec-core (3.10.1)
|
61
|
+
rspec-support (~> 3.10.0)
|
62
|
+
rspec-expectations (3.10.1)
|
64
63
|
diff-lcs (>= 1.2.0, < 2.0)
|
65
|
-
rspec-support (~> 3.
|
66
|
-
rspec-mocks (3.
|
64
|
+
rspec-support (~> 3.10.0)
|
65
|
+
rspec-mocks (3.10.1)
|
67
66
|
diff-lcs (>= 1.2.0, < 2.0)
|
68
|
-
rspec-support (~> 3.
|
69
|
-
rspec-support (3.
|
70
|
-
rubocop (
|
67
|
+
rspec-support (~> 3.10.0)
|
68
|
+
rspec-support (3.10.1)
|
69
|
+
rubocop (1.7.0)
|
71
70
|
parallel (~> 1.10)
|
72
|
-
parser (>= 2.
|
73
|
-
|
74
|
-
|
71
|
+
parser (>= 2.7.1.5)
|
72
|
+
rainbow (>= 2.2.2, < 4.0)
|
73
|
+
regexp_parser (>= 1.8, < 3.0)
|
74
|
+
rexml
|
75
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
75
76
|
ruby-progressbar (~> 1.7)
|
76
|
-
unicode-display_width (
|
77
|
-
|
78
|
-
|
77
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
78
|
+
rubocop-ast (1.3.0)
|
79
|
+
parser (>= 2.7.1.5)
|
80
|
+
ruby-progressbar (1.11.0)
|
79
81
|
shellany (0.0.1)
|
80
|
-
thor (0.
|
81
|
-
unicode-display_width (1.
|
82
|
+
thor (1.0.1)
|
83
|
+
unicode-display_width (1.7.0)
|
82
84
|
|
83
85
|
PLATFORMS
|
84
86
|
ruby
|
85
87
|
|
86
88
|
DEPENDENCIES
|
87
|
-
bundler (~> 1.7)
|
88
89
|
convergence!
|
89
90
|
guard
|
90
91
|
guard-rspec
|
91
92
|
pry
|
92
|
-
rake (~>
|
93
|
+
rake (~> 13.0)
|
93
94
|
rspec (>= 3.5)
|
94
95
|
rubocop
|
95
96
|
|
96
97
|
BUNDLED WITH
|
97
|
-
1.
|
98
|
+
2.1.3
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# Convergence
|
2
2
|
|
3
3
|
Convergence is a pure-Ruby database schema migration tool.
|
4
|
-
Currently, This
|
4
|
+
Currently, This tool is support only MySQL.
|
5
5
|
|
6
6
|
It defines DB Schema using Convergence DSL(like Rails DSL).
|
7
|
-
For more information about Convergence DSL, See below 'Detail About Convergence DSL'
|
7
|
+
For more information about Convergence DSL, See below ['Detail About Convergence DSL'](#detail-about-convergence-dsl)
|
8
8
|
|
9
9
|
|
10
10
|
[](https://badge.fury.io/rb/convergence)
|
@@ -152,6 +152,32 @@ username: root
|
|
152
152
|
password:
|
153
153
|
```
|
154
154
|
|
155
|
+
#### Use SSL connection
|
156
|
+
|
157
|
+
If you would like to use SSL connection, you can specify SSL options in database.yml
|
158
|
+
|
159
|
+
```
|
160
|
+
$ cat database.yml
|
161
|
+
adapter: mysql
|
162
|
+
database: convergence_test
|
163
|
+
host: 127.0.0.1
|
164
|
+
username: root
|
165
|
+
password:
|
166
|
+
sslca: /path/to/ca-cert.pem
|
167
|
+
sslverify: true
|
168
|
+
```
|
169
|
+
|
170
|
+
Supported ssl options are below:
|
171
|
+
* `ssl_mode`
|
172
|
+
* `sslkey`
|
173
|
+
* `sslcert`
|
174
|
+
* `sslca`
|
175
|
+
* `sslcapath`
|
176
|
+
* `sslcipher`
|
177
|
+
* `sslverify`
|
178
|
+
|
179
|
+
See [the ssl options section of mysql2 README](https://github.com/brianmario/mysql2/tree/master#ssl-options) for more details of SSL options
|
180
|
+
|
155
181
|
### Export Your DB Schema
|
156
182
|
|
157
183
|
First, you need to create database.yml.
|
@@ -196,6 +222,13 @@ end
|
|
196
222
|
$ convergence apply example.schema -c database.yml --dry-run
|
197
223
|
```
|
198
224
|
|
225
|
+
### Rollback Dry run
|
226
|
+
|
227
|
+
```
|
228
|
+
$ convergence apply example.schema -c database.yml --rollback-dry-run
|
229
|
+
```
|
230
|
+
|
231
|
+
|
199
232
|
### Apply
|
200
233
|
|
201
234
|
```
|
@@ -239,6 +272,7 @@ Convergence is currently support column types below.
|
|
239
272
|
- datetime
|
240
273
|
- timestamp
|
241
274
|
- year
|
275
|
+
- json
|
242
276
|
|
243
277
|
```
|
244
278
|
create_table "tests", comment: 'Column type example' do |t|
|
data/convergence.gemspec
CHANGED
@@ -21,12 +21,11 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_dependency 'mysql2'
|
22
22
|
spec.add_dependency 'diff-lcs'
|
23
23
|
spec.add_dependency 'diffy'
|
24
|
-
spec.add_dependency 'thor'
|
24
|
+
spec.add_dependency 'thor'
|
25
25
|
|
26
|
-
spec.required_ruby_version = ">= 2.
|
26
|
+
spec.required_ruby_version = ">= 2.4.0"
|
27
27
|
|
28
|
-
spec.add_development_dependency '
|
29
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
30
29
|
spec.add_development_dependency 'rspec', '>= 3.5'
|
31
30
|
spec.add_development_dependency 'rubocop'
|
32
31
|
spec.add_development_dependency 'pry'
|
data/lib/convergence/cli.rb
CHANGED
@@ -5,18 +5,25 @@ require 'convergence/module'
|
|
5
5
|
require 'convergence/config'
|
6
6
|
|
7
7
|
class Convergence::CLI < Thor
|
8
|
-
default_command :__fallback # TODO: `__fallback` will be removed in a future version(maybe v0.4.0)
|
9
|
-
|
10
8
|
map %w[--version -v] => :version
|
11
9
|
|
12
10
|
desc 'apply FILE', 'execute sql to your database'
|
13
11
|
method_option :config, aliases: '-c', type: :string, required: true, desc: 'Database Yaml Setting'
|
14
12
|
method_option :dry_run, type: :boolean
|
13
|
+
method_option :rollback_dry_run, type: :boolean
|
14
|
+
|
15
|
+
def self.exit_on_failure?
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
15
19
|
def apply(file)
|
16
20
|
opts = { input: file }
|
17
21
|
if options[:dry_run]
|
18
22
|
require 'convergence/command/dryrun'
|
19
23
|
Convergence::Command::Dryrun.new(opts, config: config).execute
|
24
|
+
elsif options[:rollback_dry_run]
|
25
|
+
require 'convergence/command/rollback_dryrun'
|
26
|
+
Convergence::Command::RollbackDryrun.new(opts, config: config).execute
|
20
27
|
else
|
21
28
|
require 'convergence/command/apply'
|
22
29
|
Convergence::Command::Apply.new(opts, config: config).execute
|
@@ -44,61 +51,10 @@ class Convergence::CLI < Thor
|
|
44
51
|
puts "version #{Convergence::VERSION}"
|
45
52
|
end
|
46
53
|
|
47
|
-
# TODO: `__fallback` will be removed in a future version(maybe v0.4.0)
|
48
|
-
desc '', '', hide: true
|
49
|
-
method_option :config,
|
50
|
-
aliases: '-c', type: :string,
|
51
|
-
desc: 'Database Yaml Setting'
|
52
|
-
method_option :diff,
|
53
|
-
aliases: '-d', type: :array, default: nil,
|
54
|
-
banner: 'DSL1 DSL2'
|
55
|
-
method_option :export,
|
56
|
-
aliases: '-e', type: :boolean, default: false,
|
57
|
-
desc: 'export db schema to dsl'
|
58
|
-
method_option :input,
|
59
|
-
aliases: '-i', type: :string,
|
60
|
-
desc: 'Input DSL'
|
61
|
-
method_option :dryrun,
|
62
|
-
type: :boolean, default: false
|
63
|
-
method_option :apply,
|
64
|
-
type: :boolean, default: false,
|
65
|
-
desc: 'execute sql to your database'
|
66
|
-
def __fallback
|
67
|
-
command_klass =
|
68
|
-
if !options[:diff].nil? && !options[:diff].empty?
|
69
|
-
require 'convergence/command/diff'
|
70
|
-
opts = { diff: options[:diff] }
|
71
|
-
Convergence::Command::Diff
|
72
|
-
elsif options[:export]
|
73
|
-
require 'convergence/command/export'
|
74
|
-
opts = {}
|
75
|
-
Convergence::Command::Export
|
76
|
-
elsif options[:dryrun]
|
77
|
-
require 'convergence/command/dryrun'
|
78
|
-
opts = { input: options[:input] }
|
79
|
-
Convergence::Command::Dryrun
|
80
|
-
elsif options[:apply]
|
81
|
-
require 'convergence/command/apply'
|
82
|
-
opts = { input: options[:input] }
|
83
|
-
Convergence::Command::Apply
|
84
|
-
end
|
85
|
-
|
86
|
-
if command_klass
|
87
|
-
deprecation_warning
|
88
|
-
command_klass.new(opts, config: config).execute
|
89
|
-
else
|
90
|
-
help
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
54
|
private
|
95
55
|
|
96
56
|
def config
|
97
57
|
return unless options[:config]
|
98
58
|
@config ||= Convergence::Config.load(options[:config])
|
99
59
|
end
|
100
|
-
|
101
|
-
def deprecation_warning
|
102
|
-
warn '[DEPRECATION] Option style is deprecated. Please use subscommand style.'
|
103
|
-
end
|
104
60
|
end
|
data/lib/convergence/column.rb
CHANGED
data/lib/convergence/command.rb
CHANGED
@@ -12,6 +12,8 @@ class Convergence::Command
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
private
|
16
|
+
|
15
17
|
def database_adapter
|
16
18
|
@config.nil? ? 'mysql' : @config.adapter
|
17
19
|
end
|
@@ -30,16 +32,6 @@ class Convergence::Command
|
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
33
|
-
def sql_generator
|
34
|
-
@sql_generator ||= case database_adapter
|
35
|
-
when 'mysql', 'mysql2'
|
36
|
-
require 'convergence/sql_generator/mysql_generator'
|
37
|
-
SQLGenerator::MysqlGenerator.new
|
38
|
-
else
|
39
|
-
fail NotImplementedError.new('unknown database adapter')
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
35
|
def logger
|
44
36
|
@logger ||= Convergence::Logger.new
|
45
37
|
end
|
@@ -6,19 +6,34 @@ require 'convergence/default_parameter'
|
|
6
6
|
require 'convergence/diff'
|
7
7
|
|
8
8
|
class Convergence::Command::Apply < Convergence::Command
|
9
|
-
def validate!
|
10
|
-
fail ArgumentError.new('config required') if @config.nil?
|
11
|
-
fail ArgumentError.new('input required') unless @opts[:input]
|
12
|
-
end
|
13
|
-
|
14
9
|
def execute
|
15
|
-
validate!
|
16
10
|
current_dir_path = Pathname.new(@opts[:input]).realpath.dirname
|
17
11
|
input_tables = Convergence::DSL.parse(File.open(@opts[:input]).read, current_dir_path)
|
18
12
|
current_tables = dumper.dump
|
19
13
|
execute_sql(input_tables, current_tables)
|
20
14
|
end
|
21
15
|
|
16
|
+
def generate_sql(input_tables, current_tables)
|
17
|
+
current_tables_with_full_option =
|
18
|
+
Convergence::DefaultParameter.append_database_default_parameter(current_tables, database_adapter)
|
19
|
+
input_tables_with_full_option =
|
20
|
+
Convergence::DefaultParameter.append_database_default_parameter(input_tables, database_adapter)
|
21
|
+
delta = Convergence::Diff.new.diff(current_tables_with_full_option, input_tables_with_full_option)
|
22
|
+
sql_generator.generate(input_tables_with_full_option, delta, current_tables_with_full_option)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def sql_generator
|
28
|
+
@sql_generator ||= case database_adapter
|
29
|
+
when 'mysql', 'mysql2'
|
30
|
+
require 'convergence/sql_generator/mysql_generator'
|
31
|
+
SQLGenerator::MysqlGenerator.new
|
32
|
+
else
|
33
|
+
fail NotImplementedError.new('unknown database adapter')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
22
37
|
def execute_sql(input_tables, current_tables)
|
23
38
|
sql = generate_sql(input_tables, current_tables)
|
24
39
|
unless sql.strip.empty?
|
@@ -45,13 +60,4 @@ SET FOREIGN_KEY_CHECKS=1;
|
|
45
60
|
end
|
46
61
|
end
|
47
62
|
end
|
48
|
-
|
49
|
-
def generate_sql(input_tables, current_tables)
|
50
|
-
current_tables_with_full_option =
|
51
|
-
Convergence::DefaultParameter.append_database_default_parameter(current_tables, database_adapter)
|
52
|
-
input_tables_with_full_option =
|
53
|
-
Convergence::DefaultParameter.append_database_default_parameter(input_tables, database_adapter)
|
54
|
-
delta = Convergence::Diff.new.diff(current_tables_with_full_option, input_tables_with_full_option)
|
55
|
-
sql_generator.generate(input_tables_with_full_option, delta, current_tables_with_full_option)
|
56
|
-
end
|
57
63
|
end
|
@@ -5,14 +5,7 @@ require 'convergence/pretty_diff'
|
|
5
5
|
require 'convergence/dsl'
|
6
6
|
|
7
7
|
class Convergence::Command::Diff < Convergence::Command
|
8
|
-
def validate!
|
9
|
-
unless @opts[:diff].size == 2
|
10
|
-
fail ArgumentError.new('diff required two arguments')
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
8
|
def execute
|
15
|
-
validate!
|
16
9
|
from = Convergence::DefaultParameter.remove_database_default_parameter(from_tables, database_adapter)
|
17
10
|
to = Convergence::DefaultParameter.remove_database_default_parameter(to_tables, database_adapter)
|
18
11
|
msg = Convergence::PrettyDiff.new(from, to).output
|
@@ -6,13 +6,7 @@ require 'convergence/default_parameter'
|
|
6
6
|
require 'convergence/pretty_diff'
|
7
7
|
|
8
8
|
class Convergence::Command::Dryrun < Convergence::Command
|
9
|
-
def validate!
|
10
|
-
fail ArgumentError.new('config required') if @config.nil?
|
11
|
-
fail ArgumentError.new('input required') unless @opts[:input]
|
12
|
-
end
|
13
|
-
|
14
9
|
def execute
|
15
|
-
validate!
|
16
10
|
current_dir_path = Pathname.new(@opts[:input]).realpath.dirname
|
17
11
|
input_tables = Convergence::DSL.parse(File.open(@opts[:input]).read, current_dir_path)
|
18
12
|
current_tables = dumper.dump
|
@@ -21,6 +15,8 @@ class Convergence::Command::Dryrun < Convergence::Command
|
|
21
15
|
output_sql(input_tables, current_tables)
|
22
16
|
end
|
23
17
|
|
18
|
+
private
|
19
|
+
|
24
20
|
def output_diff(input_tables, current_tables)
|
25
21
|
input_tables_without_default_parameter =
|
26
22
|
Convergence::DefaultParameter.remove_database_default_parameter(input_tables, database_adapter)
|
@@ -41,7 +37,7 @@ class Convergence::Command::Dryrun < Convergence::Command
|
|
41
37
|
.split("\n")
|
42
38
|
.map { |v| '# ' + v }
|
43
39
|
.join("\n")
|
44
|
-
logger.output(msg)
|
40
|
+
logger.output(msg) unless msg.empty?
|
45
41
|
msg
|
46
42
|
end
|
47
43
|
end
|
@@ -3,14 +3,7 @@ require 'convergence/dumper'
|
|
3
3
|
require 'convergence/default_parameter'
|
4
4
|
|
5
5
|
class Convergence::Command::Export < Convergence::Command
|
6
|
-
def validate!
|
7
|
-
if @config.nil?
|
8
|
-
fail ArgumentError.new('config required')
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
6
|
def execute
|
13
|
-
validate!
|
14
7
|
tables = Convergence::DefaultParameter.remove_database_default_parameter(dumper.dump, database_adapter)
|
15
8
|
msg = Convergence::Dumper.new.dump_dsl(tables)
|
16
9
|
logger.output(msg)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'convergence/command'
|
3
|
+
require 'convergence/command/apply'
|
4
|
+
require 'convergence/dsl'
|
5
|
+
require 'convergence/default_parameter'
|
6
|
+
|
7
|
+
class Convergence::Command::RollbackDryrun < Convergence::Command
|
8
|
+
def execute
|
9
|
+
current_dir_path = Pathname.new(@opts[:input]).realpath.dirname
|
10
|
+
input_tables = Convergence::DSL.parse(File.open(@opts[:input]).read, current_dir_path)
|
11
|
+
current_tables = dumper.dump
|
12
|
+
|
13
|
+
output_sql(current_tables, input_tables)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def output_sql(input_tables, current_tables)
|
19
|
+
msg = Convergence::Command::Apply
|
20
|
+
.new(@opts, config: @config)
|
21
|
+
.generate_sql(input_tables, current_tables)
|
22
|
+
.split("\n")
|
23
|
+
.map { |v| '# ' + v }
|
24
|
+
.join("\n")
|
25
|
+
logger.output(msg)
|
26
|
+
msg
|
27
|
+
end
|
28
|
+
end
|
data/lib/convergence/config.rb
CHANGED
@@ -4,7 +4,33 @@ require 'yaml'
|
|
4
4
|
class Convergence::Config
|
5
5
|
ATTRIBUTES = %i[adapter database host port username password].freeze
|
6
6
|
|
7
|
-
attr_accessor(*ATTRIBUTES)
|
7
|
+
attr_accessor(*ATTRIBUTES, :mysql)
|
8
|
+
|
9
|
+
class MySQL
|
10
|
+
ATTRIBUTES = %i[ssl_mode sslkey sslcert sslca sslcapath sslcipher sslverify].freeze
|
11
|
+
|
12
|
+
attr_accessor(*ATTRIBUTES)
|
13
|
+
|
14
|
+
def initialize(attributes)
|
15
|
+
attributes.each do |k, v|
|
16
|
+
next if v.nil?
|
17
|
+
next if !ATTRIBUTES.include?(k.to_sym) && !ATTRIBUTES.include?(k.to_s)
|
18
|
+
instance_variable_set("@#{k}", v)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def ssl_options
|
23
|
+
{
|
24
|
+
ssl_mode: ssl_mode,
|
25
|
+
sslkey: sslkey,
|
26
|
+
sslcert: sslcert,
|
27
|
+
sslca: sslca,
|
28
|
+
sslcapath: sslcapath,
|
29
|
+
sslcipher: sslcipher,
|
30
|
+
sslverify: sslverify
|
31
|
+
}.compact
|
32
|
+
end
|
33
|
+
end
|
8
34
|
|
9
35
|
def initialize(attributes)
|
10
36
|
attributes.each do |k, v|
|
@@ -12,6 +38,10 @@ class Convergence::Config
|
|
12
38
|
next if !ATTRIBUTES.include?(k.to_sym) && !ATTRIBUTES.include?(k.to_s)
|
13
39
|
instance_variable_set("@#{k}", v)
|
14
40
|
end
|
41
|
+
case adapter
|
42
|
+
when 'mysql', 'mysql2'
|
43
|
+
@mysql = MySQL.new(attributes)
|
44
|
+
end
|
15
45
|
end
|
16
46
|
|
17
47
|
def self.load(yaml_path)
|
@@ -10,21 +10,25 @@ class Convergence::DatabaseConnector::MysqlConnector
|
|
10
10
|
|
11
11
|
def client(database_name = @config.database)
|
12
12
|
@mysql ||= Mysql2::Client.new(
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
{
|
14
|
+
host: @config.host,
|
15
|
+
port: @config.port,
|
16
|
+
username: @config.username,
|
17
|
+
password: @config.password,
|
18
|
+
database: database_name
|
19
|
+
}.merge!(@config.mysql.ssl_options)
|
18
20
|
)
|
19
21
|
end
|
20
22
|
|
21
23
|
def schema_client
|
22
24
|
@schema_mysql ||= Mysql2::Client.new(
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
{
|
26
|
+
host: @config.host,
|
27
|
+
port: @config.port,
|
28
|
+
username: @config.username,
|
29
|
+
password: @config.password,
|
30
|
+
database: 'information_schema'
|
31
|
+
}.merge!(@config.mysql.ssl_options)
|
28
32
|
)
|
29
33
|
end
|
30
34
|
end
|
data/lib/convergence/diff.rb
CHANGED
@@ -99,7 +99,7 @@ class Convergence::Diff
|
|
99
99
|
from_columns = from.columns.keys
|
100
100
|
to_columns = to.columns.keys
|
101
101
|
order_changed_columns = Diff::LCS.diff(from_columns, to_columns)
|
102
|
-
.flatten
|
102
|
+
.flatten(1)
|
103
103
|
.select(&:adding?)
|
104
104
|
.map(&:element)
|
105
105
|
order_changed_columns.each do |column|
|
data/lib/convergence/dumper.rb
CHANGED
data/lib/convergence/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: convergence
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shinsuke Nishio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mysql2
|
@@ -56,44 +56,30 @@ dependencies:
|
|
56
56
|
name: thor
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0
|
61
|
+
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0.20'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: bundler
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '1.7'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
66
|
+
- - ">="
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
68
|
+
version: '0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: rake
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
73
|
- - "~>"
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
75
|
+
version: '13.0'
|
90
76
|
type: :development
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
80
|
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
82
|
+
version: '13.0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: rspec
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -194,6 +180,7 @@ files:
|
|
194
180
|
- lib/convergence/command/diff.rb
|
195
181
|
- lib/convergence/command/dryrun.rb
|
196
182
|
- lib/convergence/command/export.rb
|
183
|
+
- lib/convergence/command/rollback_dryrun.rb
|
197
184
|
- lib/convergence/config.rb
|
198
185
|
- lib/convergence/database_connector.rb
|
199
186
|
- lib/convergence/database_connector/mysql_connector.rb
|
@@ -242,15 +229,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
242
229
|
requirements:
|
243
230
|
- - ">="
|
244
231
|
- !ruby/object:Gem::Version
|
245
|
-
version: 2.
|
232
|
+
version: 2.4.0
|
246
233
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
247
234
|
requirements:
|
248
235
|
- - ">="
|
249
236
|
- !ruby/object:Gem::Version
|
250
237
|
version: '0'
|
251
238
|
requirements: []
|
252
|
-
|
253
|
-
rubygems_version: 2.6.8
|
239
|
+
rubygems_version: 3.1.2
|
254
240
|
signing_key:
|
255
241
|
specification_version: 4
|
256
242
|
summary: DB Schema management tool
|