ridgepole 0.8.13 → 0.9.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +3 -1
  3. data/Appraisals +4 -5
  4. data/README.md +17 -19
  5. data/bin/ridgepole +13 -1
  6. data/gemfiles/{activerecord_5.0.gemfile → activerecord_6.1.gemfile} +1 -2
  7. data/lib/ridgepole/client.rb +8 -3
  8. data/lib/ridgepole/delta.rb +16 -1
  9. data/lib/ridgepole/diff.rb +43 -20
  10. data/lib/ridgepole/execute_expander.rb +10 -1
  11. data/lib/ridgepole/ext/abstract_adapter/disable_table_options.rb +9 -1
  12. data/lib/ridgepole/external_sql_executer.rb +12 -1
  13. data/lib/ridgepole/version.rb +1 -1
  14. data/ridgepole.gemspec +1 -1
  15. data/spec/erb_helper.rb +5 -1
  16. data/spec/mysql/_migrate/migrate_change_table_option_spec.rb +2 -2
  17. data/spec/mysql/cli/ridgepole_spec.rb +35 -1
  18. data/spec/mysql/collation/collation_spec.rb +7 -7
  19. data/spec/mysql/dump/dump_class_method_spec.rb +3 -3
  20. data/spec/mysql/dump/dump_spec.rb +3 -3
  21. data/spec/mysql/dump/dump_unknown_column_type_spec.rb +1 -1
  22. data/spec/mysql/dump/dump_without_table_options_spec.rb +2 -2
  23. data/spec/mysql/fk/migrate_create_fk_spec.rb +7 -7
  24. data/spec/mysql/migrate/migrate_add_column_with_alter_extra_spec.rb +88 -0
  25. data/spec/mysql/migrate/migrate_change_column8_spec.rb +38 -5
  26. data/spec/mysql/migrate/migrate_change_index_spec.rb +7 -1
  27. data/spec/mysql/migrate/migrate_check_relation_column_type_spec.rb +4 -4
  28. data/spec/mysql/migrate/migrate_primary_key_spec.rb +30 -5
  29. data/spec/mysql/migrate/migrate_same_spec.rb +3 -3
  30. data/spec/mysql/text_blob_types/text_blob_types_spec.rb +1 -1
  31. data/spec/postgresql/dump/dump_spec.rb +1 -1
  32. data/spec/postgresql/migrate/migrate_same_spec.rb +1 -1
  33. metadata +10 -15
  34. data/lib/ridgepole/ext/abstract_mysql_adapter/use_alter_index.rb +0 -31
  35. data/spec/mysql/migrate_/migrate_create_index_with_alter_spec.rb +0 -141
  36. data/spec/mysql/migrate_/migrate_drop_index_with_alter_spec.rb +0 -141
@@ -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('>= 5.1', id: :bigint) %>, unsigned: true, force: :cascade do |t|
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('>= 5.1', id: :bigint) %>, unsigned: true, force: :cascade do |t|
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('>= 5.1', id: :bigint) %>, unsigned: true, force: :cascade do |t|
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('>= 5.1', id: :bigint) %>, unsigned: true, force: :cascade do |t|
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('>= 5.1', id: :bigint) %>, unsigned: true, force: :cascade do |t|
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('>= 5.1', id: :bigint) %>, unsigned: true, force: :cascade do |t|
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('>= 5.1', id: :bigint) %>, unsigned: true, force: :cascade do |t|
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"
@@ -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) %>, unsigned: true, force: :cascade do |t|
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) %>, unsigned: true, force: :cascade do |t|
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) %>, unsigned: true, force: :cascade do |t|
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) %>, unsigned: true, force: :cascade do |t|
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,7 +7,7 @@ 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) %>, unsigned: true, force: :cascade do |t|
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
@@ -3,7 +3,7 @@
3
3
  describe 'Ridgepole::Client#dump' do
4
4
  let(:actual_dsl) do
5
5
  erbh(<<-'ERB')
6
- create_table "books", unsigned: true, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='\"london\" bridge \"is\" falling \"down\"'" do |t|
6
+ create_table "books", unsigned: true, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='\"london\" bridge \"is\" falling \"down\"'" do |t|
7
7
  t.string "title", null: false
8
8
  t.integer "author_id", null: false
9
9
  t.datetime "created_at"
@@ -15,7 +15,7 @@ describe 'Ridgepole::Client#dump' do
15
15
  context 'when without table options' do
16
16
  let(:expected_dsl) do
17
17
  erbh(<<-ERB)
18
- create_table "books", <%= i cond('>= 5.1',id: :bigint) %>, unsigned: true, force: :cascade, comment: "\\"london\\" bridge \\"is\\" falling \\"down\\"" do |t|
18
+ create_table "books", <%= i cond({ '>= 6.1' => { id: { type: :bigint, unsigned: true } }, '> 5.1, < 6.1' => { id: :bigint, unsigned: true } }, { unsigned: true }) %>, force: :cascade, comment: "\\"london\\" bridge \\"is\\" falling \\"down\\"" do |t|
19
19
  t.string "title", null: false
20
20
  t.integer "author_id", null: false
21
21
  t.datetime "created_at"
@@ -195,10 +195,10 @@ describe 'Ridgepole::Client#diff -> migrate' do
195
195
  context 'when create fk with first key of multiple column indexes for its column' do
196
196
  let(:dsl) do
197
197
  erbh(<<-ERB)
198
- create_table "parent", <%= i cond('>= 5.1',id: :integer) %>, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
198
+ create_table "parent", <%= i cond('>= 5.1',id: :integer) %>, force: :cascade, <%= i cond('>= 6.1', { charset: 'utf8' }, { options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" }) %> do |t|
199
199
  end
200
200
 
201
- create_table "child", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
201
+ create_table "child", force: :cascade, <%= i cond('>= 6.1', { charset: 'utf8' }, { options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" }) %> do |t|
202
202
  t.integer "parent_id"
203
203
  t.string "name"
204
204
  t.index ["parent_id", "name"], name: "par_id", <%= i cond(5.0, using: :btree) %>
@@ -220,10 +220,10 @@ describe 'Ridgepole::Client#diff -> migrate' do
220
220
  context 'when create fk on the primary key' do
221
221
  let(:dsl) do
222
222
  erbh(<<-ERB)
223
- create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
223
+ create_table "users", force: :cascade, <%= i cond('>= 6.1', { charset: 'utf8' }, { options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" }) %> do |t|
224
224
  end
225
225
 
226
- create_table "icons", primary_key: "user_id", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
226
+ create_table "icons", primary_key: "user_id", force: :cascade, <%= i cond('>= 6.1', { charset: 'utf8' }, { options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" }) %> do |t|
227
227
  end
228
228
  add_foreign_key "icons", "users", name: "fk_icons_users"
229
229
  ERB
@@ -243,13 +243,13 @@ end
243
243
  context 'when create fk on the first primary key' do
244
244
  let(:dsl) do
245
245
  erbh(<<-ERB)
246
- create_table "users", <%= i cond('>= 5.1',id: :integer) %>, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
246
+ create_table "users", <%= i cond('>= 5.1',id: :integer) %>, force: :cascade, <%= i cond('>= 6.1', { charset: 'utf8' }, { options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" }) %> do |t|
247
247
  end
248
248
 
249
- create_table "employee", <%= i cond('>= 5.1',id: :integer) %>, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
249
+ create_table "employee", <%= i cond('>= 5.1',id: :integer) %>, force: :cascade, <%= i cond('>= 6.1', { charset: 'utf8' }, { options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" }) %> do |t|
250
250
  end
251
251
 
252
- create_table "icons", primary_key: ["user_id", "employee_id"], force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
252
+ create_table "icons", primary_key: ["user_id", "employee_id"], force: :cascade, <%= i cond('>= 6.1', { charset: 'utf8' }, { options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" }) %> do |t|
253
253
  t.integer "user_id", null: false
254
254
  t.integer "employee_id", null: false
255
255
  end
@@ -140,4 +140,92 @@ describe 'Ridgepole::Client#diff -> migrate' do
140
140
  expect(subject.dump).to match_ruby expected_dsl
141
141
  }
142
142
  end
143
+
144
+ context 'when add index' do
145
+ let(:actual_dsl) do
146
+ erbh(<<-ERB)
147
+ create_table "employees", primary_key: "emp_no", force: :cascade do |t|
148
+ t.date "birth_date", null: false
149
+ t.string "first_name", limit: 14, null: false
150
+ t.string "last_name", limit: 16, null: false
151
+ t.string "gender", limit: 1, null: false
152
+ t.date "hire_date", null: false
153
+ end
154
+ ERB
155
+ end
156
+
157
+ let(:expected_dsl) do
158
+ erbh(<<-ERB)
159
+ create_table "employees", primary_key: "emp_no", force: :cascade do |t|
160
+ t.date "birth_date", null: false
161
+ t.string "first_name", limit: 14, null: false
162
+ t.string "last_name", limit: 16, null: false
163
+ t.string "gender", limit: 1, null: false
164
+ t.date "hire_date", null: false
165
+ t.index ["first_name"], name: "idx_first_name", <%= i cond(5.0, using: :btree) %>
166
+ end
167
+ ERB
168
+ end
169
+
170
+ let(:alter_extra) { 'LOCK=DEFAULT, ALGORITHM=DEFAULT' }
171
+
172
+ before { subject.diff(actual_dsl).migrate }
173
+ subject { client }
174
+
175
+ it {
176
+ delta = subject.diff(expected_dsl)
177
+ expect(delta.differ?).to be_truthy
178
+ expect(subject.dump).to match_ruby actual_dsl
179
+ migrated, sql = delta.migrate(alter_extra: alter_extra, noop: true)
180
+ expect(migrated).to be_truthy
181
+ expect(sql).to match_fuzzy erbh(<<-SQL)
182
+ CREATE INDEX `idx_first_name` <%= cond('5.0', 'USING btree') %> ON `employees` (`first_name`) LOCK=DEFAULT ALGORITHM=DEFAULT
183
+ SQL
184
+ delta.migrate(alter_extra: alter_extra)
185
+ expect(subject.dump).to match_ruby expected_dsl
186
+ }
187
+ end
188
+
189
+ context 'when drop index' do
190
+ let(:actual_dsl) do
191
+ erbh(<<-ERB)
192
+ create_table "employees", primary_key: "emp_no", force: :cascade do |t|
193
+ t.date "birth_date", null: false
194
+ t.string "first_name", limit: 14, null: false
195
+ t.string "last_name", limit: 16, null: false
196
+ t.string "gender", limit: 1, null: false
197
+ t.date "hire_date", null: false
198
+ t.index ["first_name"], name: "idx_first_name", <%= i cond(5.0, using: :btree) %>
199
+ end
200
+ ERB
201
+ end
202
+
203
+ let(:expected_dsl) do
204
+ erbh(<<-ERB)
205
+ create_table "employees", primary_key: "emp_no", force: :cascade do |t|
206
+ t.date "birth_date", null: false
207
+ t.string "first_name", limit: 14, null: false
208
+ t.string "last_name", limit: 16, null: false
209
+ t.string "gender", limit: 1, null: false
210
+ t.date "hire_date", null: false
211
+ end
212
+ ERB
213
+ end
214
+
215
+ let(:alter_extra) { 'LOCK=DEFAULT, ALGORITHM=DEFAULT' }
216
+
217
+ before { subject.diff(actual_dsl).migrate }
218
+ subject { client }
219
+
220
+ it {
221
+ delta = subject.diff(expected_dsl)
222
+ expect(delta.differ?).to be_truthy
223
+ expect(subject.dump).to match_ruby actual_dsl
224
+ migrated, sql = delta.migrate(alter_extra: alter_extra, noop: true)
225
+ expect(migrated).to be_truthy
226
+ expect(sql).to eq 'DROP INDEX `idx_first_name` ON `employees` LOCK=DEFAULT ALGORITHM=DEFAULT'
227
+ delta.migrate(alter_extra: alter_extra)
228
+ expect(subject.dump).to match_ruby expected_dsl
229
+ }
230
+ end
143
231
  end
@@ -2,14 +2,16 @@
2
2
 
3
3
  describe 'Ridgepole::Client#diff -> migrate' do
4
4
  before { subject.diff(actual_dsl).migrate }
5
- subject { client(table_options: table_options, dump_without_table_options: dump_without_table_options) }
5
+ subject { client(table_options: table_options, table_hash_options: table_hash_options, dump_without_table_options: dump_without_table_options) }
6
6
 
7
7
  let(:warning_regexp) { /Table option changes are ignored/ }
8
8
  let(:dump_without_table_options) { false }
9
+ let(:table_options) { nil }
10
+ let(:table_hash_options) { {} }
9
11
 
10
12
  let(:actual_dsl) do
11
13
  erbh(<<-ERB)
12
- create_table "employees", primary_key: "emp_no", force: :cascade, options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8' do |t|
14
+ create_table "employees", primary_key: "emp_no", force: :cascade, <%= i cond('>= 6.1', { charset: 'utf8' }, { options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8' }) %> do |t|
13
15
  end
14
16
  ERB
15
17
  end
@@ -21,7 +23,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
21
23
  ERB
22
24
  end
23
25
 
24
- context 'when change options (no change)' do
26
+ context 'when change options (no change)', condition: '< 6.1' do
25
27
  let(:table_options) { 'ENGINE=InnoDB DEFAULT CHARSET=utf8' }
26
28
 
27
29
  it {
@@ -31,7 +33,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
31
33
  }
32
34
  end
33
35
 
34
- context 'when change options (change)' do
36
+ context 'when change options (change)', condition: '< 6.1' do
35
37
  let(:table_options) { 'ENGINE=InnoDB DEFAULT CHARSET=utf8mb4' }
36
38
 
37
39
  it {
@@ -41,7 +43,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
41
43
  }
42
44
  end
43
45
 
44
- context 'when dump_without_table_options => true' do
46
+ context 'when dump_without_table_options => true', condition: '< 6.1' do
45
47
  let(:table_options) { 'ENGINE=InnoDB DEFAULT CHARSET=utf8mb4' }
46
48
  let(:dump_without_table_options) { true }
47
49
 
@@ -51,4 +53,35 @@ describe 'Ridgepole::Client#diff -> migrate' do
51
53
  expect(delta.differ?).to be_falsey
52
54
  }
53
55
  end
56
+
57
+ context 'when change options (no change)', condition: '>= 6.1' do
58
+ let(:table_hash_options) { { charset: 'utf8' } }
59
+
60
+ it {
61
+ expect(Ridgepole::Logger.instance).to_not receive(:warn).with(warning_regexp)
62
+ delta = subject.diff(expected_dsl)
63
+ expect(delta.differ?).to be_falsey
64
+ }
65
+ end
66
+
67
+ context 'when change options (change)', condition: '>= 6.1' do
68
+ let(:table_hash_options) { { charset: 'utf8mb4' } }
69
+
70
+ it {
71
+ expect(Ridgepole::Logger.instance).to receive(:warn).with(warning_regexp)
72
+ delta = subject.diff(expected_dsl)
73
+ expect(delta.differ?).to be_falsey
74
+ }
75
+ end
76
+
77
+ context 'when dump_without_table_options => true', condition: '>= 6.1' do
78
+ let(:table_hash_options) { { charset: 'utf8mb4' } }
79
+ let(:dump_without_table_options) { true }
80
+
81
+ it {
82
+ expect(Ridgepole::Logger.instance).to_not receive(:warn)
83
+ delta = subject.diff(expected_dsl)
84
+ expect(delta.differ?).to be_falsey
85
+ }
86
+ end
54
87
  end
@@ -219,11 +219,17 @@ describe 'Ridgepole::Client#diff -> migrate' do
219
219
  t.index(["from_date"], **{:name=>"emp_no", :using=>:btree, :unique=>false})
220
220
  end
221
221
  RUBY
222
+ }
223
+
224
+ # duplicated index checker is deleted in 6.1
225
+ # https://github.com/rails/rails/commit/edb23791d2ee9df89c5a4f24d72940ff8eaec8fc#diff-5a1c923abf3a794dbc133959167f794b2479ea8bcd0b1deda7766c22f05e8dfeL1198
226
+ it 'detects duplicated index', condition: '< 6.1' do
227
+ delta = client(bulk_change: true).diff(expected_dsl)
222
228
 
223
229
  # XXX: Can not add an index of the same name
224
230
  expect do
225
231
  delta.migrate
226
232
  end.to raise_error(/Index name 'emp_no' on table 'dept_emp' already exists/)
227
- }
233
+ end
228
234
  end
229
235
  end
@@ -68,7 +68,7 @@ describe 'Ridgepole::Client#diff -> migrate', condition: '>= 5.1.0' do
68
68
  t.date "to_date", null: false
69
69
  end
70
70
 
71
- create_table "employees", id: :bigint, unsigned: true, force: :cascade do |t|
71
+ create_table "employees", <%= i cond(">= 6.1", { id: { type: :bigint, unsigned: true } }, { id: :bigint, unsigned: true }) %>, force: :cascade do |t|
72
72
  t.integer "emp_no", null: false
73
73
  t.date "birth_date", null: false
74
74
  t.string "first_name", limit: 14, null: false
@@ -88,7 +88,7 @@ describe 'Ridgepole::Client#diff -> migrate', condition: '>= 5.1.0' do
88
88
  t.date "to_date", null: false
89
89
  end
90
90
 
91
- create_table "employees", id: :bigint, unsigned: true, force: :cascade do |t|
91
+ create_table "employees", <%= i cond(">= 6.1", { id: { type: :bigint, unsigned: true } }, { id: :bigint, unsigned: true }) %>, force: :cascade do |t|
92
92
  t.integer "emp_no", null: false
93
93
  t.date "birth_date", null: false
94
94
  t.string "first_name", limit: 14, null: false
@@ -179,7 +179,7 @@ describe 'Ridgepole::Client#diff -> migrate', condition: '>= 5.1.0' do
179
179
  t.date "to_date", null: false
180
180
  end
181
181
 
182
- create_table "employees", id: :bigint, unsigned: true, force: :cascade do |t|
182
+ create_table "employees", <%= i cond(">= 6.1", { id: { type: :bigint, unsigned: true } }, { id: :bigint, unsigned: true }) %>, force: :cascade do |t|
183
183
  t.integer "emp_no", null: false
184
184
  t.date "birth_date", null: false
185
185
  t.string "first_name", limit: 14, null: false
@@ -199,7 +199,7 @@ describe 'Ridgepole::Client#diff -> migrate', condition: '>= 5.1.0' do
199
199
  t.date "to_date", null: false
200
200
  end
201
201
 
202
- create_table "employees", id: :bigint, unsigned: true, force: :cascade do |t|
202
+ create_table "employees", <%= i cond(">= 6.1", { id: { type: :bigint, unsigned: true } }, { id: :bigint, unsigned: true }) %>, force: :cascade do |t|
203
203
  t.integer "emp_no", null: false
204
204
  t.date "birth_date", null: false
205
205
  t.string "first_name", limit: 14, null: false
@@ -3,7 +3,7 @@
3
3
  describe 'Ridgepole::Client#diff -> migrate' do
4
4
  let(:actual_dsl) do
5
5
  erbh(<<-ERB)
6
- create_table "employees", id: :integer, unsigned: true, force: :cascade do |t|
6
+ create_table "employees", <%= i cond(">= 6.1", { id: { type: :integer, unsigned: true } }, { id: :integer, unsigned: true }) %>, force: :cascade do |t|
7
7
  end
8
8
  ERB
9
9
  end
@@ -23,11 +23,11 @@ describe 'Ridgepole::Client#diff -> migrate' do
23
23
  end
24
24
 
25
25
  it {
26
- expect(Ridgepole::Logger.instance).to receive(:warn).with(<<-MSG)
26
+ expect(Ridgepole::Logger.instance).to receive(:warn).with(erbh(<<-ERB))
27
27
  [WARNING] Primary key definition of `employees` differ but `allow_pk_change` option is false
28
- from: {:id=>:integer, :unsigned=>true}
28
+ from: <%= i cond(">= 6.1", "{:id=>{:type=>:integer, :unsigned=>true}}", "{:id=>:integer, :unsigned=>true}") %>
29
29
  to: {:id=>:bigint, :unsigned=>true}
30
- MSG
30
+ ERB
31
31
 
32
32
  delta = subject.diff(expected_dsl)
33
33
  expect(delta.differ?).to be_falsey
@@ -58,7 +58,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
58
58
  let(:allow_pk_change) { true }
59
59
  let(:expected_dsl) do
60
60
  erbh(<<-ERB)
61
- create_table "employees", id: :bigint, unsigned: true, force: :cascade do |t|
61
+ create_table "employees", <%= i cond(">= 6.1", { id: { type: :bigint, unsigned: true } }, { id: :bigint, unsigned: true }) %>, force: :cascade do |t|
62
62
  end
63
63
 
64
64
  create_table "salaries", force: :cascade do |t|
@@ -76,4 +76,29 @@ describe 'Ridgepole::Client#diff -> migrate' do
76
76
  expect(subject.dump).to match_ruby expected_dsl
77
77
  }
78
78
  end
79
+
80
+ context 'when deafult: nil' do
81
+ let(:allow_pk_change) { true }
82
+
83
+ let(:actual_dsl) do
84
+ erbh(<<-ERB)
85
+ create_table "foo", id: :integer, unsigned: true, default: nil, force: :cascade do |t|
86
+ end
87
+ ERB
88
+ end
89
+
90
+ let(:expected_dsl) do
91
+ erbh(<<-ERB)
92
+ create_table "foo", id: :integer, default: nil, force: :cascade do |t|
93
+ end
94
+ ERB
95
+ end
96
+
97
+ it {
98
+ delta = subject.diff(expected_dsl)
99
+ expect(delta.differ?).to be_truthy
100
+ delta.migrate
101
+ expect(subject.dump).to match_ruby expected_dsl
102
+ }
103
+ end
79
104
  end