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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +65 -0
  3. data/.rubocop.yml +11 -36
  4. data/Appraisals +4 -5
  5. data/README.md +27 -17
  6. data/bin/ridgepole +13 -1
  7. data/gemfiles/{activerecord_5.0.gemfile → activerecord_6.1.gemfile} +1 -2
  8. data/lib/ridgepole/client.rb +8 -3
  9. data/lib/ridgepole/default_limit.rb +1 -1
  10. data/lib/ridgepole/delta.rb +16 -1
  11. data/lib/ridgepole/diff.rb +55 -20
  12. data/lib/ridgepole/dsl_parser.rb +3 -4
  13. data/lib/ridgepole/dsl_parser/context.rb +1 -1
  14. data/lib/ridgepole/dsl_parser/table_definition.rb +51 -41
  15. data/lib/ridgepole/execute_expander.rb +10 -1
  16. data/lib/ridgepole/ext/abstract_adapter/disable_table_options.rb +9 -1
  17. data/lib/ridgepole/external_sql_executer.rb +12 -1
  18. data/lib/ridgepole/version.rb +1 -1
  19. data/ridgepole.gemspec +5 -3
  20. data/spec/erb_helper.rb +9 -5
  21. data/spec/mysql/_migrate/migrate_change_table_option_spec.rb +2 -2
  22. data/spec/mysql/cli/ridgepole_spec.rb +35 -1
  23. data/spec/mysql/collation/collation_spec.rb +8 -8
  24. data/spec/mysql/dump/dump_class_method_spec.rb +3 -3
  25. data/spec/mysql/dump/dump_spec.rb +3 -3
  26. data/spec/mysql/dump/dump_unknown_column_type_spec.rb +1 -1
  27. data/spec/mysql/dump/dump_without_table_options_spec.rb +2 -2
  28. data/spec/mysql/fk/migrate_create_fk_spec.rb +79 -10
  29. data/spec/mysql/migrate/migrate_add_column_with_alter_extra_spec.rb +88 -0
  30. data/spec/mysql/migrate/migrate_change_column3_spec.rb +109 -18
  31. data/spec/mysql/migrate/migrate_change_column8_spec.rb +38 -5
  32. data/spec/mysql/migrate/migrate_change_index_spec.rb +7 -1
  33. data/spec/mysql/migrate/migrate_check_relation_column_type_spec.rb +4 -4
  34. data/spec/mysql/migrate/migrate_primary_key_spec.rb +30 -5
  35. data/spec/mysql/migrate/migrate_same_spec.rb +3 -3
  36. data/spec/mysql/text_blob_types/text_blob_types_spec.rb +5 -2
  37. data/spec/postgresql/dump/dump_spec.rb +1 -1
  38. data/spec/postgresql/migrate/migrate_add_column_spec.rb +11 -4
  39. data/spec/postgresql/migrate/migrate_change_column_spec.rb +4 -0
  40. data/spec/postgresql/migrate/migrate_drop_column_spec.rb +11 -4
  41. data/spec/postgresql/migrate/migrate_same_spec.rb +1 -1
  42. data/spec/spec_condition.rb +4 -0
  43. data/spec/spec_helper.rb +2 -1
  44. metadata +43 -20
  45. data/.travis.yml +0 -45
  46. data/lib/ridgepole/ext/abstract_mysql_adapter/use_alter_index.rb +0 -31
  47. data/spec/mysql/migrate_/migrate_create_index_with_alter_spec.rb +0 -141
  48. data/spec/mysql/migrate_/migrate_drop_index_with_alter_spec.rb +0 -141
@@ -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"
@@ -186,25 +186,19 @@ describe 'Ridgepole::Client#diff -> migrate' do
186
186
  subject { client(dump_without_table_options: false) }
187
187
 
188
188
  it {
189
- expect(Ridgepole::Logger.instance).to receive(:warn).with(<<-MSG).twice
190
- [WARNING] Table `child` has a foreign key on `parent_id` column, but doesn't have any indexes on the column.
191
- Although an index will be added automatically by InnoDB, please add an index explicitly for your future operations.
192
- MSG
193
- subject.diff(dsl).migrate
194
-
195
189
  expect do
196
190
  subject.diff(dsl).migrate
197
- end.to raise_error(/Mysql2::Error: Cannot drop index/)
191
+ end.to raise_error('The column `parent_id` of the table `child` has a foreign key but no index. Although InnoDB creates an index automatically, please add one explicitly in order for ridgepole to manage it.')
198
192
  }
199
193
  end
200
194
 
201
195
  context 'when create fk with first key of multiple column indexes for its column' do
202
196
  let(:dsl) do
203
197
  erbh(<<-ERB)
204
- 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|
205
199
  end
206
200
 
207
- 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|
208
202
  t.integer "parent_id"
209
203
  t.string "name"
210
204
  t.index ["parent_id", "name"], name: "par_id", <%= i cond(5.0, using: :btree) %>
@@ -219,7 +213,82 @@ describe 'Ridgepole::Client#diff -> migrate' do
219
213
  expect(Ridgepole::Logger.instance).to_not receive(:warn)
220
214
  subject.diff(dsl).migrate
221
215
 
222
- expect { subject.diff(dsl).migrate }.to_not raise_error
216
+ expect(subject.diff(dsl).differ?).to be_falsey
223
217
  }
224
218
  end
219
+
220
+ context 'when create fk on the primary key' do
221
+ let(:dsl) do
222
+ erbh(<<-ERB)
223
+ create_table "users", force: :cascade, <%= i cond('>= 6.1', { charset: 'utf8' }, { options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" }) %> do |t|
224
+ end
225
+
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
+ end
228
+ add_foreign_key "icons", "users", name: "fk_icons_users"
229
+ ERB
230
+ end
231
+
232
+ subject { client(dump_without_table_options: false) }
233
+
234
+ it {
235
+ expect(Ridgepole::Logger.instance).to_not receive(:warn)
236
+ subject.diff(dsl).migrate
237
+
238
+ expect(subject.diff(dsl).differ?).to be_falsey
239
+ }
240
+ end
241
+ end
242
+
243
+ context 'when create fk on the first primary key' do
244
+ let(:dsl) do
245
+ erbh(<<-ERB)
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
+ end
248
+
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
+ end
251
+
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
+ t.integer "user_id", null: false
254
+ t.integer "employee_id", null: false
255
+ end
256
+ add_foreign_key "icons", "users", name: "fk_icons_users"
257
+ ERB
258
+ end
259
+
260
+ subject { client(dump_without_table_options: false) }
261
+
262
+ it {
263
+ expect(Ridgepole::Logger.instance).to_not receive(:warn)
264
+ subject.diff(dsl).migrate
265
+
266
+ expect(subject.diff(dsl).differ?).to be_falsey
267
+ }
268
+ end
269
+
270
+ context 'when create fk on the second primary key' do
271
+ let(:dsl) do
272
+ erbh(<<-ERB)
273
+ create_table "users", <%= i cond('>= 5.1',id: :integer) %>, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
274
+ end
275
+
276
+ create_table "employee", <%= i cond('>= 5.1',id: :integer) %>, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
277
+ end
278
+
279
+ create_table "icons", primary_key: ["user_id", "employee_id"], force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
280
+ t.integer "user_id", null: false
281
+ t.integer "employee_id", null: false
282
+ end
283
+ add_foreign_key "icons", "employees", name: "fk_icons_employees"
284
+ ERB
285
+ end
286
+
287
+ subject { client(dump_without_table_options: false) }
288
+
289
+ it {
290
+ expect do
291
+ subject.diff(dsl).migrate
292
+ end.to raise_error('The column `employee_id` of the table `icons` has a foreign key but no index. Although InnoDB creates an index automatically, please add one explicitly in order for ridgepole to manage it.')
293
+ }
225
294
  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
@@ -99,9 +99,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
99
99
  t.string "last_name", limit: 16, null: false
100
100
  t.string "gender", limit: 1, null: false
101
101
  t.date "hire_date", null: false
102
- t.<%= cond('>= 5.1','bigint', 'integer') %> "products_id"
103
102
  t.<%= cond('>= 5.1','bigint', 'integer') %> "user_id"
104
- t.index "products_id"
105
103
  t.index "user_id"
106
104
  end
107
105
  ERB
@@ -115,7 +113,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
115
113
  t.string "last_name", limit: 16, null: false
116
114
  t.string "gender", limit: 1, null: false
117
115
  t.date "hire_date", null: false
118
- t.references :products, :user
116
+ t.references :user
119
117
  end
120
118
  RUBY
121
119
  end
@@ -138,11 +136,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
138
136
  t.string "last_name", limit: 16, null: false
139
137
  t.string "gender", limit: 1, null: false
140
138
  t.date "hire_date", null: false
141
- t.<%= cond('>= 5.1','bigint', 'integer') %> "products_id"
142
- t.string "products_type"
143
139
  t.<%= cond('>= 5.1','bigint', 'integer') %> "user_id"
144
140
  t.string "user_type"
145
- t.index ["products_type", "products_id"]
146
141
  t.index ["user_type", "user_id"]
147
142
  end
148
143
  ERB
@@ -156,7 +151,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
156
151
  t.string "last_name", limit: 16, null: false
157
152
  t.string "gender", limit: 1, null: false
158
153
  t.date "hire_date", null: false
159
- t.references :products, :user, polymorphic: true
154
+ t.references :user, polymorphic: true
160
155
  end
161
156
  RUBY
162
157
  end
@@ -174,11 +169,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
174
169
  let(:actual_dsl) do
175
170
  erbh(<<-ERB)
176
171
  create_table "employees", primary_key: "emp_no", force: :cascade do |t|
177
- t.<%= cond('>= 5.1','bigint', 'integer') %> "products_id", unsigned: true
178
- t.string "products_type"
179
172
  t.<%= cond('>= 5.1','bigint', 'integer') %> "user_id", unsigned: true
180
173
  t.string "user_type"
181
- t.index ["products_type", "products_id"]
182
174
  t.index ["user_type", "user_id"]
183
175
  end
184
176
  ERB
@@ -187,7 +179,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
187
179
  let(:expected_dsl) do
188
180
  <<-RUBY
189
181
  create_table "employees", primary_key: "emp_no", force: :cascade do |t|
190
- t.references :products, :user, unsigned: true, polymorphic: true
182
+ t.references :user, unsigned: true, polymorphic: true
191
183
  end
192
184
  RUBY
193
185
  end
@@ -222,7 +214,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
222
214
  t.string "last_name", limit: 16, null: false
223
215
  t.string "gender", limit: 1, null: false
224
216
  t.date "hire_date", null: false
225
- t.references :products, :user
217
+ t.references :user
226
218
  end
227
219
  RUBY
228
220
  end
@@ -235,9 +227,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
235
227
  t.string "last_name", limit: 16, null: false
236
228
  t.string "gender", limit: 1, null: false
237
229
  t.date "hire_date", null: false
238
- t.<%= cond('>= 5.1','bigint', 'integer') %> "products_id"
239
230
  t.<%= cond('>= 5.1','bigint', 'integer') %> "user_id"
240
- t.index ["products_id"], name: "index_employees_on_products_id", <%= i cond(5.0, using: :btree) %>
241
231
  t.index ["user_id"], name: "index_employees_on_user_id", <%= i cond(5.0, using: :btree) %>
242
232
  end
243
233
  ERB
@@ -276,7 +266,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
276
266
  t.string "last_name", limit: 16, null: false
277
267
  t.string "gender", limit: 1, null: false
278
268
  t.date "hire_date", null: false
279
- t.references :products, :user, polymorphic: true
269
+ t.references :user, polymorphic: true
280
270
  end
281
271
  RUBY
282
272
  end
@@ -289,11 +279,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
289
279
  t.string "last_name", limit: 16, null: false
290
280
  t.string "gender", limit: 1, null: false
291
281
  t.date "hire_date", null: false
292
- t.<%= cond('>= 5.1','bigint', 'integer') %> "products_id"
293
- t.string "products_type"
294
282
  t.<%= cond('>= 5.1','bigint', 'integer') %> "user_id"
295
283
  t.string "user_type"
296
- t.index ["products_type", "products_id"], name: "index_employees_on_products_type_and_products_id", <%= i cond(5.0, using: :btree) %>
297
284
  t.index ["user_type", "user_id"], name: "index_employees_on_user_type_and_user_id", <%= i cond(5.0, using: :btree) %>
298
285
  end
299
286
  ERB
@@ -310,4 +297,108 @@ describe 'Ridgepole::Client#diff -> migrate' do
310
297
  expect(subject.dump).to match_ruby expected_dsl
311
298
  }
312
299
  end
300
+
301
+ context 'when use references with fk (no change)' do
302
+ let(:actual_dsl) do
303
+ erbh(<<-ERB)
304
+ create_table "users", force: :cascade do |t|
305
+ end
306
+
307
+ create_table "employees", primary_key: "emp_no", force: :cascade do |t|
308
+ t.date "birth_date", null: false
309
+ t.string "first_name", limit: 14, null: false
310
+ t.string "last_name", limit: 16, null: false
311
+ t.string "gender", limit: 1, null: false
312
+ t.date "hire_date", null: false
313
+ t.<%= cond('>= 5.1','bigint', 'integer') %> "user_id"
314
+ t.index "user_id"
315
+ end
316
+
317
+ add_foreign_key("employees", "users")
318
+ ERB
319
+ end
320
+
321
+ let(:expected_dsl) do
322
+ erbh(<<-ERB)
323
+ create_table "users", force: :cascade do |t|
324
+ end
325
+
326
+ create_table "employees", primary_key: "emp_no", force: :cascade do |t|
327
+ t.date "birth_date", null: false
328
+ t.string "first_name", limit: 14, null: false
329
+ t.string "last_name", limit: 16, null: false
330
+ t.string "gender", limit: 1, null: false
331
+ t.date "hire_date", null: false
332
+ t.references :user, foreign_key: true
333
+ end
334
+ ERB
335
+ end
336
+
337
+ before { subject.diff(actual_dsl).migrate }
338
+ subject { client }
339
+
340
+ it {
341
+ delta = subject.diff(expected_dsl)
342
+ expect(delta.differ?).to be_falsey
343
+ }
344
+ end
345
+
346
+ context 'when use references with fk (change)' do
347
+ let(:actual_dsl) do
348
+ erbh(<<-ERB)
349
+ create_table "employees", primary_key: "emp_no", force: :cascade do |t|
350
+ t.date "birth_date", null: false
351
+ t.string "first_name", limit: 14, null: false
352
+ t.string "last_name", limit: 16, null: false
353
+ t.string "gender", limit: 1, null: false
354
+ t.date "hire_date", null: false
355
+ end
356
+ create_table "users", force: :cascade do |t|
357
+ end
358
+ ERB
359
+ end
360
+
361
+ let(:dsl) do
362
+ erbh(<<-ERB)
363
+ create_table "employees", primary_key: "emp_no", force: :cascade do |t|
364
+ t.date "birth_date", null: false
365
+ t.string "first_name", limit: 14, null: false
366
+ t.string "last_name", limit: 16, null: false
367
+ t.string "gender", limit: 1, null: false
368
+ t.date "hire_date", null: false
369
+ t.references :user, foreign_key: true
370
+ end
371
+ create_table "users", force: :cascade do |t|
372
+ end
373
+ ERB
374
+ end
375
+
376
+ let(:expected_dsl) do
377
+ erbh(<<-ERB)
378
+ create_table "employees", primary_key: "emp_no", force: :cascade do |t|
379
+ t.date "birth_date", null: false
380
+ t.string "first_name", limit: 14, null: false
381
+ t.string "last_name", limit: 16, null: false
382
+ t.string "gender", limit: 1, null: false
383
+ t.date "hire_date", null: false
384
+ t.<%= cond('>= 5.1','bigint', 'integer') %> "user_id"
385
+ t.index ["user_id"], name: "index_employees_on_user_id", <%= i cond(5.0, using: :btree) %>
386
+ end
387
+ create_table "users", force: :cascade do |t|
388
+ end
389
+ add_foreign_key("employees", "users")
390
+ ERB
391
+ end
392
+
393
+ before { subject.diff(actual_dsl).migrate }
394
+ subject { client }
395
+
396
+ it {
397
+ delta = subject.diff(dsl)
398
+ expect(delta.differ?).to be_truthy
399
+ expect(subject.dump).to match_ruby actual_dsl
400
+ delta.migrate
401
+ expect(subject.dump).to match_ruby expected_dsl
402
+ }
403
+ end
313
404
  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