ridgepole 0.6.6 → 0.7.0.alpha

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 (73) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -7
  3. data/Appraisals +4 -5
  4. data/README.md +3 -0
  5. data/gemfiles/activerecord_5.0.gemfile +1 -1
  6. data/gemfiles/{activerecord_4.2.gemfile → activerecord_5.1.gemfile} +1 -2
  7. data/lib/ridgepole.rb +1 -0
  8. data/lib/ridgepole/client.rb +1 -3
  9. data/lib/ridgepole/connection_adapters.rb +11 -0
  10. data/lib/ridgepole/delta.rb +5 -0
  11. data/lib/ridgepole/diff.rb +5 -10
  12. data/lib/ridgepole/dsl_parser/context.rb +1 -4
  13. data/lib/ridgepole/dumper.rb +0 -11
  14. data/lib/ridgepole/schema_statements_ext.rb +1 -1
  15. data/lib/ridgepole/version.rb +1 -1
  16. data/ridgepole.gemspec +2 -2
  17. data/ridgepole.iml +9 -0
  18. data/spec/erb_helper.rb +25 -15
  19. data/spec/mysql/bigint_pk/bigint_pk_spec.rb +15 -15
  20. data/spec/mysql/bigint_pk/int_pk_spec.rb +45 -0
  21. data/spec/mysql/cli/config_spec.rb +7 -7
  22. data/spec/mysql/cli/ridgepole_spec.rb +20 -20
  23. data/spec/mysql/collation/collation_spec.rb +40 -41
  24. data/spec/mysql/comment/comment_spec.rb +19 -19
  25. data/spec/mysql/default_lambda/default_lambda_spec.rb +3 -3
  26. data/spec/mysql/diff/diff2_spec.rb +8 -5
  27. data/spec/mysql/diff/diff_spec.rb +8 -5
  28. data/spec/mysql/dump/dump_class_method_spec.rb +18 -68
  29. data/spec/mysql/dump/dump_some_tables_spec.rb +10 -30
  30. data/spec/mysql/dump/dump_spec.rb +21 -54
  31. data/spec/mysql/dump/dump_without_table_options_spec.rb +8 -35
  32. data/spec/mysql/fk/migrate_change_fk_spec.rb +8 -8
  33. data/spec/mysql/fk/migrate_create_fk_spec.rb +21 -35
  34. data/spec/mysql/fk/migrate_drop_fk_spec.rb +16 -30
  35. data/spec/mysql/migrate/migrate_add_column2_spec.rb +3 -5
  36. data/spec/mysql/migrate/migrate_add_column_order_spec.rb +21 -39
  37. data/spec/mysql/migrate/migrate_change_column5_spec.rb +8 -8
  38. data/spec/mysql/migrate/migrate_change_column6_spec.rb +18 -18
  39. data/spec/mysql/migrate/migrate_change_column_default_spec.rb +23 -16
  40. data/spec/mysql/migrate/migrate_change_column_spec.rb +34 -34
  41. data/spec/mysql/migrate/migrate_change_index3_spec.rb +19 -9
  42. data/spec/mysql/migrate/migrate_create_index_spec.rb +32 -32
  43. data/spec/mysql/migrate/migrate_create_table_spec.rb +0 -9
  44. data/spec/mysql/migrate/migrate_drop_index_spec.rb +32 -32
  45. data/spec/mysql/migrate/migrate_drop_table_spec.rb +30 -30
  46. data/spec/mysql/migrate/migrate_execute_spec.rb +68 -81
  47. data/spec/mysql/migrate/migrate_merge_mode_spec.rb +1 -3
  48. data/spec/mysql/migrate/migrate_noop_spec.rb +34 -61
  49. data/spec/mysql/migrate/migrate_rename_table_spec.rb +3 -24
  50. data/spec/mysql/migrate/migrate_same_spec.rb +12 -45
  51. data/spec/mysql/migrate/migrate_with_ignore_tables_spec.rb +6 -6
  52. data/spec/mysql/migrate/migrate_with_tables_spec.rb +2 -2
  53. data/spec/mysql/migrate/migrate_with_verbose_log_spec.rb +1 -6
  54. data/spec/mysql/migrate_/migrate_drop_index_with_alter_spec.rb +10 -10
  55. data/spec/mysql/text_blob_types/text_blob_types_spec.rb +3 -3
  56. data/spec/mysql/~default_name_fk/migrate_change_fk_spec.rb +6 -6
  57. data/spec/mysql/~default_name_fk/migrate_create_fk_spec.rb +10 -10
  58. data/spec/mysql/~default_name_fk/migrate_drop_fk_spec.rb +6 -6
  59. data/spec/postgresql/diff/diff_spec.rb +6 -0
  60. data/spec/postgresql/dump/dump_spec.rb +9 -33
  61. data/spec/postgresql/migrate/migrate_add_expression_index_spec.rb +3 -3
  62. data/spec/postgresql/migrate/migrate_bigint_spec.rb +10 -26
  63. data/spec/postgresql/migrate/migrate_create_table_spec.rb +0 -9
  64. data/spec/postgresql/migrate/migrate_create_table_with_default_proc_spec.rb +1 -1
  65. data/spec/postgresql/migrate/migrate_drop_column_with_index_spec.rb +2 -2
  66. data/spec/postgresql/migrate/migrate_drop_expression_index_spec.rb +7 -7
  67. data/spec/postgresql/migrate/migrate_drop_index_spec.rb +4 -4
  68. data/spec/postgresql/migrate/migrate_drop_table_spec.rb +3 -3
  69. data/spec/postgresql/migrate/migrate_ext_cols_spec.rb +0 -3
  70. data/spec/postgresql/migrate/migrate_same_spec.rb +9 -33
  71. data/spec/spec_condition.rb +15 -6
  72. data/spec/spec_helper.rb +2 -15
  73. metadata +14 -10
@@ -1,27 +1,14 @@
1
1
  describe 'Ridgepole::Client#diff -> migrate' do
2
- let(:template_variables) {
3
- opts = {
4
- sql_int_type: 'int(11)',
5
- test_schema: TEST_SCHEMA,
6
- }
7
-
8
- if condition(:mysql_awesome_enabled)
9
- opts[:sql_int_type] = 'int(10) unsigned'
10
- end
11
-
12
- opts
13
- }
14
-
15
2
  context 'when execute' do
16
3
  let(:dsl) {
17
- erbh(<<-EOS, template_variables)
18
- create_table "authors", <%= i unsigned(true) + {force: :cascade} %> do |t|
19
- t.string "name", <%= i limit(255) + {null: false} %>
4
+ erbh(<<-EOS)
5
+ create_table "authors", <%= i cond(5.1, id: :integer) + {force: :cascade} %> do |t|
6
+ t.string "name", null: false
20
7
  end
21
8
 
22
- create_table "books", <%= i unsigned(true) + {force: :cascade} %> do |t|
23
- t.string "title", <%= i limit(255) + {null: false} %>
24
- t.integer "author_id", <%= i limit(4) + {null: false} + unsigned(true) %>
9
+ create_table "books", <%= i cond(5.1, id: :integer) + {force: :cascad} %>e do |t|
10
+ t.string "title", null: false
11
+ t.integer "author_id", null: false
25
12
  end
26
13
 
27
14
  <%= add_index "books", ["author_id"], name: "idx_author_id", using: :btree %>
@@ -29,20 +16,20 @@ describe 'Ridgepole::Client#diff -> migrate' do
29
16
  }
30
17
 
31
18
  let(:dsl_with_execute) {
32
- erbh(<<-EOS, template_variables)
33
- create_table "authors", force: :cascade do |t|
19
+ erbh(<<-EOS)
20
+ create_table "authors", <%= i cond(5.1, id: :integer) + {force: :cascade} %> do |t|
34
21
  t.string "name", null: false
35
22
  end
36
23
 
37
- create_table "books", force: :cascade do |t|
24
+ create_table "books", <%= i cond(5.1, id: :integer) + {force: :cascad} %>e do |t|
38
25
  t.string "title", null: false
39
- t.integer "author_id", <%= i limit(4) + {null: false} + unsigned(true) %>
26
+ t.integer "author_id", null: false
40
27
  end
41
28
 
42
29
  <%= add_index "books", ["author_id"], name: "idx_author_id", using: :btree %>
43
30
 
44
31
  execute("ALTER TABLE books ADD CONSTRAINT fk_author FOREIGN KEY (author_id) REFERENCES authors (id)") do |c|
45
- c.raw_connection.query("SELECT 1 FROM information_schema.key_column_usage WHERE TABLE_SCHEMA = '<%= @test_schema %>' AND CONSTRAINT_NAME = 'fk_author' LIMIT 1").each.length.zero?
32
+ c.raw_connection.query("SELECT 1 FROM information_schema.key_column_usage WHERE TABLE_SCHEMA = '<%= TEST_SCHEMA %>' AND CONSTRAINT_NAME = 'fk_author' LIMIT 1").each.length.zero?
46
33
  end
47
34
  EOS
48
35
  }
@@ -55,13 +42,13 @@ describe 'Ridgepole::Client#diff -> migrate' do
55
42
  expect(delta.differ?).to be_truthy
56
43
  expect(subject.dump).to match_fuzzy dsl
57
44
 
58
- expect(show_create_table(:books)).to match_fuzzy erbh(<<-EOS, template_variables)
45
+ expect(show_create_table(:books)).to match_fuzzy erbh(<<-EOS)
59
46
  CREATE TABLE `books` (
60
- `id` <%= @sql_int_type %> NOT NULL AUTO_INCREMENT,
47
+ `id` int(11) NOT NULL AUTO_INCREMENT,
61
48
  `title` varchar(255) NOT NULL,
62
- `author_id` <%= @sql_int_type %> NOT NULL,
49
+ `author_id` int(11) NOT NULL,
63
50
  PRIMARY KEY (`id`),
64
- KEY `idx_author_id` (`author_id`) USING BTREE
51
+ KEY `idx_author_id` (`author_id`) <%= cond(5.0, 'USING BTREE') %>
65
52
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8
66
53
  EOS
67
54
 
@@ -71,13 +58,13 @@ describe 'Ridgepole::Client#diff -> migrate' do
71
58
  add_foreign_key "books", "authors", name: "fk_author"
72
59
  EOS
73
60
 
74
- expect(show_create_table(:books)).to match_fuzzy erbh(<<-EOS, template_variables)
61
+ expect(show_create_table(:books)).to match_fuzzy erbh(<<-EOS)
75
62
  CREATE TABLE `books` (
76
- `id` <%= @sql_int_type %> NOT NULL AUTO_INCREMENT,
63
+ `id` int(11) NOT NULL AUTO_INCREMENT,
77
64
  `title` varchar(255) NOT NULL,
78
- `author_id` <%= @sql_int_type %> NOT NULL,
65
+ `author_id` int(11) NOT NULL,
79
66
  PRIMARY KEY (`id`),
80
- KEY `idx_author_id` (`author_id`) USING BTREE,
67
+ KEY `idx_author_id` (`author_id`) <%= cond(5.0, 'USING BTREE') %>,
81
68
  CONSTRAINT `fk_author` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`)
82
69
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8
83
70
  EOS
@@ -86,14 +73,14 @@ describe 'Ridgepole::Client#diff -> migrate' do
86
73
 
87
74
  context 'when not execute' do
88
75
  let(:dsl) {
89
- erbh(<<-EOS, template_variables)
90
- create_table "authors", force: :cascade do |t|
91
- t.string "name", <%= i limit(255) + {null: false} %>
76
+ erbh(<<-EOS)
77
+ create_table "authors", <%= i cond(5.1, id: :integer) + {force: :cascade} %> do |t|
78
+ t.string "name", null: false
92
79
  end
93
80
 
94
- create_table "books", force: :cascade do |t|
95
- t.string "title", <%= i limit(255) + {null: false} %>
96
- t.integer "author_id", <%= i limit(4) + {null: false} %>
81
+ create_table "books", <%= i cond(5.1, id: :integer) + {force: :cascad} %>e do |t|
82
+ t.string "title", null: false
83
+ t.integer "author_id", null: false
97
84
  end
98
85
 
99
86
  <%= add_index "books", ["author_id"], name: "idx_author_id", using: :btree %>
@@ -102,20 +89,20 @@ describe 'Ridgepole::Client#diff -> migrate' do
102
89
  }
103
90
 
104
91
  let(:dsl_with_execute) {
105
- erbh(<<-EOS, template_variables)
106
- create_table "authors", force: :cascade do |t|
92
+ erbh(<<-EOS)
93
+ create_table "authors", <%= i cond(5.1, id: :integer) + {force: :cascade} %> do |t|
107
94
  t.string "name", null: false
108
95
  end
109
96
 
110
- create_table "books", force: :cascade do |t|
97
+ create_table "books", <%= i cond(5.1, id: :integer) + {force: :cascad} %>e do |t|
111
98
  t.string "title", null: false
112
- t.integer "author_id", <%= i limit(4) + {null: false} %>
99
+ t.integer "author_id", null: false
113
100
  end
114
101
 
115
102
  <%= add_index "books", ["author_id"], name: "idx_author_id", using: :btree %>
116
103
 
117
104
  execute("ALTER TABLE books ADD CONSTRAINT fk_author FOREIGN KEY (author_id) REFERENCES authors (id)") do |c|
118
- c.raw_connection.query("SELECT 1 FROM information_schema.key_column_usage WHERE TABLE_SCHEMA = '<%= @test_schema %>' AND CONSTRAINT_NAME = 'fk_author' LIMIT 1").each.length.zero?
105
+ c.raw_connection.query("SELECT 1 FROM information_schema.key_column_usage WHERE TABLE_SCHEMA = '<%= TEST_SCHEMA %>' AND CONSTRAINT_NAME = 'fk_author' LIMIT 1").each.length.zero?
119
106
  end
120
107
 
121
108
  add_foreign_key "books", "authors", name: "fk_author"
@@ -130,13 +117,13 @@ describe 'Ridgepole::Client#diff -> migrate' do
130
117
  expect(delta.differ?).to be_truthy
131
118
  expect(subject.dump).to match_fuzzy dsl
132
119
 
133
- expect(show_create_table(:books)).to match_fuzzy erbh(<<-EOS, template_variables)
120
+ expect(show_create_table(:books)).to match_fuzzy erbh(<<-EOS)
134
121
  CREATE TABLE `books` (
135
122
  `id` int(11) NOT NULL AUTO_INCREMENT,
136
123
  `title` varchar(255) NOT NULL,
137
124
  `author_id` int(11) NOT NULL,
138
125
  PRIMARY KEY (`id`),
139
- KEY `idx_author_id` (`author_id`) USING BTREE,
126
+ KEY `idx_author_id` (`author_id`) <%= cond(5.0, 'USING BTREE') %>,
140
127
  CONSTRAINT `fk_author` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`)
141
128
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8
142
129
  EOS
@@ -145,13 +132,13 @@ describe 'Ridgepole::Client#diff -> migrate' do
145
132
  expect(migrated).to be_falsey
146
133
  expect(subject.dump).to match_fuzzy dsl
147
134
 
148
- expect(show_create_table(:books)).to match_fuzzy erbh(<<-EOS, template_variables)
135
+ expect(show_create_table(:books)).to match_fuzzy erbh(<<-EOS)
149
136
  CREATE TABLE `books` (
150
137
  `id` int(11) NOT NULL AUTO_INCREMENT,
151
138
  `title` varchar(255) NOT NULL,
152
139
  `author_id` int(11) NOT NULL,
153
140
  PRIMARY KEY (`id`),
154
- KEY `idx_author_id` (`author_id`) USING BTREE,
141
+ KEY `idx_author_id` (`author_id`) <%= cond(5.0, 'USING BTREE') %>,
155
142
  CONSTRAINT `fk_author` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`)
156
143
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8
157
144
  EOS
@@ -160,14 +147,14 @@ describe 'Ridgepole::Client#diff -> migrate' do
160
147
 
161
148
  context 'when execute (noop)' do
162
149
  let(:dsl) {
163
- erbh(<<-EOS, template_variables)
164
- create_table "authors", <%= i unsigned(true) + {force: :cascade} %> do |t|
165
- t.string "name", <%= i limit(255) + {null: false} %>
150
+ erbh(<<-EOS)
151
+ create_table "authors", <%= i cond(5.1, id: :integer) + {force: :cascade} %> do |t|
152
+ t.string "name", null: false
166
153
  end
167
154
 
168
- create_table "books", <%= i unsigned(true) + {force: :cascade} %> do |t|
169
- t.string "title", <%= i limit(255) + {null: false} %>
170
- t.integer "author_id", <%= i limit(4) + {null: false} + unsigned(true) %>
155
+ create_table "books", <%= i cond(5.1, id: :integer) + {force: :cascad} %>e do |t|
156
+ t.string "title", null: false
157
+ t.integer "author_id", null: false
171
158
  end
172
159
 
173
160
  <%= add_index "books", ["author_id"], name: "idx_author_id", using: :btree %>
@@ -175,20 +162,20 @@ describe 'Ridgepole::Client#diff -> migrate' do
175
162
  }
176
163
 
177
164
  let(:dsl_with_execute) {
178
- erbh(<<-EOS, template_variables)
179
- create_table "authors", force: :cascade do |t|
165
+ erbh(<<-EOS)
166
+ create_table "authors", <%= i cond(5.1, id: :integer) + {force: :cascade} %> do |t|
180
167
  t.string "name", null: false
181
168
  end
182
169
 
183
- create_table "books", force: :cascade do |t|
170
+ create_table "books", <%= i cond(5.1, id: :integer) + {force: :cascad} %>e do |t|
184
171
  t.string "title", null: false
185
- t.integer "author_id", <%= i limit(4) + {null: false} + unsigned(true) %>
172
+ t.integer "author_id", null: false
186
173
  end
187
174
 
188
175
  <%= add_index "books", ["author_id"], name: "idx_author_id", using: :btree %>
189
176
 
190
177
  execute("ALTER TABLE books ADD CONSTRAINT fk_author FOREIGN KEY (author_id) REFERENCES authors (id)") do |c|
191
- c.raw_connection.query("SELECT 1 FROM information_schema.key_column_usage WHERE TABLE_SCHEMA = '<%= @test_schema %>' AND CONSTRAINT_NAME = 'fk_author' LIMIT 1").each.length.zero?
178
+ c.raw_connection.query("SELECT 1 FROM information_schema.key_column_usage WHERE TABLE_SCHEMA = '<%= TEST_SCHEMA %>' AND CONSTRAINT_NAME = 'fk_author' LIMIT 1").each.length.zero?
192
179
  end
193
180
  EOS
194
181
  }
@@ -201,13 +188,13 @@ describe 'Ridgepole::Client#diff -> migrate' do
201
188
  expect(delta.differ?).to be_truthy
202
189
  expect(subject.dump).to match_fuzzy dsl
203
190
 
204
- expect(show_create_table(:books)).to match_fuzzy erbh(<<-EOS, template_variables)
191
+ expect(show_create_table(:books)).to match_fuzzy erbh(<<-EOS)
205
192
  CREATE TABLE `books` (
206
- `id` <%= @sql_int_type %> NOT NULL AUTO_INCREMENT,
193
+ `id` int(11) NOT NULL AUTO_INCREMENT,
207
194
  `title` varchar(255) NOT NULL,
208
- `author_id` <%= @sql_int_type %> NOT NULL,
195
+ `author_id` int(11) NOT NULL,
209
196
  PRIMARY KEY (`id`),
210
- KEY `idx_author_id` (`author_id`) USING BTREE
197
+ KEY `idx_author_id` (`author_id`) <%= cond(5.0, 'USING BTREE') %>
211
198
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8
212
199
  EOS
213
200
 
@@ -217,13 +204,13 @@ describe 'Ridgepole::Client#diff -> migrate' do
217
204
 
218
205
  expect(sql).to match_fuzzy "ALTER TABLE books ADD CONSTRAINT fk_author FOREIGN KEY (author_id) REFERENCES authors (id)"
219
206
 
220
- expect(show_create_table(:books)).to match_fuzzy erbh(<<-EOS, template_variables)
207
+ expect(show_create_table(:books)).to match_fuzzy erbh(<<-EOS)
221
208
  CREATE TABLE `books` (
222
- `id` <%= @sql_int_type %> NOT NULL AUTO_INCREMENT,
209
+ `id` int(11) NOT NULL AUTO_INCREMENT,
223
210
  `title` varchar(255) NOT NULL,
224
- `author_id` <%= @sql_int_type %> NOT NULL,
211
+ `author_id` int(11) NOT NULL,
225
212
  PRIMARY KEY (`id`),
226
- KEY `idx_author_id` (`author_id`) USING BTREE
213
+ KEY `idx_author_id` (`author_id`) <%= cond(5.0, 'USING BTREE') %>
227
214
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8
228
215
  EOS
229
216
  }
@@ -231,14 +218,14 @@ describe 'Ridgepole::Client#diff -> migrate' do
231
218
 
232
219
  context 'when not execute (noop)' do
233
220
  let(:dsl) {
234
- erbh(<<-EOS, template_variables)
235
- create_table "authors", force: :cascade do |t|
236
- t.string "name", <%= i limit(255) + {null: false} %>
221
+ erbh(<<-EOS)
222
+ create_table "authors", <%= i cond(5.1, id: :integer) + {force: :cascade} %> do |t|
223
+ t.string "name", null: false
237
224
  end
238
225
 
239
- create_table "books", force: :cascade do |t|
240
- t.string "title", <%= i limit(255) + {null: false} %>
241
- t.integer "author_id", <%= i limit(4) + {null: false} %>
226
+ create_table "books", <%= i cond(5.1, id: :integer) + {force: :cascad} %>e do |t|
227
+ t.string "title", null: false
228
+ t.integer "author_id", null: false
242
229
  end
243
230
 
244
231
  <%= add_index "books", ["author_id"], name: "idx_author_id", using: :btree %>
@@ -247,20 +234,20 @@ describe 'Ridgepole::Client#diff -> migrate' do
247
234
  }
248
235
 
249
236
  let(:dsl_with_execute) {
250
- erbh(<<-EOS, template_variables)
251
- create_table "authors", force: :cascade do |t|
237
+ erbh(<<-EOS)
238
+ create_table "authors", <%= i cond(5.1, id: :integer) + {force: :cascade} %> do |t|
252
239
  t.string "name", null: false
253
240
  end
254
241
 
255
- create_table "books", force: :cascade do |t|
242
+ create_table "books", <%= i cond(5.1, id: :integer) + {force: :cascad} %>e do |t|
256
243
  t.string "title", null: false
257
- t.integer "author_id", <%= i limit(4) + {null: false} %>
244
+ t.integer "author_id", null: false
258
245
  end
259
246
 
260
247
  <%= add_index "books", ["author_id"], name: "idx_author_id", using: :btree %>
261
248
 
262
249
  execute("ALTER TABLE books ADD CONSTRAINT fk_author FOREIGN KEY (author_id) REFERENCES authors (id)") do |c|
263
- c.raw_connection.query("SELECT 1 FROM information_schema.key_column_usage WHERE TABLE_SCHEMA = '<%= @test_schema %>' AND CONSTRAINT_NAME = 'fk_author' LIMIT 1").each.length.zero?
250
+ c.raw_connection.query("SELECT 1 FROM information_schema.key_column_usage WHERE TABLE_SCHEMA = '<%= TEST_SCHEMA %>' AND CONSTRAINT_NAME = 'fk_author' LIMIT 1").each.length.zero?
264
251
  end
265
252
 
266
253
  add_foreign_key "books", "authors", name: "fk_author"
@@ -275,13 +262,13 @@ describe 'Ridgepole::Client#diff -> migrate' do
275
262
  expect(delta.differ?).to be_truthy
276
263
  expect(subject.dump).to match_fuzzy dsl
277
264
 
278
- expect(show_create_table(:books)).to match_fuzzy erbh(<<-EOS, template_variables)
265
+ expect(show_create_table(:books)).to match_fuzzy erbh(<<-EOS)
279
266
  CREATE TABLE `books` (
280
267
  `id` int(11) NOT NULL AUTO_INCREMENT,
281
268
  `title` varchar(255) NOT NULL,
282
269
  `author_id` int(11) NOT NULL,
283
270
  PRIMARY KEY (`id`),
284
- KEY `idx_author_id` (`author_id`) USING BTREE,
271
+ KEY `idx_author_id` (`author_id`) <%= cond(5.0, 'USING BTREE') %>,
285
272
  CONSTRAINT `fk_author` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`)
286
273
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8
287
274
  EOS
@@ -292,13 +279,13 @@ describe 'Ridgepole::Client#diff -> migrate' do
292
279
 
293
280
  expect(sql).to match_fuzzy ""
294
281
 
295
- expect(show_create_table(:books)).to match_fuzzy erbh(<<-EOS, template_variables)
282
+ expect(show_create_table(:books)).to match_fuzzy erbh(<<-EOS)
296
283
  CREATE TABLE `books` (
297
284
  `id` int(11) NOT NULL AUTO_INCREMENT,
298
285
  `title` varchar(255) NOT NULL,
299
286
  `author_id` int(11) NOT NULL,
300
287
  PRIMARY KEY (`id`),
301
- KEY `idx_author_id` (`author_id`) USING BTREE,
288
+ KEY `idx_author_id` (`author_id`) <%= cond(5.0, 'USING BTREE') %>,
302
289
  CONSTRAINT `fk_author` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`)
303
290
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8
304
291
  EOS
@@ -4,9 +4,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
4
4
  unsigned: {}
5
5
  }
6
6
 
7
- if condition(:mysql_awesome_enabled)
8
- opts[:unsigned] = {unsigned: true}
9
- end
7
+ opts[:unsigned] = {unsigned: true}
10
8
 
11
9
  opts
12
10
  }
@@ -1,31 +1,4 @@
1
1
  describe 'Ridgepole::Client#diff -> migrate' do
2
- let(:template_variables) {
3
- opts = {
4
- sql_int_pk_type: 'int(11) auto_increment PRIMARY KEY',
5
- sql_int_type: 'int(11)',
6
- sql_uint_type: 'int(11)',
7
- }
8
-
9
- if condition(:mysql_awesome_enabled)
10
- opts.merge!(
11
- sql_int_pk_type: 'int PRIMARY KEY AUTO_INCREMENT',
12
- sql_int_type: 'int',
13
- sql_uint_type: 'int unsigned'
14
- )
15
- end
16
-
17
- if condition(:activerecord_5)
18
- opts.merge!(
19
- sql_int_pk_type: 'int AUTO_INCREMENT PRIMARY KEY',
20
- sql_int_type: 'int',
21
- sql_uint_type: 'int unsigned',
22
- using_btree: 'USING btree'
23
- )
24
- end
25
-
26
- opts
27
- }
28
-
29
2
  context 'when no operation' do
30
3
  let(:actual_dsl) { '' }
31
4
  let(:expected_dsl) {
@@ -106,23 +79,23 @@ describe 'Ridgepole::Client#diff -> migrate' do
106
79
  expect(migrated).to be_truthy
107
80
  expect(subject.dump).to match_fuzzy actual_dsl
108
81
 
109
- expect(sql).to match_fuzzy erbh(<<-EOS, template_variables)
110
- CREATE TABLE `clubs` (`id` <%= @sql_int_pk_type %>, `name` varchar(255) DEFAULT '' NOT NULL) ENGINE=InnoDB
82
+ expect(sql).to match_fuzzy erbh(<<-EOS)
83
+ CREATE TABLE `clubs` (`id` <%= cond(5.1, 'bigint NOT NULL', 'int') %> AUTO_INCREMENT PRIMARY KEY, `name` varchar(255) DEFAULT '' NOT NULL) ENGINE=InnoDB
111
84
  CREATE UNIQUE INDEX `idx_name` USING btree ON `clubs` (`name`)
112
- CREATE TABLE `departments` (`dept_no` <%= @sql_int_pk_type %>, `dept_name` varchar(40) NOT NULL) ENGINE=InnoDB
85
+ CREATE TABLE `departments` (`dept_no` <%= cond(5.1, 'bigint NOT NULL', 'int') %> AUTO_INCREMENT PRIMARY KEY, `dept_name` varchar(40) NOT NULL) ENGINE=InnoDB
113
86
  CREATE UNIQUE INDEX `dept_name` USING btree ON `departments` (`dept_name`)
114
- CREATE TABLE `dept_emp` (`emp_no` <%= @sql_int_type %> NOT NULL, `dept_no` varchar(4) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
87
+ CREATE TABLE `dept_emp` (`emp_no` int NOT NULL, `dept_no` varchar(4) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
115
88
  CREATE INDEX `dept_no` USING btree ON `dept_emp` (`dept_no`)
116
89
  CREATE INDEX `emp_no` USING btree ON `dept_emp` (`emp_no`)
117
- CREATE TABLE `dept_manager` (`dept_no` varchar(4) NOT NULL, `emp_no` <%= @sql_int_type %> NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
90
+ CREATE TABLE `dept_manager` (`dept_no` varchar(4) NOT NULL, `emp_no` int NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
118
91
  CREATE INDEX `dept_no` USING btree ON `dept_manager` (`dept_no`)
119
92
  CREATE INDEX `emp_no` USING btree ON `dept_manager` (`emp_no`)
120
- CREATE TABLE `employee_clubs` (`id` <%= @sql_int_pk_type %>, `emp_no` <%= @sql_uint_type %> NOT NULL, `club_id` <%= @sql_uint_type %> NOT NULL) ENGINE=InnoDB
93
+ CREATE TABLE `employee_clubs` (`id` <%= cond(5.1, 'bigint NOT NULL', 'int') %> AUTO_INCREMENT PRIMARY KEY, `emp_no` int unsigned NOT NULL, `club_id` int unsigned NOT NULL) ENGINE=InnoDB
121
94
  CREATE INDEX `idx_emp_no_club_id` USING btree ON `employee_clubs` (`emp_no`, `club_id`)
122
- CREATE TABLE `employees` (`emp_no` <%= @sql_int_pk_type %>, `birth_date` date NOT NULL, `first_name` varchar(14) NOT NULL, `last_name` varchar(16) NOT NULL, `gender` varchar(1) NOT NULL, `hire_date` date NOT NULL) ENGINE=InnoDB
123
- CREATE TABLE `salaries` (`emp_no` <%= @sql_int_type %> NOT NULL, `salary` <%= @sql_int_type %> NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
95
+ CREATE TABLE `employees` (`emp_no` <%= cond(5.1, 'bigint NOT NULL', 'int') %> AUTO_INCREMENT PRIMARY KEY, `birth_date` date NOT NULL, `first_name` varchar(14) NOT NULL, `last_name` varchar(16) NOT NULL, `gender` varchar(1) NOT NULL, `hire_date` date NOT NULL) ENGINE=InnoDB
96
+ CREATE TABLE `salaries` (`emp_no` int NOT NULL, `salary` int NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
124
97
  CREATE INDEX `emp_no` USING btree ON `salaries` (`emp_no`)
125
- CREATE TABLE `titles` (`emp_no` <%= @sql_int_type %> NOT NULL, `title` varchar(50) NOT NULL, `from_date` date NOT NULL, `to_date` date) ENGINE=InnoDB
98
+ CREATE TABLE `titles` (`emp_no` int NOT NULL, `title` varchar(50) NOT NULL, `from_date` date NOT NULL, `to_date` date) ENGINE=InnoDB
126
99
  CREATE INDEX `emp_no` USING btree ON `titles` (`emp_no`)
127
100
  EOS
128
101
  }
@@ -135,22 +108,22 @@ describe 'Ridgepole::Client#diff -> migrate' do
135
108
  expect(subject.dump).to match_fuzzy actual_dsl
136
109
 
137
110
  # XXX:
138
- expect(sql.gsub('`', '')).to match_fuzzy erbh(<<-EOS, template_variables).gsub('`', '')
139
- CREATE TABLE `clubs` (`id` <%= @sql_int_pk_type %>, `name` varchar(255) DEFAULT '' NOT NULL) ENGINE=InnoDB
140
- ALTER TABLE `clubs` ADD UNIQUE INDEX `idx_name` <%= @using_btree %> (`name`)
141
- CREATE TABLE `departments` (`dept_no` <%= @sql_int_pk_type %>, `dept_name` varchar(40) NOT NULL) ENGINE=InnoDB
142
- ALTER TABLE `departments` ADD UNIQUE INDEX `dept_name` <%= @using_btree %> (`dept_name`)
143
- CREATE TABLE `dept_emp` (`emp_no` <%= @sql_int_type %> NOT NULL, `dept_no` varchar(4) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
144
- ALTER TABLE `dept_emp` ADD INDEX `dept_no` <%= @using_btree %> (`dept_no`), ADD INDEX `emp_no` <%= @using_btree %> (`emp_no`)
145
- CREATE TABLE `dept_manager` (`dept_no` varchar(4) NOT NULL, `emp_no` <%= @sql_int_type %> NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
146
- ALTER TABLE `dept_manager` ADD INDEX `dept_no` <%= @using_btree %> (`dept_no`), ADD INDEX `emp_no` <%= @using_btree %> (`emp_no`)
147
- CREATE TABLE `employee_clubs` (`id` <%= @sql_int_pk_type %>, `emp_no` <%= @sql_uint_type %> NOT NULL, `club_id` <%= @sql_uint_type %> NOT NULL) ENGINE=InnoDB
148
- ALTER TABLE `employee_clubs` ADD INDEX `idx_emp_no_club_id` <%= @using_btree %> (`emp_no`, `club_id`)
149
- CREATE TABLE `employees` (`emp_no` <%= @sql_int_pk_type %>, `birth_date` date NOT NULL, `first_name` varchar(14) NOT NULL, `last_name` varchar(16) NOT NULL, `gender` varchar(1) NOT NULL, `hire_date` date NOT NULL) ENGINE=InnoDB
150
- CREATE TABLE `salaries` (`emp_no` <%= @sql_int_type %> NOT NULL, `salary` <%= @sql_int_type %> NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
151
- ALTER TABLE `salaries` ADD INDEX `emp_no` <%= @using_btree %> (`emp_no`)
152
- CREATE TABLE `titles` (`emp_no` <%= @sql_int_type %> NOT NULL, `title` varchar(50) NOT NULL, `from_date` date NOT NULL, `to_date` date) ENGINE=InnoDB
153
- ALTER TABLE `titles` ADD INDEX `emp_no` <%= @using_btree %> (`emp_no`)
111
+ expect(sql.gsub('`', '')).to match_fuzzy erbh(<<-EOS).gsub('`', '')
112
+ CREATE TABLE `clubs` (`id` <%= cond(5.1, 'bigint NOT NULL', 'int') %> AUTO_INCREMENT PRIMARY KEY, `name` varchar(255) DEFAULT '' NOT NULL) ENGINE=InnoDB
113
+ ALTER TABLE `clubs` ADD UNIQUE INDEX `idx_name` USING btree (`name`)
114
+ CREATE TABLE `departments` (`dept_no` <%= cond(5.1, 'bigint NOT NULL', 'int') %> AUTO_INCREMENT PRIMARY KEY, `dept_name` varchar(40) NOT NULL) ENGINE=InnoDB
115
+ ALTER TABLE `departments` ADD UNIQUE INDEX `dept_name` USING btree (`dept_name`)
116
+ CREATE TABLE `dept_emp` (`emp_no` int NOT NULL, `dept_no` varchar(4) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
117
+ ALTER TABLE `dept_emp` ADD INDEX `dept_no` USING btree (`dept_no`), ADD INDEX `emp_no` USING btree (`emp_no`)
118
+ CREATE TABLE `dept_manager` (`dept_no` varchar(4) NOT NULL, `emp_no` int NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
119
+ ALTER TABLE `dept_manager` ADD INDEX `dept_no` USING btree (`dept_no`), ADD INDEX `emp_no` USING btree (`emp_no`)
120
+ CREATE TABLE `employee_clubs` (`id` <%= cond(5.1, 'bigint NOT NULL', 'int') %> AUTO_INCREMENT PRIMARY KEY, `emp_no` int unsigned NOT NULL, `club_id` int unsigned NOT NULL) ENGINE=InnoDB
121
+ ALTER TABLE `employee_clubs` ADD INDEX `idx_emp_no_club_id` USING btree (`emp_no`, `club_id`)
122
+ CREATE TABLE `employees` (`emp_no` <%= cond(5.1, 'bigint NOT NULL', 'int') %> AUTO_INCREMENT PRIMARY KEY, `birth_date` date NOT NULL, `first_name` varchar(14) NOT NULL, `last_name` varchar(16) NOT NULL, `gender` varchar(1) NOT NULL, `hire_date` date NOT NULL) ENGINE=InnoDB
123
+ CREATE TABLE `salaries` (`emp_no` int NOT NULL, `salary` int NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
124
+ ALTER TABLE `salaries` ADD INDEX `emp_no` USING btree (`emp_no`)
125
+ CREATE TABLE `titles` (`emp_no` int NOT NULL, `title` varchar(50) NOT NULL, `from_date` date NOT NULL, `to_date` date) ENGINE=InnoDB
126
+ ALTER TABLE `titles` ADD INDEX `emp_no` USING btree (`emp_no`)
154
127
  EOS
155
128
  }
156
129
  end
@@ -235,23 +208,23 @@ describe 'Ridgepole::Client#diff -> migrate' do
235
208
  expect(migrated).to be_truthy
236
209
  expect(subject.dump).to match_fuzzy actual_dsl
237
210
 
238
- expect(sql).to match_fuzzy erbh(<<-EOS, template_variables)
239
- CREATE TABLE `clubs` (`id` <%= @sql_int_pk_type %>, `name` varchar(255) DEFAULT '' NOT NULL) ENGINE=InnoDB
211
+ expect(sql).to match_fuzzy erbh(<<-EOS)
212
+ CREATE TABLE `clubs` (`id` <%= cond(5.1, 'bigint NOT NULL', 'int') %> AUTO_INCREMENT PRIMARY KEY, `name` varchar(255) DEFAULT '' NOT NULL) ENGINE=InnoDB
240
213
  CREATE UNIQUE INDEX `idx_name` USING btree ON `clubs` (`name`)
241
- CREATE TABLE `departments` (`dept_no` <%= @sql_int_pk_type %>, `dept_name` varchar(40) NOT NULL) ENGINE=InnoDB
214
+ CREATE TABLE `departments` (`dept_no` <%= cond(5.1, 'bigint NOT NULL', 'int') %> AUTO_INCREMENT PRIMARY KEY, `dept_name` varchar(40) NOT NULL) ENGINE=InnoDB
242
215
  CREATE UNIQUE INDEX `dept_name` USING btree ON `departments` (`dept_name`)
243
- CREATE TABLE `dept_emp` (`emp_no` <%= @sql_int_type %> NOT NULL, `dept_no` varchar(4) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
216
+ CREATE TABLE `dept_emp` (`emp_no` int NOT NULL, `dept_no` varchar(4) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
244
217
  CREATE INDEX `dept_no` USING btree ON `dept_emp` (`dept_no`)
245
218
  CREATE INDEX `emp_no` USING btree ON `dept_emp` (`emp_no`)
246
- CREATE TABLE `dept_manager` (`dept_no` varchar(4) NOT NULL, `emp_no` <%= @sql_int_type %> NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
219
+ CREATE TABLE `dept_manager` (`dept_no` varchar(4) NOT NULL, `emp_no` int NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
247
220
  CREATE INDEX `dept_no` USING btree ON `dept_manager` (`dept_no`)
248
221
  CREATE INDEX `emp_no` USING btree ON `dept_manager` (`emp_no`)
249
- CREATE TABLE `employee_clubs` (`id` <%= @sql_int_pk_type %>, `emp_no` <%= @sql_uint_type %> NOT NULL, `club_id` <%= @sql_uint_type %> NOT NULL) ENGINE=InnoDB
222
+ CREATE TABLE `employee_clubs` (`id` <%= cond(5.1, 'bigint NOT NULL', 'int') %> AUTO_INCREMENT PRIMARY KEY, `emp_no` int unsigned NOT NULL, `club_id` int unsigned NOT NULL) ENGINE=InnoDB
250
223
  CREATE INDEX `idx_emp_no_club_id` USING btree ON `employee_clubs` (`emp_no`, `club_id`)
251
- CREATE TABLE `employees` (`emp_no` <%= @sql_int_pk_type %>, `birth_date` date NOT NULL, `first_name` varchar(14) NOT NULL, `last_name` varchar(16) NOT NULL, `gender` varchar(1) NOT NULL, `hire_date` date NOT NULL) ENGINE=InnoDB
252
- CREATE TABLE `salaries` (`emp_no` <%= @sql_int_type %> NOT NULL, `salary` <%= @sql_int_type %> NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
224
+ CREATE TABLE `employees` (`emp_no` <%= cond(5.1, 'bigint NOT NULL', 'int') %> AUTO_INCREMENT PRIMARY KEY, `birth_date` date NOT NULL, `first_name` varchar(14) NOT NULL, `last_name` varchar(16) NOT NULL, `gender` varchar(1) NOT NULL, `hire_date` date NOT NULL) ENGINE=InnoDB
225
+ CREATE TABLE `salaries` (`emp_no` int NOT NULL, `salary` int NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
253
226
  CREATE INDEX `emp_no` USING btree ON `salaries` (`emp_no`)
254
- CREATE TABLE `titles` (`emp_no` <%= @sql_int_type %> NOT NULL, `title` varchar(50) NOT NULL, `from_date` date NOT NULL, `to_date` date) ENGINE=InnoDB
227
+ CREATE TABLE `titles` (`emp_no` int NOT NULL, `title` varchar(50) NOT NULL, `from_date` date NOT NULL, `to_date` date) ENGINE=InnoDB
255
228
  CREATE INDEX `emp_no` USING btree ON `titles` (`emp_no`)
256
229
  EOS
257
230
  }