ridgepole 0.9.5 → 0.9.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/ridgepole/delta.rb +1 -1
- data/lib/ridgepole/version.rb +1 -1
- data/ridgepole.gemspec +5 -2
- metadata +3 -279
- data/.github/workflows/test.yml +0 -70
- data/.gitignore +0 -25
- data/spec/cli_helper.rb +0 -65
- data/spec/dsl_parser/context_spec.rb +0 -16
- data/spec/erb_helper.rb +0 -26
- data/spec/fixtures/for_require_relative_spec.rb +0 -3
- data/spec/hide_pending_formatter.rb +0 -9
- data/spec/mysql/_migrate/migrate_change_table_option_spec.rb +0 -40
- data/spec/mysql/bigint_pk/int_pk_spec.rb +0 -47
- data/spec/mysql/cli/config_spec.rb +0 -210
- data/spec/mysql/cli/ridgepole_spec.rb +0 -447
- data/spec/mysql/collation/collation_spec.rb +0 -153
- data/spec/mysql/comment/comment_spec.rb +0 -179
- data/spec/mysql/default_lambda/default_lambda_spec.rb +0 -164
- data/spec/mysql/diff/diff2_spec.rb +0 -189
- data/spec/mysql/diff/diff_spec.rb +0 -168
- data/spec/mysql/dump/dump_class_method_spec.rb +0 -74
- data/spec/mysql/dump/dump_some_tables_spec.rb +0 -70
- data/spec/mysql/dump/dump_spec.rb +0 -74
- data/spec/mysql/dump/dump_unknown_column_type_spec.rb +0 -28
- data/spec/mysql/dump/dump_without_table_options_spec.rb +0 -34
- data/spec/mysql/fk/migrate_change_fk2_spec.rb +0 -47
- data/spec/mysql/fk/migrate_change_fk_spec.rb +0 -265
- data/spec/mysql/fk/migrate_create_fk_spec.rb +0 -349
- data/spec/mysql/fk/migrate_drop_fk_spec.rb +0 -331
- data/spec/mysql/fk/migrate_fk_with_column_spec.rb +0 -163
- data/spec/mysql/fk/migrate_ignore_fk_spec.rb +0 -70
- data/spec/mysql/migrate/check_orphan_index_spec.rb +0 -83
- data/spec/mysql/migrate/migrate_add_column2_spec.rb +0 -159
- data/spec/mysql/migrate/migrate_add_column_order_spec.rb +0 -242
- data/spec/mysql/migrate/migrate_add_column_spec.rb +0 -161
- data/spec/mysql/migrate/migrate_add_column_with_alter_extra_spec.rb +0 -276
- data/spec/mysql/migrate/migrate_add_column_with_script_spec.rb +0 -152
- data/spec/mysql/migrate/migrate_change_column2_spec.rb +0 -91
- data/spec/mysql/migrate/migrate_change_column3_spec.rb +0 -404
- data/spec/mysql/migrate/migrate_change_column4_spec.rb +0 -83
- data/spec/mysql/migrate/migrate_change_column5_spec.rb +0 -129
- data/spec/mysql/migrate/migrate_change_column6_spec.rb +0 -241
- data/spec/mysql/migrate/migrate_change_column7_spec.rb +0 -34
- data/spec/mysql/migrate/migrate_change_column8_spec.rb +0 -87
- data/spec/mysql/migrate/migrate_change_column_default_spec.rb +0 -199
- data/spec/mysql/migrate/migrate_change_column_float_spec.rb +0 -75
- data/spec/mysql/migrate/migrate_change_column_spec.rb +0 -158
- data/spec/mysql/migrate/migrate_change_index2_spec.rb +0 -86
- data/spec/mysql/migrate/migrate_change_index3_spec.rb +0 -179
- data/spec/mysql/migrate/migrate_change_index4_spec.rb +0 -112
- data/spec/mysql/migrate/migrate_change_index5_spec.rb +0 -74
- data/spec/mysql/migrate/migrate_change_index6_spec.rb +0 -202
- data/spec/mysql/migrate/migrate_change_index7_spec.rb +0 -85
- data/spec/mysql/migrate/migrate_change_index8_spec.rb +0 -85
- data/spec/mysql/migrate/migrate_change_index_spec.rb +0 -235
- data/spec/mysql/migrate/migrate_change_table_comment_spec.rb +0 -72
- data/spec/mysql/migrate/migrate_change_table_option_spec.rb +0 -83
- data/spec/mysql/migrate/migrate_check_relation_column_type_spec.rb +0 -225
- data/spec/mysql/migrate/migrate_create_index2_spec.rb +0 -203
- data/spec/mysql/migrate/migrate_create_index_spec.rb +0 -220
- data/spec/mysql/migrate/migrate_create_table_spec.rb +0 -123
- data/spec/mysql/migrate/migrate_create_table_with_ignore_spec.rb +0 -45
- data/spec/mysql/migrate/migrate_create_table_with_index_spec.rb +0 -43
- data/spec/mysql/migrate/migrate_create_table_with_options_spec.rb +0 -59
- data/spec/mysql/migrate/migrate_create_table_with_script_spec.rb +0 -132
- data/spec/mysql/migrate/migrate_drop_column_and_index2_spec.rb +0 -140
- data/spec/mysql/migrate/migrate_drop_column_and_index_spec.rb +0 -167
- data/spec/mysql/migrate/migrate_drop_column_and_unique_index_spec.rb +0 -52
- data/spec/mysql/migrate/migrate_drop_column_spec.rb +0 -158
- data/spec/mysql/migrate/migrate_drop_index_spec.rb +0 -160
- data/spec/mysql/migrate/migrate_drop_table_spec.rb +0 -123
- data/spec/mysql/migrate/migrate_duplicate_index_spec.rb +0 -27
- data/spec/mysql/migrate/migrate_duplicate_table_spec.rb +0 -37
- data/spec/mysql/migrate/migrate_empty_spec.rb +0 -78
- data/spec/mysql/migrate/migrate_execute_spec.rb +0 -288
- data/spec/mysql/migrate/migrate_ignore_column_spec.rb +0 -98
- data/spec/mysql/migrate/migrate_ignore_index_spec.rb +0 -92
- data/spec/mysql/migrate/migrate_log_file_spec.rb +0 -125
- data/spec/mysql/migrate/migrate_merge_mode_spec.rb +0 -145
- data/spec/mysql/migrate/migrate_noop_spec.rb +0 -234
- data/spec/mysql/migrate/migrate_primary_key_spec.rb +0 -104
- data/spec/mysql/migrate/migrate_rename_column_spec.rb +0 -184
- data/spec/mysql/migrate/migrate_rename_table_spec.rb +0 -241
- data/spec/mysql/migrate/migrate_same_default_null_spec.rb +0 -77
- data/spec/mysql/migrate/migrate_same_spec.rb +0 -82
- data/spec/mysql/migrate/migrate_script_error_spec.rb +0 -91
- data/spec/mysql/migrate/migrate_skip_column_comment_change_spec.rb +0 -39
- data/spec/mysql/migrate/migrate_skip_drop_table_spec.rb +0 -145
- data/spec/mysql/migrate/migrate_skip_rename_column_spec.rb +0 -140
- data/spec/mysql/migrate/migrate_skip_rename_table_spec.rb +0 -141
- data/spec/mysql/migrate/migrate_with_ignore_tables_spec.rb +0 -307
- data/spec/mysql/migrate/migrate_with_pre_post_query_spec.rb +0 -153
- data/spec/mysql/migrate/migrate_with_tables_spec.rb +0 -149
- data/spec/mysql/migrate/migrate_with_verbose_log_spec.rb +0 -60
- data/spec/mysql/ridgepole_test_database.sql +0 -2
- data/spec/mysql/ridgepole_test_tables.sql +0 -79
- data/spec/mysql/ridgepole_test_tables_unknown_column_type.sql +0 -17
- data/spec/mysql/text_blob_types/text_blob_types_spec.rb +0 -131
- data/spec/mysql/~default_name_fk/migrate_change_fk_spec.rb +0 -59
- data/spec/mysql/~default_name_fk/migrate_create_fk_spec.rb +0 -133
- data/spec/mysql/~default_name_fk/migrate_drop_fk_spec.rb +0 -100
- data/spec/mysql/~dump_auto_increment/migrate_create_table_with_index_spec.rb +0 -43
- data/spec/mysql57/json/add_json_column_spec.rb +0 -35
- data/spec/mysql57/json/change_json_column_spec.rb +0 -102
- data/spec/mysql57/json/drop_json_column_spec.rb +0 -35
- data/spec/mysql57/virtual/add_virtual_column_spec.rb +0 -37
- data/spec/mysql57/virtual/change_virtual_column_spec.rb +0 -40
- data/spec/mysql57/virtual/drop_virtual_column_spec.rb +0 -37
- data/spec/postgresql/diff/diff_spec.rb +0 -216
- data/spec/postgresql/dump/dump_spec.rb +0 -69
- data/spec/postgresql/fk/migrate_change_fk_spec.rb +0 -115
- data/spec/postgresql/fk/migrate_create_fk_spec.rb +0 -176
- data/spec/postgresql/fk/migrate_drop_fk_spec.rb +0 -197
- data/spec/postgresql/migrate/migrate_add_column_spec.rb +0 -203
- data/spec/postgresql/migrate/migrate_add_expression_index_spec.rb +0 -25
- data/spec/postgresql/migrate/migrate_bigint_spec.rb +0 -53
- data/spec/postgresql/migrate/migrate_change_column_default_spec.rb +0 -38
- data/spec/postgresql/migrate/migrate_change_column_spec.rb +0 -185
- data/spec/postgresql/migrate/migrate_change_index_spec.rb +0 -164
- data/spec/postgresql/migrate/migrate_check_relation_column_type_spec.rb +0 -114
- data/spec/postgresql/migrate/migrate_create_table_spec.rb +0 -120
- data/spec/postgresql/migrate/migrate_create_table_with_default_proc_spec.rb +0 -112
- data/spec/postgresql/migrate/migrate_drop_column_spec.rb +0 -163
- data/spec/postgresql/migrate/migrate_drop_column_with_index_spec.rb +0 -166
- data/spec/postgresql/migrate/migrate_drop_expression_index_spec.rb +0 -59
- data/spec/postgresql/migrate/migrate_drop_index_spec.rb +0 -158
- data/spec/postgresql/migrate/migrate_drop_table_spec.rb +0 -122
- data/spec/postgresql/migrate/migrate_ext_cols_spec.rb +0 -64
- data/spec/postgresql/migrate/migrate_primary_key2_spec.rb +0 -73
- data/spec/postgresql/migrate/migrate_primary_key_spec.rb +0 -99
- data/spec/postgresql/migrate/migrate_references_spec.rb +0 -90
- data/spec/postgresql/migrate/migrate_rename_column_spec.rb +0 -155
- data/spec/postgresql/migrate/migrate_rename_table_spec.rb +0 -175
- data/spec/postgresql/migrate/migrate_same_spec.rb +0 -77
- data/spec/postgresql/ridgepole_test_database.sql +0 -16
- data/spec/postgresql/ridgepole_test_tables.sql +0 -75
- data/spec/postgresql/~default_name_fk/migrate_change_fk_spec.rb +0 -59
- data/spec/postgresql/~default_name_fk/migrate_create_fk_spec.rb +0 -134
- data/spec/postgresql/~default_name_fk/migrate_drop_fk_spec.rb +0 -100
- data/spec/processing_for_ci.rb +0 -13
- data/spec/spec_condition.rb +0 -58
- data/spec/spec_const.rb +0 -20
- data/spec/spec_helper.rb +0 -173
@@ -1,349 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
describe 'Ridgepole::Client#diff -> migrate' do
|
4
|
-
context 'when create fk' do
|
5
|
-
let(:actual_dsl) do
|
6
|
-
erbh(<<-ERB)
|
7
|
-
create_table "child", force: :cascade do |t|
|
8
|
-
t.integer "parent_id"
|
9
|
-
t.index ["parent_id"], name: "par_id"
|
10
|
-
end
|
11
|
-
|
12
|
-
create_table "parent", id: :integer, force: :cascade do |t|
|
13
|
-
end
|
14
|
-
ERB
|
15
|
-
end
|
16
|
-
|
17
|
-
let(:expected_dsl) do
|
18
|
-
erbh(actual_dsl + <<-ERB)
|
19
|
-
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
20
|
-
ERB
|
21
|
-
end
|
22
|
-
|
23
|
-
before { subject.diff(actual_dsl).migrate }
|
24
|
-
subject { client }
|
25
|
-
|
26
|
-
it {
|
27
|
-
delta = subject.diff(expected_dsl)
|
28
|
-
expect(delta.differ?).to be_truthy
|
29
|
-
expect(subject.dump).to match_ruby actual_dsl
|
30
|
-
delta.migrate
|
31
|
-
expect(subject.dump).to match_ruby expected_dsl
|
32
|
-
}
|
33
|
-
|
34
|
-
it {
|
35
|
-
delta = client(bulk_change: true).diff(expected_dsl)
|
36
|
-
expect(delta.differ?).to be_truthy
|
37
|
-
expect(subject.dump).to match_ruby actual_dsl
|
38
|
-
expect(delta.script).to match_fuzzy <<-RUBY
|
39
|
-
add_foreign_key("child", "parent", **{:name=>"child_ibfk_1"})
|
40
|
-
RUBY
|
41
|
-
delta.migrate
|
42
|
-
expect(subject.dump).to match_ruby expected_dsl
|
43
|
-
}
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'when create fk using `t.foreign_key`' do
|
47
|
-
let(:actual_dsl) do
|
48
|
-
erbh(<<-ERB)
|
49
|
-
create_table "child", force: :cascade do |t|
|
50
|
-
t.integer "parent_id"
|
51
|
-
t.index ["parent_id"], name: "par_id"
|
52
|
-
end
|
53
|
-
|
54
|
-
create_table "parent", id: :integer, force: :cascade do |t|
|
55
|
-
end
|
56
|
-
ERB
|
57
|
-
end
|
58
|
-
|
59
|
-
let(:expected_dsl) do
|
60
|
-
erbh(actual_dsl + <<-ERB)
|
61
|
-
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
62
|
-
ERB
|
63
|
-
end
|
64
|
-
|
65
|
-
let(:expected_dsl_using_t_foreign_key) do
|
66
|
-
erbh(<<-ERB)
|
67
|
-
create_table "child", force: :cascade do |t|
|
68
|
-
t.integer "parent_id"
|
69
|
-
t.index ["parent_id"], name: "par_id"
|
70
|
-
t.foreign_key "parent", name: "child_ibfk_1"
|
71
|
-
end
|
72
|
-
|
73
|
-
create_table "parent", id: :integer, force: :cascade do |t|
|
74
|
-
end
|
75
|
-
ERB
|
76
|
-
end
|
77
|
-
|
78
|
-
before { subject.diff(actual_dsl).migrate }
|
79
|
-
subject { client }
|
80
|
-
|
81
|
-
it {
|
82
|
-
delta = subject.diff(expected_dsl_using_t_foreign_key)
|
83
|
-
expect(delta.differ?).to be_truthy
|
84
|
-
expect(subject.dump).to match_ruby actual_dsl
|
85
|
-
delta.migrate
|
86
|
-
expect(subject.dump).to match_ruby expected_dsl
|
87
|
-
}
|
88
|
-
|
89
|
-
it {
|
90
|
-
delta = client(bulk_change: true).diff(expected_dsl_using_t_foreign_key)
|
91
|
-
expect(delta.differ?).to be_truthy
|
92
|
-
expect(subject.dump).to match_ruby actual_dsl
|
93
|
-
expect(delta.script).to match_fuzzy <<-RUBY
|
94
|
-
add_foreign_key("child", "parent", **{:name=>"child_ibfk_1"})
|
95
|
-
RUBY
|
96
|
-
delta.migrate
|
97
|
-
expect(subject.dump).to match_ruby expected_dsl
|
98
|
-
}
|
99
|
-
end
|
100
|
-
|
101
|
-
context 'when create fk when create table' do
|
102
|
-
let(:dsl) do
|
103
|
-
erbh(<<-ERB)
|
104
|
-
create_table "child", force: :cascade do |t|
|
105
|
-
t.integer "parent_id"
|
106
|
-
t.index ["parent_id"], name: "par_id"
|
107
|
-
end
|
108
|
-
|
109
|
-
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
110
|
-
|
111
|
-
create_table "parent", id: :integer, force: :cascade do |t|
|
112
|
-
end
|
113
|
-
ERB
|
114
|
-
end
|
115
|
-
|
116
|
-
let(:sorted_dsl) do
|
117
|
-
erbh(<<-ERB)
|
118
|
-
create_table "child", force: :cascade do |t|
|
119
|
-
t.integer "parent_id"
|
120
|
-
t.index ["parent_id"], name: "par_id"
|
121
|
-
end
|
122
|
-
|
123
|
-
create_table "parent", id: :integer, force: :cascade do |t|
|
124
|
-
end
|
125
|
-
|
126
|
-
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
127
|
-
ERB
|
128
|
-
end
|
129
|
-
|
130
|
-
subject { client }
|
131
|
-
|
132
|
-
it {
|
133
|
-
delta = subject.diff(dsl)
|
134
|
-
expect(delta.differ?).to be_truthy
|
135
|
-
expect(subject.dump).to match_fuzzy ''
|
136
|
-
delta.migrate
|
137
|
-
expect(subject.dump).to match_fuzzy sorted_dsl
|
138
|
-
}
|
139
|
-
end
|
140
|
-
|
141
|
-
context 'already defined' do
|
142
|
-
let(:dsl) do
|
143
|
-
erbh(<<-ERB)
|
144
|
-
create_table "child", force: :cascade do |t|
|
145
|
-
t.integer "parent_id", unsigned: true
|
146
|
-
t.index ["parent_id"], name: "par_id"
|
147
|
-
end
|
148
|
-
|
149
|
-
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
150
|
-
|
151
|
-
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
152
|
-
|
153
|
-
create_table "parent", id: :integer, force: :cascade do |t|
|
154
|
-
end
|
155
|
-
ERB
|
156
|
-
end
|
157
|
-
|
158
|
-
subject { client }
|
159
|
-
|
160
|
-
it {
|
161
|
-
expect do
|
162
|
-
subject.diff(dsl)
|
163
|
-
end.to raise_error('Foreign Key `child(child_ibfk_1)` already defined')
|
164
|
-
}
|
165
|
-
end
|
166
|
-
|
167
|
-
context 'when create fk without name' do
|
168
|
-
let(:actual_dsl) do
|
169
|
-
erbh(<<-ERB)
|
170
|
-
create_table "child", force: :cascade do |t|
|
171
|
-
t.integer "parent_id"
|
172
|
-
t.index ["parent_id"], name: "par_id"
|
173
|
-
end
|
174
|
-
|
175
|
-
create_table "parent", id: :integer, force: :cascade do |t|
|
176
|
-
end
|
177
|
-
ERB
|
178
|
-
end
|
179
|
-
|
180
|
-
let(:expected_dsl) do
|
181
|
-
erbh(actual_dsl + <<-ERB)
|
182
|
-
add_foreign_key "child", "parent"
|
183
|
-
ERB
|
184
|
-
end
|
185
|
-
|
186
|
-
before { subject.diff(actual_dsl).migrate }
|
187
|
-
subject { client }
|
188
|
-
|
189
|
-
it {
|
190
|
-
delta = subject.diff(expected_dsl)
|
191
|
-
expect(delta.differ?).to be_truthy
|
192
|
-
expect(subject.dump).to match_ruby actual_dsl
|
193
|
-
delta.migrate
|
194
|
-
expect(subject.dump).to match_ruby expected_dsl
|
195
|
-
}
|
196
|
-
|
197
|
-
it {
|
198
|
-
delta = client(bulk_change: true).diff(expected_dsl)
|
199
|
-
expect(delta.differ?).to be_truthy
|
200
|
-
expect(subject.dump).to match_ruby actual_dsl
|
201
|
-
expect(delta.script).to match_fuzzy <<-RUBY
|
202
|
-
add_foreign_key("child", "parent", **{})
|
203
|
-
RUBY
|
204
|
-
delta.migrate
|
205
|
-
expect(subject.dump).to match_ruby expected_dsl
|
206
|
-
}
|
207
|
-
end
|
208
|
-
|
209
|
-
context 'orphan fk' do
|
210
|
-
let(:dsl) do
|
211
|
-
erbh(<<-ERB)
|
212
|
-
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
213
|
-
|
214
|
-
create_table "parent", id: :integer, force: :cascade do |t|
|
215
|
-
end
|
216
|
-
ERB
|
217
|
-
end
|
218
|
-
|
219
|
-
subject { client }
|
220
|
-
|
221
|
-
it {
|
222
|
-
expect do
|
223
|
-
subject.diff(dsl)
|
224
|
-
end.to raise_error('Table `child` to create the foreign key is not defined: child_ibfk_1')
|
225
|
-
}
|
226
|
-
end
|
227
|
-
|
228
|
-
context 'when create fk without any indexes for its column' do
|
229
|
-
let(:dsl) do
|
230
|
-
erbh(<<-ERB)
|
231
|
-
create_table "parent", id: :integer, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
232
|
-
end
|
233
|
-
|
234
|
-
create_table "child", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
235
|
-
t.integer "parent_id"
|
236
|
-
end
|
237
|
-
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
238
|
-
ERB
|
239
|
-
end
|
240
|
-
|
241
|
-
subject { client(dump_without_table_options: false) }
|
242
|
-
|
243
|
-
it {
|
244
|
-
expect do
|
245
|
-
subject.diff(dsl).migrate
|
246
|
-
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.')
|
247
|
-
}
|
248
|
-
end
|
249
|
-
|
250
|
-
context 'when create fk with first key of multiple column indexes for its column' do
|
251
|
-
let(:dsl) do
|
252
|
-
erbh(<<-ERB)
|
253
|
-
create_table "parent", id: :integer, force: :cascade, <%= i cond('>= 6.1', { charset: 'utf8' }, { options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" }) %> do |t|
|
254
|
-
end
|
255
|
-
|
256
|
-
create_table "child", force: :cascade, <%= i cond('>= 6.1', { charset: 'utf8' }, { options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" }) %> do |t|
|
257
|
-
t.integer "parent_id"
|
258
|
-
t.string "name"
|
259
|
-
t.index ["parent_id", "name"], name: "par_id"
|
260
|
-
end
|
261
|
-
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
262
|
-
ERB
|
263
|
-
end
|
264
|
-
|
265
|
-
subject { client(dump_without_table_options: false) }
|
266
|
-
|
267
|
-
it {
|
268
|
-
expect(Ridgepole::Logger.instance).to_not receive(:warn)
|
269
|
-
subject.diff(dsl).migrate
|
270
|
-
|
271
|
-
expect(subject.diff(dsl).differ?).to be_falsey
|
272
|
-
}
|
273
|
-
end
|
274
|
-
|
275
|
-
context 'when create fk on the primary key' do
|
276
|
-
let(:dsl) do
|
277
|
-
erbh(<<-ERB)
|
278
|
-
create_table "users", force: :cascade, <%= i cond('>= 6.1', { charset: 'utf8' }, { options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" }) %> do |t|
|
279
|
-
end
|
280
|
-
|
281
|
-
create_table "icons", primary_key: "user_id", force: :cascade, <%= i cond('>= 6.1', { charset: 'utf8' }, { options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" }) %> do |t|
|
282
|
-
end
|
283
|
-
add_foreign_key "icons", "users", name: "fk_icons_users"
|
284
|
-
ERB
|
285
|
-
end
|
286
|
-
|
287
|
-
subject { client(dump_without_table_options: false) }
|
288
|
-
|
289
|
-
it {
|
290
|
-
expect(Ridgepole::Logger.instance).to_not receive(:warn)
|
291
|
-
subject.diff(dsl).migrate
|
292
|
-
|
293
|
-
expect(subject.diff(dsl).differ?).to be_falsey
|
294
|
-
}
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
context 'when create fk on the first primary key' do
|
299
|
-
let(:dsl) do
|
300
|
-
erbh(<<-ERB)
|
301
|
-
create_table "users", id: :integer, force: :cascade, <%= i cond('>= 6.1', { charset: 'utf8' }, { options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" }) %> do |t|
|
302
|
-
end
|
303
|
-
|
304
|
-
create_table "employee", id: :integer, force: :cascade, <%= i cond('>= 6.1', { charset: 'utf8' }, { options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" }) %> do |t|
|
305
|
-
end
|
306
|
-
|
307
|
-
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|
|
308
|
-
t.integer "user_id", null: false
|
309
|
-
t.integer "employee_id", null: false
|
310
|
-
end
|
311
|
-
add_foreign_key "icons", "users", name: "fk_icons_users"
|
312
|
-
ERB
|
313
|
-
end
|
314
|
-
|
315
|
-
subject { client(dump_without_table_options: false) }
|
316
|
-
|
317
|
-
it {
|
318
|
-
expect(Ridgepole::Logger.instance).to_not receive(:warn)
|
319
|
-
subject.diff(dsl).migrate
|
320
|
-
|
321
|
-
expect(subject.diff(dsl).differ?).to be_falsey
|
322
|
-
}
|
323
|
-
end
|
324
|
-
|
325
|
-
context 'when create fk on the second primary key' do
|
326
|
-
let(:dsl) do
|
327
|
-
erbh(<<-ERB)
|
328
|
-
create_table "users", id: :integer, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
329
|
-
end
|
330
|
-
|
331
|
-
create_table "employee", id: :integer, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
332
|
-
end
|
333
|
-
|
334
|
-
create_table "icons", primary_key: ["user_id", "employee_id"], force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
335
|
-
t.integer "user_id", null: false
|
336
|
-
t.integer "employee_id", null: false
|
337
|
-
end
|
338
|
-
add_foreign_key "icons", "employees", name: "fk_icons_employees"
|
339
|
-
ERB
|
340
|
-
end
|
341
|
-
|
342
|
-
subject { client(dump_without_table_options: false) }
|
343
|
-
|
344
|
-
it {
|
345
|
-
expect do
|
346
|
-
subject.diff(dsl).migrate
|
347
|
-
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.')
|
348
|
-
}
|
349
|
-
end
|
@@ -1,331 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
describe 'Ridgepole::Client#diff -> migrate' do
|
4
|
-
context 'when drop fk' do
|
5
|
-
let(:actual_dsl) do
|
6
|
-
erbh(<<-ERB)
|
7
|
-
create_table "parent", id: :integer, force: :cascade do |t|
|
8
|
-
end
|
9
|
-
|
10
|
-
create_table "child", force: :cascade do |t|
|
11
|
-
t.integer "parent_id"
|
12
|
-
t.index ["parent_id"], name: "par_id"
|
13
|
-
end
|
14
|
-
|
15
|
-
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
16
|
-
ERB
|
17
|
-
end
|
18
|
-
|
19
|
-
let(:sorted_actual_dsl) do
|
20
|
-
expected_dsl + <<-RUBY
|
21
|
-
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
22
|
-
RUBY
|
23
|
-
end
|
24
|
-
|
25
|
-
let(:expected_dsl) do
|
26
|
-
erbh(<<-ERB)
|
27
|
-
create_table "child", force: :cascade do |t|
|
28
|
-
t.integer "parent_id"
|
29
|
-
t.index ["parent_id"], name: "par_id"
|
30
|
-
end
|
31
|
-
|
32
|
-
create_table "parent", id: :integer, force: :cascade do |t|
|
33
|
-
end
|
34
|
-
ERB
|
35
|
-
end
|
36
|
-
|
37
|
-
before { subject.diff(actual_dsl).migrate }
|
38
|
-
subject { client }
|
39
|
-
|
40
|
-
it {
|
41
|
-
delta = subject.diff(expected_dsl)
|
42
|
-
expect(delta.differ?).to be_truthy
|
43
|
-
expect(subject.dump).to match_fuzzy sorted_actual_dsl
|
44
|
-
delta.migrate
|
45
|
-
expect(subject.dump).to match_ruby expected_dsl
|
46
|
-
}
|
47
|
-
|
48
|
-
it {
|
49
|
-
delta = client(bulk_change: true).diff(expected_dsl)
|
50
|
-
expect(delta.differ?).to be_truthy
|
51
|
-
expect(subject.dump).to match_fuzzy sorted_actual_dsl
|
52
|
-
expect(delta.script).to match_fuzzy <<-RUBY
|
53
|
-
remove_foreign_key("child", name: "child_ibfk_1")
|
54
|
-
RUBY
|
55
|
-
delta.migrate
|
56
|
-
expect(subject.dump).to match_ruby expected_dsl
|
57
|
-
}
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'when drop fk using `t.foreign_key`' do
|
61
|
-
let(:actual_dsl) do
|
62
|
-
erbh(<<-ERB)
|
63
|
-
create_table "parent", id: :integer, force: :cascade do |t|
|
64
|
-
end
|
65
|
-
|
66
|
-
create_table "child", force: :cascade do |t|
|
67
|
-
t.integer "parent_id"
|
68
|
-
t.index ["parent_id"], name: "par_id"
|
69
|
-
t.foreign_key "parent", name: "child_ibfk_1"
|
70
|
-
end
|
71
|
-
ERB
|
72
|
-
end
|
73
|
-
|
74
|
-
let(:sorted_actual_dsl) do
|
75
|
-
expected_dsl + <<-RUBY
|
76
|
-
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
77
|
-
RUBY
|
78
|
-
end
|
79
|
-
|
80
|
-
let(:expected_dsl) do
|
81
|
-
erbh(<<-ERB)
|
82
|
-
create_table "child", force: :cascade do |t|
|
83
|
-
t.integer "parent_id"
|
84
|
-
t.index ["parent_id"], name: "par_id"
|
85
|
-
end
|
86
|
-
|
87
|
-
create_table "parent", id: :integer, force: :cascade do |t|
|
88
|
-
end
|
89
|
-
ERB
|
90
|
-
end
|
91
|
-
|
92
|
-
before { subject.diff(actual_dsl).migrate }
|
93
|
-
subject { client }
|
94
|
-
|
95
|
-
it {
|
96
|
-
delta = subject.diff(expected_dsl)
|
97
|
-
expect(delta.differ?).to be_truthy
|
98
|
-
expect(subject.dump).to match_fuzzy sorted_actual_dsl
|
99
|
-
delta.migrate
|
100
|
-
expect(subject.dump).to match_ruby expected_dsl
|
101
|
-
}
|
102
|
-
|
103
|
-
it {
|
104
|
-
delta = client(bulk_change: true).diff(expected_dsl)
|
105
|
-
expect(delta.differ?).to be_truthy
|
106
|
-
expect(subject.dump).to match_fuzzy sorted_actual_dsl
|
107
|
-
expect(delta.script).to match_fuzzy <<-RUBY
|
108
|
-
remove_foreign_key("child", name: "child_ibfk_1")
|
109
|
-
RUBY
|
110
|
-
delta.migrate
|
111
|
-
expect(subject.dump).to match_ruby expected_dsl
|
112
|
-
}
|
113
|
-
end
|
114
|
-
|
115
|
-
context 'when drop fk when drop table' do
|
116
|
-
let(:dsl) do
|
117
|
-
erbh(<<-ERB)
|
118
|
-
create_table "users", id: :integer, force: :cascade do |t|
|
119
|
-
t.integer "invitation_id"
|
120
|
-
t.index ["invitation_id"], name: "idx_invitation_id"
|
121
|
-
end
|
122
|
-
|
123
|
-
add_foreign_key "users", "invitations", name: "users_ibfk"
|
124
|
-
|
125
|
-
create_table "invitations", id: :integer, force: :cascade do |t|
|
126
|
-
t.integer "user_id"
|
127
|
-
t.index ["user_id"], name: "idx_user_id"
|
128
|
-
end
|
129
|
-
|
130
|
-
add_foreign_key "invitations", "users", name: "invitations_ibfk"
|
131
|
-
ERB
|
132
|
-
end
|
133
|
-
|
134
|
-
let(:sorted_dsl) do
|
135
|
-
erbh(<<-ERB)
|
136
|
-
create_table "invitations", id: :integer, force: :cascade do |t|
|
137
|
-
t.integer "user_id"
|
138
|
-
t.index ["user_id"], name: "idx_user_id"
|
139
|
-
end
|
140
|
-
|
141
|
-
create_table "users", id: :integer, force: :cascade do |t|
|
142
|
-
t.integer "invitation_id"
|
143
|
-
t.index ["invitation_id"], name: "idx_invitation_id"
|
144
|
-
end
|
145
|
-
|
146
|
-
add_foreign_key "invitations", "users", name: "invitations_ibfk"
|
147
|
-
add_foreign_key "users", "invitations", name: "users_ibfk"
|
148
|
-
ERB
|
149
|
-
end
|
150
|
-
|
151
|
-
before { subject.diff(dsl).migrate }
|
152
|
-
subject { client }
|
153
|
-
|
154
|
-
it {
|
155
|
-
delta = subject.diff('')
|
156
|
-
expect(delta.differ?).to be_truthy
|
157
|
-
expect(subject.dump).to match_fuzzy sorted_dsl
|
158
|
-
delta.migrate
|
159
|
-
expect(subject.dump).to match_fuzzy ''
|
160
|
-
}
|
161
|
-
end
|
162
|
-
|
163
|
-
context 'when drop fk without name' do
|
164
|
-
let(:actual_dsl) do
|
165
|
-
erbh(<<-ERB)
|
166
|
-
create_table "parent", id: :integer, force: :cascade do |t|
|
167
|
-
end
|
168
|
-
|
169
|
-
create_table "child", force: :cascade do |t|
|
170
|
-
t.integer "parent_id"
|
171
|
-
t.index ["parent_id"], name: "par_id"
|
172
|
-
end
|
173
|
-
|
174
|
-
add_foreign_key "child", "parent"
|
175
|
-
ERB
|
176
|
-
end
|
177
|
-
|
178
|
-
let(:sorted_actual_dsl) do
|
179
|
-
expected_dsl + <<-RUBY
|
180
|
-
add_foreign_key "child", "parent"
|
181
|
-
RUBY
|
182
|
-
end
|
183
|
-
|
184
|
-
let(:expected_dsl) do
|
185
|
-
erbh(<<-ERB)
|
186
|
-
create_table "child", force: :cascade do |t|
|
187
|
-
t.integer "parent_id"
|
188
|
-
t.index ["parent_id"], name: "par_id"
|
189
|
-
end
|
190
|
-
|
191
|
-
create_table "parent", id: :integer, force: :cascade do |t|
|
192
|
-
end
|
193
|
-
ERB
|
194
|
-
end
|
195
|
-
|
196
|
-
before { subject.diff(actual_dsl).migrate }
|
197
|
-
subject { client }
|
198
|
-
|
199
|
-
it {
|
200
|
-
delta = subject.diff(expected_dsl)
|
201
|
-
expect(delta.differ?).to be_truthy
|
202
|
-
expect(subject.dump).to match_fuzzy sorted_actual_dsl
|
203
|
-
delta.migrate
|
204
|
-
expect(subject.dump).to match_ruby expected_dsl
|
205
|
-
}
|
206
|
-
|
207
|
-
it {
|
208
|
-
delta = client(bulk_change: true).diff(expected_dsl)
|
209
|
-
expect(delta.differ?).to be_truthy
|
210
|
-
expect(subject.dump).to match_fuzzy sorted_actual_dsl
|
211
|
-
expect(delta.script).to match_fuzzy <<-RUBY
|
212
|
-
remove_foreign_key("child", "parent")
|
213
|
-
RUBY
|
214
|
-
delta.migrate
|
215
|
-
expect(subject.dump).to match_ruby expected_dsl
|
216
|
-
}
|
217
|
-
end
|
218
|
-
|
219
|
-
context 'when drop fk when drop table without name' do
|
220
|
-
let(:dsl) do
|
221
|
-
erbh(<<-ERB)
|
222
|
-
create_table "parent", id: :integer, force: :cascade do |t|
|
223
|
-
end
|
224
|
-
|
225
|
-
create_table "child", force: :cascade do |t|
|
226
|
-
t.integer "parent_id"
|
227
|
-
t.index ["parent_id"], name: "par_id"
|
228
|
-
end
|
229
|
-
|
230
|
-
add_foreign_key "child", "parent"
|
231
|
-
ERB
|
232
|
-
end
|
233
|
-
|
234
|
-
let(:sorted_dsl) do
|
235
|
-
erbh(<<-ERB)
|
236
|
-
create_table "child", force: :cascade do |t|
|
237
|
-
t.integer "parent_id"
|
238
|
-
t.index ["parent_id"], name: "par_id"
|
239
|
-
end
|
240
|
-
|
241
|
-
create_table "parent", id: :integer, force: :cascade do |t|
|
242
|
-
end
|
243
|
-
|
244
|
-
add_foreign_key "child", "parent"
|
245
|
-
ERB
|
246
|
-
end
|
247
|
-
|
248
|
-
before { subject.diff(dsl).migrate }
|
249
|
-
subject { client }
|
250
|
-
|
251
|
-
it {
|
252
|
-
delta = subject.diff('')
|
253
|
-
expect(delta.differ?).to be_truthy
|
254
|
-
expect(subject.dump).to match_fuzzy sorted_dsl
|
255
|
-
delta.migrate
|
256
|
-
expect(subject.dump).to match_fuzzy ''
|
257
|
-
}
|
258
|
-
end
|
259
|
-
|
260
|
-
context 'when drop fk with parent table' do
|
261
|
-
let(:actual_dsl) do
|
262
|
-
erbh(<<-ERB)
|
263
|
-
create_table "child", force: :cascade do |t|
|
264
|
-
t.integer "parent_id"
|
265
|
-
t.index ["parent_id"], name: "par_id"
|
266
|
-
end
|
267
|
-
|
268
|
-
create_table "parent", id: :integer, force: :cascade do |t|
|
269
|
-
end
|
270
|
-
|
271
|
-
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
272
|
-
ERB
|
273
|
-
end
|
274
|
-
|
275
|
-
let(:expected_dsl) do
|
276
|
-
erbh(<<-ERB)
|
277
|
-
create_table "child", force: :cascade do |t|
|
278
|
-
t.integer "parent_id"
|
279
|
-
t.index ["parent_id"], name: "par_id"
|
280
|
-
end
|
281
|
-
ERB
|
282
|
-
end
|
283
|
-
|
284
|
-
before { subject.diff(actual_dsl).migrate }
|
285
|
-
subject { client }
|
286
|
-
|
287
|
-
it {
|
288
|
-
delta = subject.diff(expected_dsl)
|
289
|
-
expect(delta.differ?).to be_truthy
|
290
|
-
expect(subject.dump).to match_ruby actual_dsl
|
291
|
-
delta.migrate
|
292
|
-
expect(subject.dump).to match_ruby expected_dsl
|
293
|
-
}
|
294
|
-
end
|
295
|
-
|
296
|
-
context 'when drop fk with parent table without name' do
|
297
|
-
let(:actual_dsl) do
|
298
|
-
erbh(<<-ERB)
|
299
|
-
create_table "child", force: :cascade do |t|
|
300
|
-
t.integer "parent_id"
|
301
|
-
t.index ["parent_id"], name: "par_id"
|
302
|
-
end
|
303
|
-
|
304
|
-
create_table "parent", id: :integer, force: :cascade do |t|
|
305
|
-
end
|
306
|
-
|
307
|
-
add_foreign_key "child", "parent"
|
308
|
-
ERB
|
309
|
-
end
|
310
|
-
|
311
|
-
let(:expected_dsl) do
|
312
|
-
erbh(<<-ERB)
|
313
|
-
create_table "child", force: :cascade do |t|
|
314
|
-
t.integer "parent_id"
|
315
|
-
t.index ["parent_id"], name: "par_id"
|
316
|
-
end
|
317
|
-
ERB
|
318
|
-
end
|
319
|
-
|
320
|
-
before { subject.diff(actual_dsl).migrate }
|
321
|
-
subject { client }
|
322
|
-
|
323
|
-
it {
|
324
|
-
delta = subject.diff(expected_dsl)
|
325
|
-
expect(delta.differ?).to be_truthy
|
326
|
-
expect(subject.dump).to match_ruby actual_dsl
|
327
|
-
delta.migrate
|
328
|
-
expect(subject.dump).to match_ruby expected_dsl
|
329
|
-
}
|
330
|
-
end
|
331
|
-
end
|