convergence 1.0.1 → 1.0.2
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/CHANGELOG.md +6 -0
- data/Gemfile.lock +4 -4
- data/convergence.gemspec +1 -1
- data/lib/convergence/cli.rb +0 -53
- 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 +2 -6
- data/lib/convergence/command/export.rb +0 -7
- data/lib/convergence/command/rollback_dryrun.rb +2 -6
- data/lib/convergence/config.rb +31 -1
- data/lib/convergence/database_connector/mysql_connector.rb +14 -10
- data/lib/convergence/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d589a1c75e088d6e45f8dc8b3d0afdab65025b9f6ac1cb1abf919703dbc34682
|
4
|
+
data.tar.gz: e01d8e2e02c26f1c9d8bc80a7aeb2e3b425eded2c138203d3cb8e3ad602ab7d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2622208e674c2192813556e25911b72db056fc57a369928e99047efcc97e66f7b152a1a2e8bec37f5aba7ddc27831d27357b9cea5d8aecda2526ae844f0068a0
|
7
|
+
data.tar.gz: ec99f89c4803f0dd2033d915de708b01b5d7e176c80f483e2abcdab9ecade94991992f2f67dbc9e54bded4dbf4501b99aaa01e308c5d8b54d833868d2010418c
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
convergence (1.0.
|
4
|
+
convergence (1.0.2)
|
5
5
|
diff-lcs
|
6
6
|
diffy
|
7
7
|
mysql2
|
@@ -13,8 +13,8 @@ GEM
|
|
13
13
|
ast (2.3.0)
|
14
14
|
coderay (1.1.2)
|
15
15
|
diff-lcs (1.3)
|
16
|
-
diffy (3.
|
17
|
-
ffi (1.
|
16
|
+
diffy (3.3.0)
|
17
|
+
ffi (1.11.1)
|
18
18
|
formatador (0.2.5)
|
19
19
|
guard (2.14.1)
|
20
20
|
formatador (>= 0.2.4)
|
@@ -94,4 +94,4 @@ DEPENDENCIES
|
|
94
94
|
rubocop
|
95
95
|
|
96
96
|
BUNDLED WITH
|
97
|
-
1.
|
97
|
+
1.17.1
|
data/convergence.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_dependency 'diffy'
|
24
24
|
spec.add_dependency 'thor', '~> 0.20'
|
25
25
|
|
26
|
-
spec.required_ruby_version = ">= 2.
|
26
|
+
spec.required_ruby_version = ">= 2.4.0"
|
27
27
|
|
28
28
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
29
29
|
spec.add_development_dependency 'rake', '~> 10.0'
|
data/lib/convergence/cli.rb
CHANGED
@@ -5,8 +5,6 @@ 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 v1.1.0)
|
9
|
-
|
10
8
|
map %w[--version -v] => :version
|
11
9
|
|
12
10
|
desc 'apply FILE', 'execute sql to your database'
|
@@ -48,61 +46,10 @@ class Convergence::CLI < Thor
|
|
48
46
|
puts "version #{Convergence::VERSION}"
|
49
47
|
end
|
50
48
|
|
51
|
-
# TODO: `__fallback` will be removed in a future version(maybe v1.1.0)
|
52
|
-
desc '', '', hide: true
|
53
|
-
method_option :config,
|
54
|
-
aliases: '-c', type: :string,
|
55
|
-
desc: 'Database Yaml Setting'
|
56
|
-
method_option :diff,
|
57
|
-
aliases: '-d', type: :array, default: nil,
|
58
|
-
banner: 'DSL1 DSL2'
|
59
|
-
method_option :export,
|
60
|
-
aliases: '-e', type: :boolean, default: false,
|
61
|
-
desc: 'export db schema to dsl'
|
62
|
-
method_option :input,
|
63
|
-
aliases: '-i', type: :string,
|
64
|
-
desc: 'Input DSL'
|
65
|
-
method_option :dryrun,
|
66
|
-
type: :boolean, default: false
|
67
|
-
method_option :apply,
|
68
|
-
type: :boolean, default: false,
|
69
|
-
desc: 'execute sql to your database'
|
70
|
-
def __fallback
|
71
|
-
command_klass =
|
72
|
-
if !options[:diff].nil? && !options[:diff].empty?
|
73
|
-
require 'convergence/command/diff'
|
74
|
-
opts = { diff: options[:diff] }
|
75
|
-
Convergence::Command::Diff
|
76
|
-
elsif options[:export]
|
77
|
-
require 'convergence/command/export'
|
78
|
-
opts = {}
|
79
|
-
Convergence::Command::Export
|
80
|
-
elsif options[:dryrun]
|
81
|
-
require 'convergence/command/dryrun'
|
82
|
-
opts = { input: options[:input] }
|
83
|
-
Convergence::Command::Dryrun
|
84
|
-
elsif options[:apply]
|
85
|
-
require 'convergence/command/apply'
|
86
|
-
opts = { input: options[:input] }
|
87
|
-
Convergence::Command::Apply
|
88
|
-
end
|
89
|
-
|
90
|
-
if command_klass
|
91
|
-
deprecation_warning
|
92
|
-
command_klass.new(opts, config: config).execute
|
93
|
-
else
|
94
|
-
help
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
49
|
private
|
99
50
|
|
100
51
|
def config
|
101
52
|
return unless options[:config]
|
102
53
|
@config ||= Convergence::Config.load(options[:config])
|
103
54
|
end
|
104
|
-
|
105
|
-
def deprecation_warning
|
106
|
-
warn '[DEPRECATION] Flag style command is deprecated. Please use sub-command style instead.'
|
107
|
-
end
|
108
55
|
end
|
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)
|
@@ -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)
|
@@ -5,13 +5,7 @@ require 'convergence/dsl'
|
|
5
5
|
require 'convergence/default_parameter'
|
6
6
|
|
7
7
|
class Convergence::Command::RollbackDryrun < Convergence::Command
|
8
|
-
def validate!
|
9
|
-
fail ArgumentError.new('config required') if @config.nil?
|
10
|
-
fail ArgumentError.new('input required') unless @opts[:input]
|
11
|
-
end
|
12
|
-
|
13
8
|
def execute
|
14
|
-
validate!
|
15
9
|
current_dir_path = Pathname.new(@opts[:input]).realpath.dirname
|
16
10
|
input_tables = Convergence::DSL.parse(File.open(@opts[:input]).read, current_dir_path)
|
17
11
|
current_tables = dumper.dump
|
@@ -19,6 +13,8 @@ class Convergence::Command::RollbackDryrun < Convergence::Command
|
|
19
13
|
output_sql(current_tables, input_tables)
|
20
14
|
end
|
21
15
|
|
16
|
+
private
|
17
|
+
|
22
18
|
def output_sql(input_tables, current_tables)
|
23
19
|
msg = Convergence::Command::Apply
|
24
20
|
.new(@opts, config: @config)
|
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/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.2
|
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: 2019-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mysql2
|
@@ -243,7 +243,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
243
243
|
requirements:
|
244
244
|
- - ">="
|
245
245
|
- !ruby/object:Gem::Version
|
246
|
-
version: 2.
|
246
|
+
version: 2.4.0
|
247
247
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
248
248
|
requirements:
|
249
249
|
- - ">="
|
@@ -251,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
251
251
|
version: '0'
|
252
252
|
requirements: []
|
253
253
|
rubyforge_project:
|
254
|
-
rubygems_version: 2.6
|
254
|
+
rubygems_version: 2.7.6
|
255
255
|
signing_key:
|
256
256
|
specification_version: 4
|
257
257
|
summary: DB Schema management tool
|