ridgepole 0.8.8 → 0.9.0.beta
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/.github/workflows/test.yml +65 -0
- data/.rubocop.yml +11 -36
- data/Appraisals +4 -5
- data/README.md +27 -17
- data/bin/ridgepole +13 -1
- data/gemfiles/{activerecord_5.0.gemfile → activerecord_6.1.gemfile} +1 -2
- data/lib/ridgepole/client.rb +8 -3
- data/lib/ridgepole/default_limit.rb +1 -1
- data/lib/ridgepole/delta.rb +16 -1
- data/lib/ridgepole/diff.rb +55 -20
- data/lib/ridgepole/dsl_parser.rb +3 -4
- data/lib/ridgepole/dsl_parser/context.rb +1 -1
- data/lib/ridgepole/dsl_parser/table_definition.rb +51 -41
- data/lib/ridgepole/execute_expander.rb +10 -1
- data/lib/ridgepole/ext/abstract_adapter/disable_table_options.rb +9 -1
- data/lib/ridgepole/external_sql_executer.rb +12 -1
- data/lib/ridgepole/version.rb +1 -1
- data/ridgepole.gemspec +5 -3
- data/spec/erb_helper.rb +9 -5
- data/spec/mysql/_migrate/migrate_change_table_option_spec.rb +2 -2
- data/spec/mysql/cli/ridgepole_spec.rb +35 -1
- data/spec/mysql/collation/collation_spec.rb +8 -8
- data/spec/mysql/dump/dump_class_method_spec.rb +3 -3
- data/spec/mysql/dump/dump_spec.rb +3 -3
- data/spec/mysql/dump/dump_unknown_column_type_spec.rb +1 -1
- data/spec/mysql/dump/dump_without_table_options_spec.rb +2 -2
- data/spec/mysql/fk/migrate_create_fk_spec.rb +79 -10
- data/spec/mysql/migrate/migrate_add_column_with_alter_extra_spec.rb +88 -0
- data/spec/mysql/migrate/migrate_change_column3_spec.rb +109 -18
- data/spec/mysql/migrate/migrate_change_column8_spec.rb +38 -5
- data/spec/mysql/migrate/migrate_change_index_spec.rb +7 -1
- data/spec/mysql/migrate/migrate_check_relation_column_type_spec.rb +4 -4
- data/spec/mysql/migrate/migrate_primary_key_spec.rb +30 -5
- data/spec/mysql/migrate/migrate_same_spec.rb +3 -3
- data/spec/mysql/text_blob_types/text_blob_types_spec.rb +5 -2
- data/spec/postgresql/dump/dump_spec.rb +1 -1
- data/spec/postgresql/migrate/migrate_add_column_spec.rb +11 -4
- data/spec/postgresql/migrate/migrate_change_column_spec.rb +4 -0
- data/spec/postgresql/migrate/migrate_drop_column_spec.rb +11 -4
- data/spec/postgresql/migrate/migrate_same_spec.rb +1 -1
- data/spec/spec_condition.rb +4 -0
- data/spec/spec_helper.rb +2 -1
- metadata +43 -20
- data/.travis.yml +0 -45
- data/lib/ridgepole/ext/abstract_mysql_adapter/use_alter_index.rb +0 -31
- data/spec/mysql/migrate_/migrate_create_index_with_alter_spec.rb +0 -141
- data/spec/mysql/migrate_/migrate_drop_index_with_alter_spec.rb +0 -141
data/lib/ridgepole/dsl_parser.rb
CHANGED
@@ -37,11 +37,10 @@ module Ridgepole
|
|
37
37
|
attrs[:foreign_keys].each do |_, foreign_key_attrs|
|
38
38
|
fk_index = foreign_key_attrs[:options][:column] || "#{foreign_key_attrs[:to_table].singularize}_id"
|
39
39
|
next if attrs[:indices]&.any? { |_k, v| v[:column_name].first == fk_index }
|
40
|
+
# NOTE: For composite primary keys, the first column of the primary key is used as the foreign key index
|
41
|
+
next if Array(attrs[:options][:primary_key]).first == fk_index
|
40
42
|
|
41
|
-
|
42
|
-
[WARNING] Table `#{table_name}` has a foreign key on `#{fk_index}` column, but doesn't have any indexes on the column.
|
43
|
-
Although an index will be added automatically by InnoDB, please add an index explicitly for your future operations.
|
44
|
-
MSG
|
43
|
+
raise "The column `#{fk_index}` of the table `#{table_name}` has a foreign key but no index. Although InnoDB creates an index automatically, please add one explicitly in order for ridgepole to manage it."
|
45
44
|
end
|
46
45
|
end
|
47
46
|
end
|
@@ -27,7 +27,7 @@ module Ridgepole
|
|
27
27
|
table_name = table_name.to_s
|
28
28
|
table_definition = TableDefinition.new(table_name, self)
|
29
29
|
|
30
|
-
options[:primary_key] = options[:primary_key].to_s if options[:primary_key]
|
30
|
+
options[:primary_key] = options[:primary_key].to_s if options[:primary_key].is_a?(Symbol)
|
31
31
|
if options[:id] && TableDefinition::ALIAS_TYPES.key?(options[:id])
|
32
32
|
type, type_default_opts = TableDefinition::ALIAS_TYPES[options[:id]]
|
33
33
|
options[:id] = type
|
@@ -22,57 +22,60 @@ module Ridgepole
|
|
22
22
|
|
23
23
|
DEFAULT_PRIMARY_KEY_TYPE = Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('5.1') ? :bigint : :integer
|
24
24
|
|
25
|
-
TYPES =
|
25
|
+
TYPES = {
|
26
26
|
# https://github.com/rails/rails/blob/v4.2.1/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb#L274
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
34
|
-
:
|
35
|
-
:
|
36
|
-
:
|
37
|
-
:
|
38
|
-
:
|
27
|
+
string: {},
|
28
|
+
text: {},
|
29
|
+
integer: {},
|
30
|
+
bigint: {},
|
31
|
+
float: {},
|
32
|
+
decimal: {},
|
33
|
+
datetime: {},
|
34
|
+
timestamp: {},
|
35
|
+
time: {},
|
36
|
+
date: {},
|
37
|
+
binary: {},
|
38
|
+
boolean: {},
|
39
39
|
|
40
40
|
# https://github.com/rails/rails/blob/v4.2.1/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L79
|
41
|
-
:
|
42
|
-
:
|
43
|
-
:
|
44
|
-
:
|
45
|
-
:
|
46
|
-
:
|
47
|
-
:
|
48
|
-
:
|
49
|
-
:
|
50
|
-
:
|
51
|
-
:
|
52
|
-
:
|
53
|
-
:
|
54
|
-
:
|
55
|
-
:
|
56
|
-
:
|
57
|
-
:
|
58
|
-
:
|
59
|
-
:
|
60
|
-
:
|
61
|
-
:
|
62
|
-
:
|
63
|
-
:
|
64
|
-
:
|
41
|
+
serial: { null: false },
|
42
|
+
bigserial: { null: false },
|
43
|
+
daterange: {},
|
44
|
+
numrange: {},
|
45
|
+
tsrange: {},
|
46
|
+
tstzrange: {},
|
47
|
+
int4range: {},
|
48
|
+
int8range: {},
|
49
|
+
# binary: {}, # dup key
|
50
|
+
# boolean: {}, # dup key
|
51
|
+
# bigint: {}, # dup key
|
52
|
+
xml: {},
|
53
|
+
tsvector: {},
|
54
|
+
hstore: {},
|
55
|
+
inet: {},
|
56
|
+
cidr: {},
|
57
|
+
macaddr: {},
|
58
|
+
uuid: {},
|
59
|
+
json: {},
|
60
|
+
jsonb: {},
|
61
|
+
ltree: {},
|
62
|
+
citext: {},
|
63
|
+
point: {},
|
64
|
+
bit: {},
|
65
|
+
bit_varying: {},
|
66
|
+
money: {},
|
65
67
|
|
66
68
|
# https://github.com/rails/rails/blob/v5.1.1/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb#L184
|
67
|
-
:
|
69
|
+
virtual: {},
|
68
70
|
|
69
71
|
# https://github.com/rails/rails/blob/v5.0.4/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb#L53
|
70
|
-
:
|
71
|
-
|
72
|
+
# json: {}, # dup key
|
73
|
+
}.freeze
|
72
74
|
|
73
|
-
TYPES.each do |column_type|
|
75
|
+
TYPES.each do |column_type, default_options|
|
74
76
|
define_method column_type do |*args|
|
75
77
|
options = args.extract_options!
|
78
|
+
options = default_options.merge(options)
|
76
79
|
column_names = args
|
77
80
|
column_names.each { |name| column(name, column_type, options) }
|
78
81
|
end
|
@@ -131,6 +134,7 @@ module Ridgepole
|
|
131
134
|
polymorphic_options.merge!(options.slice(:null, :first, :after))
|
132
135
|
index_options = options.key?(:index) ? options.delete(:index) : true
|
133
136
|
type = options.delete(:type) || DEFAULT_PRIMARY_KEY_TYPE
|
137
|
+
foreign_key_options = options.delete(:foreign_key)
|
134
138
|
|
135
139
|
args.each do |col|
|
136
140
|
column("#{col}_id", type, options)
|
@@ -139,6 +143,12 @@ module Ridgepole
|
|
139
143
|
columns = polymorphic ? ["#{col}_type", "#{col}_id"] : ["#{col}_id"]
|
140
144
|
index(columns, index_options.is_a?(Hash) ? index_options : {})
|
141
145
|
end
|
146
|
+
if foreign_key_options # rubocop:disable Style/Next
|
147
|
+
fk_opts = foreign_key_options.is_a?(Hash) ? foreign_key_options.dup : {}
|
148
|
+
fk_opts.update(column: "#{col}_id") if col.to_s.singularize != col.to_s
|
149
|
+
to_table = fk_opts.delete(:to_table) || col.to_s.pluralize
|
150
|
+
@base.add_foreign_key(@table_name, to_table, fk_opts)
|
151
|
+
end
|
142
152
|
end
|
143
153
|
end
|
144
154
|
alias belongs_to references
|
@@ -46,7 +46,16 @@ module Ridgepole
|
|
46
46
|
private
|
47
47
|
|
48
48
|
def append_alter_extra(sql)
|
49
|
-
|
49
|
+
if Ridgepole::ExecuteExpander.alter_extra
|
50
|
+
case sql
|
51
|
+
when /\AALTER\b/i
|
52
|
+
sql += ',' + Ridgepole::ExecuteExpander.alter_extra
|
53
|
+
when /\A(CREATE|DROP)\s+INDEX\b/i
|
54
|
+
# https://dev.mysql.com/doc/refman/5.6/en/create-index.html
|
55
|
+
# https://dev.mysql.com/doc/refman/5.6/en/drop-index.html
|
56
|
+
sql += ' ' + Ridgepole::ExecuteExpander.alter_extra.tr(',', ' ')
|
57
|
+
end
|
58
|
+
end
|
50
59
|
|
51
60
|
sql
|
52
61
|
end
|
@@ -15,7 +15,15 @@ module Ridgepole
|
|
15
15
|
|
16
16
|
def table_options(table_name)
|
17
17
|
options = super
|
18
|
-
|
18
|
+
|
19
|
+
if options && @__without_table_options
|
20
|
+
options.delete(:options)
|
21
|
+
|
22
|
+
# For >= AR 6.1.0
|
23
|
+
options.delete(:charset)
|
24
|
+
options.delete(:collation)
|
25
|
+
end
|
26
|
+
|
19
27
|
options
|
20
28
|
end
|
21
29
|
end
|
@@ -8,7 +8,7 @@ module Ridgepole
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def execute(sql)
|
11
|
-
cmd = Shellwords.join([@script, sql, JSON.dump(
|
11
|
+
cmd = Shellwords.join([@script, sql, JSON.dump(connection_configuration_hash)])
|
12
12
|
@logger.info("Execute #{@script}")
|
13
13
|
script_basename = File.basename(@script)
|
14
14
|
|
@@ -48,5 +48,16 @@ module Ridgepole
|
|
48
48
|
raise "`#{@script}` execution failed" unless wait_thr.value.success?
|
49
49
|
end
|
50
50
|
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def connection_configuration_hash
|
55
|
+
if ActiveRecord.gem_version < Gem::Version.new('6.1.0')
|
56
|
+
# NOTE: Remove code when stopping support for versions below 6.1
|
57
|
+
ActiveRecord::Base.connection_config
|
58
|
+
else
|
59
|
+
ActiveRecord::Base.connection_db_config.configuration_hash
|
60
|
+
end
|
61
|
+
end
|
51
62
|
end
|
52
63
|
end
|
data/lib/ridgepole/version.rb
CHANGED
data/ridgepole.gemspec
CHANGED
@@ -19,9 +19,9 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.required_ruby_version = Gem::Requirement.new('>= 2.2.7')
|
22
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.2.7') # rubocop:disable Gemspec/RequiredRubyVersion
|
23
23
|
|
24
|
-
spec.add_dependency 'activerecord', '>= 5.
|
24
|
+
spec.add_dependency 'activerecord', '>= 5.1', '< 6.2'
|
25
25
|
spec.add_dependency 'diffy'
|
26
26
|
|
27
27
|
spec.add_development_dependency 'appraisal', '>= 2.2.0'
|
@@ -36,5 +36,7 @@ Gem::Specification.new do |spec|
|
|
36
36
|
spec.add_development_dependency 'rspec', '>= 3.0.0'
|
37
37
|
spec.add_development_dependency 'rspec-match_fuzzy', '>= 0.1.3'
|
38
38
|
spec.add_development_dependency 'rspec-match_ruby', '>= 0.1.3'
|
39
|
-
spec.add_development_dependency 'rubocop', '>=
|
39
|
+
spec.add_development_dependency 'rubocop', '>= 1.7.0'
|
40
|
+
spec.add_development_dependency 'rubocop-rake', '>= 0.5.1'
|
41
|
+
spec.add_development_dependency 'rubocop-rspec', '>= 2.1.0'
|
40
42
|
end
|
data/spec/erb_helper.rb
CHANGED
@@ -14,13 +14,17 @@ ERBh.define_method(:i) do |obj|
|
|
14
14
|
end
|
15
15
|
|
16
16
|
ERBh.define_method(:cond) do |conds, m, e = nil|
|
17
|
-
if
|
17
|
+
if conds.is_a?(Hash)
|
18
|
+
conds.find do |c, _|
|
19
|
+
condition(c)
|
20
|
+
end&.last || m
|
21
|
+
elsif condition(conds)
|
18
22
|
m
|
19
23
|
else
|
20
24
|
e || (begin
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
+
m.class.new
|
26
|
+
rescue StandardError
|
27
|
+
nil
|
28
|
+
end)
|
25
29
|
end
|
26
30
|
end
|
@@ -4,7 +4,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
4
4
|
context 'when change mysql table options' do
|
5
5
|
let(:actual_dsl) do
|
6
6
|
erbh(<<-ERB)
|
7
|
-
create_table "employees", primary_key: "emp_no", force: :cascade, options: "ENGINE=MyISAM DEFAULT CHARSET=utf8" do |t|
|
7
|
+
create_table "employees", primary_key: "emp_no", force: :cascade, <%= i cond(">= 6.1", { charset: "utf8", options: "ENGINE=MyISAM" }, { options: "ENGINE=MyISAM DEFAULT CHARSET=utf8" }) %> do |t|
|
8
8
|
t.date "birth_date", null: false
|
9
9
|
t.string "first_name", limit: 14, null: false
|
10
10
|
t.string "last_name", limit: 16, null: false
|
@@ -16,7 +16,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
16
16
|
|
17
17
|
let(:expected_dsl) do
|
18
18
|
erbh(<<-ERB)
|
19
|
-
create_table "employees", primary_key: "emp_no", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=ascii" do |t|
|
19
|
+
create_table "employees", primary_key: "emp_no", force: :cascade, <%= i cond(">= 6.1", { charset: "ascii" }, { options: "ENGINE=InnoDB DEFAULT CHARSET=ascii" }) %> do |t|
|
20
20
|
t.date "birth_date", null: false
|
21
21
|
t.string "first_name", limit: 14, null: false, <%= i cond('>= 5.2', collation: "utf8_general_ci") %>
|
22
22
|
t.string "last_name", limit: 16, null: false, <%= i cond('>= 5.2', collation: "utf8_general_ci") %>
|
@@ -23,6 +23,7 @@ describe 'ridgepole' do
|
|
23
23
|
-f, --file SCHEMAFILE
|
24
24
|
--dry-run
|
25
25
|
--table-options OPTIONS
|
26
|
+
--table-hash-options OPTIONS
|
26
27
|
--alter-extra ALTER_SPEC
|
27
28
|
--external-script SCRIPT
|
28
29
|
--bulk-change
|
@@ -43,7 +44,6 @@ describe 'ridgepole' do
|
|
43
44
|
-o, --output SCHEMAFILE
|
44
45
|
-t, --tables TABLES
|
45
46
|
--ignore-tables REGEX_LIST
|
46
|
-
--mysql-use-alter
|
47
47
|
--dump-without-table-options
|
48
48
|
--dump-with-default-fk-name
|
49
49
|
--index-removed-drop-column
|
@@ -192,6 +192,40 @@ describe 'ridgepole' do
|
|
192
192
|
end
|
193
193
|
end
|
194
194
|
|
195
|
+
context 'apply with --table-hash-options' do
|
196
|
+
context 'given flatten json' do
|
197
|
+
it 'parses string to hash' do
|
198
|
+
out, status = run_cli(args: ['-c', conf, '-a', '--table-hash-options', %('{ id: "bigint", unsigned: true }')])
|
199
|
+
|
200
|
+
expect(status.success?).to be_truthy
|
201
|
+
expect(out).to match_fuzzy <<-MSG
|
202
|
+
Ridgepole::Client#initialize([#{conn_spec_str('ridgepole_test')}, {:dry_run=>false, :debug=>false, :color=>false, :table_hash_options=>{:id=>:bigint, :unsigned=>true}}])
|
203
|
+
Apply `Schemafile`
|
204
|
+
Ridgepole::Client#diff
|
205
|
+
Ridgepole::Delta#differ?
|
206
|
+
Ridgepole::Delta#migrate
|
207
|
+
No change
|
208
|
+
MSG
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
context 'given nested json' do
|
213
|
+
it 'parses string to nested hash' do
|
214
|
+
out, status = run_cli(args: ['-c', conf, '-a', '--table-hash-options', %('id: { type: "bigint", unsigned: true }')])
|
215
|
+
|
216
|
+
expect(status.success?).to be_truthy
|
217
|
+
expect(out).to match_fuzzy <<-MSG
|
218
|
+
Ridgepole::Client#initialize([#{conn_spec_str('ridgepole_test')}, {:dry_run=>false, :debug=>false, :color=>false, :table_hash_options=>{:id=>{:type=>:bigint, :unsigned=>true}}}])
|
219
|
+
Apply `Schemafile`
|
220
|
+
Ridgepole::Client#diff
|
221
|
+
Ridgepole::Delta#differ?
|
222
|
+
Ridgepole::Delta#migrate
|
223
|
+
No change
|
224
|
+
MSG
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
195
229
|
specify 'dry-run' do
|
196
230
|
out, status = run_cli(args: ['-c', conf, '-a', '--dry-run'])
|
197
231
|
|
@@ -4,7 +4,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
4
4
|
context 'when change column (add collation)' do
|
5
5
|
let(:actual_dsl) do
|
6
6
|
erbh(<<-ERB)
|
7
|
-
create_table "employee_clubs", <%= i cond(
|
7
|
+
create_table "employee_clubs", <%= i cond({ ">= 5.1, < 6.1" => { id: :bigint, unsigned: true }, ">= 6.1" => { id: { type: :bigint, unsigned: true } } }, { unsigned: true }) %>, force: :cascade do |t|
|
8
8
|
t.integer "emp_no", null: false
|
9
9
|
t.integer "club_id", null: false, unsigned: true
|
10
10
|
t.string "string", null: false, collation: "ascii_bin"
|
@@ -15,7 +15,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
15
15
|
|
16
16
|
let(:expected_dsl) do
|
17
17
|
erbh(<<-ERB)
|
18
|
-
create_table "employee_clubs", <%= i cond(
|
18
|
+
create_table "employee_clubs", <%= i cond({ ">= 5.1, < 6.1" => { id: :bigint, unsigned: true }, ">= 6.1" => { id: { type: :bigint, unsigned: true } } }, { unsigned: true }) %>, force: :cascade do |t|
|
19
19
|
t.integer "emp_no", null: false
|
20
20
|
t.integer "club_id", null: false, unsigned: true
|
21
21
|
t.string "string", null: false, collation: "ascii_bin"
|
@@ -39,7 +39,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
39
39
|
context 'when change column (delete collation)' do
|
40
40
|
let(:actual_dsl) do
|
41
41
|
erbh(<<-ERB)
|
42
|
-
create_table "employee_clubs", <%= i cond(
|
42
|
+
create_table "employee_clubs", <%= i cond({ ">= 5.1, < 6.1" => { id: :bigint, unsigned: true }, ">= 6.1" => { id: { type: :bigint, unsigned: true } } }, { unsigned: true }) %>, force: :cascade do |t|
|
43
43
|
t.integer "emp_no", null: false
|
44
44
|
t.integer "club_id", null: false, unsigned: true
|
45
45
|
t.string "string", null: false, collation: "ascii_bin"
|
@@ -50,7 +50,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
50
50
|
|
51
51
|
let(:expected_dsl) do
|
52
52
|
erbh(<<-ERB)
|
53
|
-
create_table "employee_clubs", <%= i cond(
|
53
|
+
create_table "employee_clubs", <%= i cond({ ">= 5.1, < 6.1" => { id: :bigint, unsigned: true }, ">= 6.1" => { id: { type: :bigint, unsigned: true } } }, { unsigned: true }) %>, force: :cascade do |t|
|
54
54
|
t.integer "emp_no", null: false
|
55
55
|
t.integer "club_id", null: false, unsigned: true
|
56
56
|
t.string "string", null: false, collation: "ascii_bin"
|
@@ -74,7 +74,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
74
74
|
context 'when change column (change collation)' do
|
75
75
|
let(:actual_dsl) do
|
76
76
|
erbh(<<-ERB)
|
77
|
-
create_table "employee_clubs", <%= i cond(
|
77
|
+
create_table "employee_clubs", <%= i cond({ ">= 5.1, < 6.1" => { id: :bigint, unsigned: true }, ">= 6.1" => { id: { type: :bigint, unsigned: true } } }, { unsigned: true }) %>, force: :cascade do |t|
|
78
78
|
t.integer "emp_no", null: false
|
79
79
|
t.integer "club_id", null: false, unsigned: true
|
80
80
|
t.string "string", null: false, collation: "ascii_bin"
|
@@ -85,7 +85,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
85
85
|
|
86
86
|
let(:expected_dsl) do
|
87
87
|
erbh(<<-ERB)
|
88
|
-
create_table "employee_clubs", <%= i cond(
|
88
|
+
create_table "employee_clubs", <%= i cond({ ">= 5.1, < 6.1" => { id: :bigint, unsigned: true }, ">= 6.1" => { id: { type: :bigint, unsigned: true } } }, { unsigned: true }) %>, force: :cascade do |t|
|
89
89
|
t.integer "emp_no", null: false
|
90
90
|
t.integer "club_id", null: false, unsigned: true
|
91
91
|
t.string "string", null: false, collation: "utf8mb4_bin"
|
@@ -109,7 +109,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
109
109
|
context 'when change column (no change collation)' do
|
110
110
|
let(:actual_dsl) do
|
111
111
|
erbh(<<-ERB)
|
112
|
-
create_table "employee_clubs", <%= i cond(
|
112
|
+
create_table "employee_clubs", <%= i cond({ ">= 5.1, < 6.1" => { id: :bigint, unsigned: true }, ">= 6.1" => { id: { type: :bigint, unsigned: true } } }, { unsigned: true }) %>, force: :cascade do |t|
|
113
113
|
t.integer "emp_no", null: false
|
114
114
|
t.integer "club_id", null: false, unsigned: true
|
115
115
|
t.string "string", null: false, collation: "ascii_bin"
|
@@ -141,7 +141,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
141
141
|
# v6.0.3 is the oldest version that doesn't produce any kwargs warnings with Ruby 2.7
|
142
142
|
if condition('< 6.0.3')
|
143
143
|
# https://github.com/jeremyevans/ruby-warning/blob/1.1.0/lib/warning.rb#L18
|
144
|
-
out = out.lines.grep_v(/: warning: (?:Using the last argument (?:for `.+' )?as keyword parameters is deprecated; maybe \*\* should be added to the call|Passing the keyword argument (?:for `.+' )?as the last hash parameter is deprecated|Splitting the last argument (?:for `.+' )?into positional and keyword parameters is deprecated|The called method (?:`.+' )?is defined here)\n\z/).join
|
144
|
+
out = out.lines.grep_v(/: warning: (?:Using the last argument (?:for `.+' )?as keyword parameters is deprecated; maybe \*\* should be added to the call|Passing the keyword argument (?:for `.+' )?as the last hash parameter is deprecated|Splitting the last argument (?:for `.+' )?into positional and keyword parameters is deprecated|The called method (?:`.+' )?is defined here)\n\z/).join
|
145
145
|
end
|
146
146
|
|
147
147
|
expect(out).to be_empty
|
@@ -7,12 +7,12 @@ describe 'Ridgepole::Client.dump' do
|
|
7
7
|
|
8
8
|
it {
|
9
9
|
expect(subject.dump(conn_spec, dump_without_table_options: true)).to match_fuzzy erbh(<<-ERB)
|
10
|
-
create_table "clubs", <%= i cond('>= 5.1', id: :integer
|
10
|
+
create_table "clubs", <%= i cond({ '>= 5.1, < 6.1' => { id: :integer, unsigned: true }, ">= 6.1" => { id: { type: :integer, unsigned: true } } }, { unsigned: true }) %>, force: :cascade do |t|
|
11
11
|
t.string "name", default: "", null: false
|
12
12
|
t.index ["name"], name: "idx_name", unique: true, <%= i cond(5.0, using: :btree) %>
|
13
13
|
end
|
14
14
|
|
15
|
-
create_table "departments", primary_key: "dept_no", id: :string, limit: 4, force: :cascade do |t|
|
15
|
+
create_table "departments", primary_key: "dept_no", <%= i cond(">= 6.1", { id: { type: :string, limit: 4 } }, { id: :string, limit: 4 }) %>, force: :cascade do |t|
|
16
16
|
t.string "dept_name", limit: 40, null: false
|
17
17
|
t.index ["dept_name"], name: "dept_name", unique: true, <%= i cond(5.0, using: :btree) %>
|
18
18
|
end
|
@@ -35,7 +35,7 @@ describe 'Ridgepole::Client.dump' do
|
|
35
35
|
t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
|
36
36
|
end
|
37
37
|
|
38
|
-
create_table "employee_clubs", <%= i cond('>= 5.1', id: :integer
|
38
|
+
create_table "employee_clubs", <%= i cond({ '>= 5.1, < 6.1' => { id: :integer, unsigned: true }, ">= 6.1" => { id: { type: :integer, unsigned: true }} }, { unsigned: true }) %>, force: :cascade do |t|
|
39
39
|
t.integer "emp_no", null: false, unsigned: true
|
40
40
|
t.integer "club_id", null: false, unsigned: true
|
41
41
|
t.index ["emp_no", "club_id"], name: "idx_emp_no_club_id", <%= i cond(5.0, using: :btree) %>
|
@@ -7,12 +7,12 @@ describe 'Ridgepole::Client#dump' do
|
|
7
7
|
|
8
8
|
it {
|
9
9
|
expect(subject.dump).to match_fuzzy erbh(<<-ERB)
|
10
|
-
create_table "clubs", <%= i cond('>= 5.1',id: :integer
|
10
|
+
create_table "clubs", <%= i cond({ '>= 5.1, < 6.1' => { id: :integer, unsigned: true }, ">= 6.1" => { id: { type: :integer, unsigned: true } } }, { unsigned: true }) %>, force: :cascade do |t|
|
11
11
|
t.string "name", default: "", null: false
|
12
12
|
t.index ["name"], name: "idx_name", unique: true, <%= i cond(5.0, using: :btree) %>
|
13
13
|
end
|
14
14
|
|
15
|
-
create_table "departments", primary_key: "dept_no", id: :string, limit: 4, force: :cascade do |t|
|
15
|
+
create_table "departments", primary_key: "dept_no", <%= i cond(">= 6.1", { id: { type: :string, limit: 4 } }, { id: :string, limit: 4 }) %>, force: :cascade do |t|
|
16
16
|
t.string "dept_name", limit: 40, null: false
|
17
17
|
t.index ["dept_name"], name: "dept_name", unique: true, <%= i cond(5.0, using: :btree) %>
|
18
18
|
end
|
@@ -35,7 +35,7 @@ describe 'Ridgepole::Client#dump' do
|
|
35
35
|
t.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %>
|
36
36
|
end
|
37
37
|
|
38
|
-
create_table "employee_clubs", <%= i cond('>= 5.1',id: :integer
|
38
|
+
create_table "employee_clubs", <%= i cond({ '>= 5.1, < 6.1' => { id: :integer, unsigned: true }, ">= 6.1" => { id: { type: :integer, unsigned: true } } }, { unsigned: true }) %>, force: :cascade do |t|
|
39
39
|
t.integer "emp_no", null: false, unsigned: true
|
40
40
|
t.integer "club_id", null: false, unsigned: true
|
41
41
|
t.index ["emp_no", "club_id"], name: "idx_emp_no_club_id", <%= i cond(5.0, using: :btree) %>
|