ridgepole 0.6.4 → 0.6.5.beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +18 -8
- data/Appraisals +8 -0
- data/README.md +26 -2
- data/docker-compose.yml +12 -0
- data/gemfiles/activerecord_4.2.gemfile +8 -0
- data/gemfiles/activerecord_5.0.gemfile +7 -0
- data/lib/ridgepole/diff.rb +3 -1
- data/lib/ridgepole/version.rb +1 -1
- data/ridgepole.gemspec +6 -2
- data/spec/cli_helper.rb +63 -0
- data/spec/mysql/bigint_pk/bigint_pk_spec.rb +45 -0
- data/spec/mysql/cli/config_spec.rb +0 -2
- data/spec/mysql/cli/ridgepole_spec.rb +58 -56
- data/spec/mysql/collation/collation_spec.rb +134 -138
- data/spec/mysql/diff/diff2_spec.rb +1 -3
- data/spec/mysql/diff/diff_spec.rb +1 -3
- data/spec/mysql/dump/dump_class_method_spec.rb +29 -11
- data/spec/mysql/dump/dump_some_tables_spec.rb +18 -8
- data/spec/mysql/dump/dump_spec.rb +28 -10
- data/spec/mysql/dump/dump_without_table_options_spec.rb +29 -33
- data/spec/mysql/fk/migrate_change_fk_spec.rb +2 -4
- data/spec/mysql/fk/migrate_create_fk_spec.rb +39 -29
- data/spec/mysql/fk/migrate_drop_fk_spec.rb +20 -22
- data/spec/mysql/migrate/check_orphan_index_spec.rb +2 -4
- data/spec/mysql/migrate/migrate_add_column2_spec.rb +33 -26
- data/spec/mysql/migrate/migrate_add_column_spec.rb +32 -22
- data/spec/mysql/migrate/migrate_add_column_with_alter_extra_spec.rb +26 -16
- data/spec/mysql/migrate/migrate_add_column_with_script_spec.rb +27 -17
- data/spec/mysql/migrate/migrate_change_column2_spec.rb +26 -16
- data/spec/mysql/migrate/migrate_change_column3_spec.rb +54 -44
- data/spec/mysql/migrate/migrate_change_column4_spec.rb +8 -10
- data/spec/mysql/migrate/migrate_change_column5_spec.rb +32 -22
- data/spec/mysql/migrate/migrate_change_column6_spec.rb +28 -30
- data/spec/mysql/migrate/migrate_change_column_default_spec.rb +34 -36
- data/spec/mysql/migrate/migrate_change_column_float_spec.rb +10 -12
- data/spec/mysql/migrate/migrate_change_column_spec.rb +41 -29
- data/spec/mysql/migrate/migrate_change_index2_spec.rb +12 -14
- data/spec/mysql/migrate/migrate_change_index3_spec.rb +24 -26
- data/spec/mysql/migrate/migrate_change_index4_spec.rb +34 -24
- data/spec/mysql/migrate/migrate_change_index5_spec.rb +26 -16
- data/spec/mysql/migrate/migrate_change_index6_spec.rb +38 -28
- data/spec/mysql/migrate/migrate_change_index_spec.rb +39 -29
- data/spec/mysql/migrate/migrate_change_table_option_spec.rb +26 -13
- data/spec/mysql/migrate/migrate_create_index2_spec.rb +30 -20
- data/spec/mysql/migrate/migrate_create_index_spec.rb +28 -18
- data/spec/mysql/migrate/migrate_create_table_spec.rb +24 -14
- data/spec/mysql/migrate/migrate_create_table_with_options_spec.rb +4 -6
- data/spec/mysql/migrate/migrate_create_table_with_script_spec.rb +23 -13
- data/spec/mysql/migrate/migrate_drop_column_and_index2_spec.rb +32 -22
- data/spec/mysql/migrate/migrate_drop_column_and_index_spec.rb +35 -25
- data/spec/mysql/migrate/migrate_drop_column_spec.rb +36 -26
- data/spec/mysql/migrate/migrate_drop_index_spec.rb +28 -18
- data/spec/mysql/migrate/migrate_drop_table_spec.rb +29 -19
- data/spec/mysql/migrate/migrate_duplicate_index_spec.rb +2 -4
- data/spec/mysql/migrate/migrate_duplicate_table_spec.rb +2 -4
- data/spec/mysql/migrate/migrate_empty_spec.rb +24 -14
- data/spec/mysql/migrate/migrate_execute_spec.rb +78 -65
- data/spec/mysql/migrate/migrate_log_file_spec.rb +22 -12
- data/spec/mysql/migrate/migrate_merge_mode_spec.rb +31 -21
- data/spec/mysql/migrate/migrate_noop_spec.rb +55 -45
- data/spec/mysql/migrate/migrate_rename_column_spec.rb +38 -28
- data/spec/mysql/migrate/migrate_rename_table_spec.rb +43 -33
- data/spec/mysql/migrate/migrate_same_default_null_spec.rb +28 -18
- data/spec/mysql/migrate/migrate_same_spec.rb +26 -12
- data/spec/mysql/migrate/migrate_script_error_spec.rb +3 -5
- data/spec/mysql/migrate/migrate_skip_rename_column_spec.rb +30 -20
- data/spec/mysql/migrate/migrate_skip_rename_table_spec.rb +30 -20
- data/spec/mysql/migrate/migrate_with_ignore_tables_spec.rb +44 -46
- data/spec/mysql/migrate/migrate_with_pre_post_query_spec.rb +6 -8
- data/spec/mysql/migrate/migrate_with_tables_spec.rb +20 -22
- data/spec/mysql/migrate_/migrate_create_index_with_alter_spec.rb +22 -12
- data/spec/mysql/migrate_/migrate_drop_index_with_alter_spec.rb +22 -12
- data/spec/mysql/~default_name_fk/migrate_change_fk_spec.rb +8 -10
- data/spec/mysql/~default_name_fk/migrate_create_fk_spec.rb +39 -29
- data/spec/mysql/~default_name_fk/migrate_drop_fk_spec.rb +20 -22
- data/spec/postgresql/diff/diff_spec.rb +7 -9
- data/spec/postgresql/dump/dump_spec.rb +2 -4
- data/spec/postgresql/fk/migrate_change_fk_spec.rb +8 -10
- data/spec/postgresql/fk/migrate_create_fk_spec.rb +24 -26
- data/spec/postgresql/fk/migrate_drop_fk_spec.rb +21 -23
- data/spec/postgresql/migrate/migrate_add_column_spec.rb +19 -22
- data/spec/postgresql/migrate/migrate_change_column_default_spec.rb +6 -8
- data/spec/postgresql/migrate/migrate_change_column_spec.rb +17 -19
- data/spec/postgresql/migrate/migrate_change_index_spec.rb +11 -13
- data/spec/postgresql/migrate/migrate_create_table_spec.rb +6 -9
- data/spec/postgresql/migrate/migrate_drop_column_spec.rb +12 -14
- data/spec/postgresql/migrate/migrate_drop_column_with_index_spec.rb +12 -14
- data/spec/postgresql/migrate/migrate_drop_index_spec.rb +10 -12
- data/spec/postgresql/migrate/migrate_drop_table_spec.rb +7 -9
- data/spec/postgresql/migrate/migrate_ext_cols_spec.rb +6 -8
- data/spec/postgresql/migrate/migrate_rename_column_spec.rb +12 -14
- data/spec/postgresql/migrate/migrate_rename_table_spec.rb +14 -16
- data/spec/postgresql/migrate/migrate_same_spec.rb +4 -6
- data/spec/postgresql/~default_name_fk/migrate_change_fk_spec.rb +8 -10
- data/spec/postgresql/~default_name_fk/migrate_create_fk_spec.rb +24 -26
- data/spec/postgresql/~default_name_fk/migrate_drop_fk_spec.rb +20 -22
- data/spec/processing_for_travis.rb +9 -0
- data/spec/spec_condition.rb +24 -0
- data/spec/spec_const.rb +18 -0
- data/spec/spec_helper.rb +125 -196
- data/spec/string_ext.rb +0 -13
- metadata +106 -32
- data/spec/mysql/bigint_pk/bigint_pkspec.rb +0 -47
@@ -1,38 +1,52 @@
|
|
1
|
-
unless postgresql?
|
2
1
|
describe 'Ridgepole::Client#diff -> migrate' do
|
2
|
+
let(:template_variables) {
|
3
|
+
opts = {
|
4
|
+
unsigned: {},
|
5
|
+
sql_int_type: 'int(11)',
|
6
|
+
test_schema: TEST_SCHEMA,
|
7
|
+
}
|
8
|
+
|
9
|
+
if condition(:mysql_awesome_enabled)
|
10
|
+
opts[:unsigned] = {unsigned: true}
|
11
|
+
opts[:sql_int_type] = 'int(10) unsigned'
|
12
|
+
end
|
13
|
+
|
14
|
+
opts
|
15
|
+
}
|
16
|
+
|
3
17
|
context 'when execute' do
|
4
18
|
let(:dsl) {
|
5
|
-
<<-
|
6
|
-
create_table "authors"
|
19
|
+
erbh(<<-EOS, template_variables)
|
20
|
+
create_table "authors", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
|
7
21
|
t.string "name", limit: 255, null: false
|
8
22
|
end
|
9
23
|
|
10
|
-
create_table "books"
|
24
|
+
create_table "books", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
|
11
25
|
t.string "title", limit: 255, null: false
|
12
|
-
t.integer "author_id", limit: 4,
|
26
|
+
t.integer "author_id", <%= {limit: 4, null: false}.push(@unsigned).i %>
|
13
27
|
end
|
14
28
|
|
15
29
|
add_index "books", ["author_id"], name: "idx_author_id", using: :btree
|
16
|
-
|
30
|
+
EOS
|
17
31
|
}
|
18
32
|
|
19
33
|
let(:dsl_with_execute) {
|
20
|
-
<<-
|
34
|
+
erbh(<<-EOS, template_variables)
|
21
35
|
create_table "authors", force: :cascade do |t|
|
22
36
|
t.string "name", null: false
|
23
37
|
end
|
24
38
|
|
25
39
|
create_table "books", force: :cascade do |t|
|
26
40
|
t.string "title", null: false
|
27
|
-
t.integer "author_id", limit: 4,
|
41
|
+
t.integer "author_id", <%= {limit: 4, null: false}.push(@unsigned).i %>
|
28
42
|
end
|
29
43
|
|
30
44
|
add_index "books", ["author_id"], name: "idx_author_id", using: :btree
|
31
45
|
|
32
46
|
execute("ALTER TABLE books ADD CONSTRAINT fk_author FOREIGN KEY (author_id) REFERENCES authors (id)") do |c|
|
33
|
-
c.raw_connection.query("SELECT 1 FROM information_schema.key_column_usage WHERE TABLE_SCHEMA = '
|
47
|
+
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?
|
34
48
|
end
|
35
|
-
|
49
|
+
EOS
|
36
50
|
}
|
37
51
|
|
38
52
|
before { subject.diff(dsl).migrate }
|
@@ -41,40 +55,40 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
41
55
|
it {
|
42
56
|
delta = subject.diff(dsl_with_execute)
|
43
57
|
expect(delta.differ?).to be_truthy
|
44
|
-
expect(subject.dump
|
58
|
+
expect(subject.dump).to match_fuzzy dsl
|
45
59
|
|
46
|
-
expect(show_create_table(:books)
|
60
|
+
expect(show_create_table(:books)).to match_fuzzy erbh(<<-EOS, template_variables)
|
47
61
|
CREATE TABLE `books` (
|
48
|
-
`id`
|
62
|
+
`id` <%= @sql_int_type %> NOT NULL AUTO_INCREMENT,
|
49
63
|
`title` varchar(255) NOT NULL,
|
50
|
-
`author_id`
|
64
|
+
`author_id` <%= @sql_int_type %> NOT NULL,
|
51
65
|
PRIMARY KEY (`id`),
|
52
66
|
KEY `idx_author_id` (`author_id`) USING BTREE
|
53
67
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
54
|
-
|
68
|
+
EOS
|
55
69
|
|
56
70
|
delta.migrate
|
57
71
|
|
58
|
-
expect(subject.dump
|
72
|
+
expect(subject.dump).to match_fuzzy (dsl + (<<-EOS))
|
59
73
|
add_foreign_key "books", "authors", name: "fk_author"
|
60
|
-
|
74
|
+
EOS
|
61
75
|
|
62
|
-
expect(show_create_table(:books)
|
76
|
+
expect(show_create_table(:books)).to match_fuzzy erbh(<<-EOS, template_variables)
|
63
77
|
CREATE TABLE `books` (
|
64
|
-
`id`
|
78
|
+
`id` <%= @sql_int_type %> NOT NULL AUTO_INCREMENT,
|
65
79
|
`title` varchar(255) NOT NULL,
|
66
|
-
`author_id`
|
80
|
+
`author_id` <%= @sql_int_type %> NOT NULL,
|
67
81
|
PRIMARY KEY (`id`),
|
68
82
|
KEY `idx_author_id` (`author_id`) USING BTREE,
|
69
83
|
CONSTRAINT `fk_author` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`)
|
70
84
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
71
|
-
|
85
|
+
EOS
|
72
86
|
}
|
73
87
|
end
|
74
88
|
|
75
89
|
context 'when not execute' do
|
76
90
|
let(:dsl) {
|
77
|
-
<<-
|
91
|
+
<<-EOS
|
78
92
|
create_table "authors", force: :cascade do |t|
|
79
93
|
t.string "name", limit: 255, null: false
|
80
94
|
end
|
@@ -86,11 +100,11 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
86
100
|
|
87
101
|
add_index "books", ["author_id"], name: "idx_author_id", using: :btree
|
88
102
|
add_foreign_key "books", "authors", name: "fk_author"
|
89
|
-
|
103
|
+
EOS
|
90
104
|
}
|
91
105
|
|
92
106
|
let(:dsl_with_execute) {
|
93
|
-
<<-
|
107
|
+
erbh(<<-EOS, template_variables)
|
94
108
|
create_table "authors", force: :cascade do |t|
|
95
109
|
t.string "name", null: false
|
96
110
|
end
|
@@ -103,11 +117,11 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
103
117
|
add_index "books", ["author_id"], name: "idx_author_id", using: :btree
|
104
118
|
|
105
119
|
execute("ALTER TABLE books ADD CONSTRAINT fk_author FOREIGN KEY (author_id) REFERENCES authors (id)") do |c|
|
106
|
-
c.raw_connection.query("SELECT 1 FROM information_schema.key_column_usage WHERE TABLE_SCHEMA = '
|
120
|
+
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?
|
107
121
|
end
|
108
122
|
|
109
123
|
add_foreign_key "books", "authors", name: "fk_author"
|
110
|
-
|
124
|
+
EOS
|
111
125
|
}
|
112
126
|
|
113
127
|
before { subject.diff(dsl_with_execute).migrate }
|
@@ -116,9 +130,9 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
116
130
|
it {
|
117
131
|
delta = subject.diff(dsl_with_execute)
|
118
132
|
expect(delta.differ?).to be_truthy
|
119
|
-
expect(subject.dump
|
133
|
+
expect(subject.dump).to match_fuzzy dsl
|
120
134
|
|
121
|
-
expect(show_create_table(:books)
|
135
|
+
expect(show_create_table(:books)).to match_fuzzy erbh(<<-EOS, template_variables)
|
122
136
|
CREATE TABLE `books` (
|
123
137
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
124
138
|
`title` varchar(255) NOT NULL,
|
@@ -127,13 +141,13 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
127
141
|
KEY `idx_author_id` (`author_id`) USING BTREE,
|
128
142
|
CONSTRAINT `fk_author` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`)
|
129
143
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
130
|
-
|
144
|
+
EOS
|
131
145
|
|
132
146
|
migrated, out = delta.migrate
|
133
147
|
expect(migrated).to be_falsey
|
134
|
-
expect(subject.dump
|
148
|
+
expect(subject.dump).to match_fuzzy dsl
|
135
149
|
|
136
|
-
expect(show_create_table(:books)
|
150
|
+
expect(show_create_table(:books)).to match_fuzzy erbh(<<-EOS, template_variables)
|
137
151
|
CREATE TABLE `books` (
|
138
152
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
139
153
|
`title` varchar(255) NOT NULL,
|
@@ -142,43 +156,43 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
142
156
|
KEY `idx_author_id` (`author_id`) USING BTREE,
|
143
157
|
CONSTRAINT `fk_author` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`)
|
144
158
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
145
|
-
|
159
|
+
EOS
|
146
160
|
}
|
147
161
|
end
|
148
162
|
|
149
163
|
context 'when execute (noop)' do
|
150
164
|
let(:dsl) {
|
151
|
-
<<-
|
152
|
-
create_table "authors"
|
165
|
+
erbh(<<-EOS, template_variables)
|
166
|
+
create_table "authors", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
|
153
167
|
t.string "name", limit: 255, null: false
|
154
168
|
end
|
155
169
|
|
156
|
-
create_table "books"
|
170
|
+
create_table "books", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
|
157
171
|
t.string "title", limit: 255, null: false
|
158
|
-
t.integer "author_id", limit: 4,
|
172
|
+
t.integer "author_id", <%= {limit: 4, null: false}.push(@unsigned).i %>
|
159
173
|
end
|
160
174
|
|
161
175
|
add_index "books", ["author_id"], name: "idx_author_id", using: :btree
|
162
|
-
|
176
|
+
EOS
|
163
177
|
}
|
164
178
|
|
165
179
|
let(:dsl_with_execute) {
|
166
|
-
<<-
|
180
|
+
erbh(<<-EOS, template_variables)
|
167
181
|
create_table "authors", force: :cascade do |t|
|
168
182
|
t.string "name", null: false
|
169
183
|
end
|
170
184
|
|
171
185
|
create_table "books", force: :cascade do |t|
|
172
186
|
t.string "title", null: false
|
173
|
-
t.integer "author_id", limit: 4,
|
187
|
+
t.integer "author_id", <%= {limit: 4, null: false}.push(@unsigned).i %>
|
174
188
|
end
|
175
189
|
|
176
190
|
add_index "books", ["author_id"], name: "idx_author_id", using: :btree
|
177
191
|
|
178
192
|
execute("ALTER TABLE books ADD CONSTRAINT fk_author FOREIGN KEY (author_id) REFERENCES authors (id)") do |c|
|
179
|
-
c.raw_connection.query("SELECT 1 FROM information_schema.key_column_usage WHERE TABLE_SCHEMA = '
|
193
|
+
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?
|
180
194
|
end
|
181
|
-
|
195
|
+
EOS
|
182
196
|
}
|
183
197
|
|
184
198
|
before { subject.diff(dsl).migrate }
|
@@ -187,39 +201,39 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
187
201
|
it {
|
188
202
|
delta = subject.diff(dsl_with_execute)
|
189
203
|
expect(delta.differ?).to be_truthy
|
190
|
-
expect(subject.dump
|
204
|
+
expect(subject.dump).to match_fuzzy dsl
|
191
205
|
|
192
|
-
expect(show_create_table(:books)
|
206
|
+
expect(show_create_table(:books)).to match_fuzzy erbh(<<-EOS, template_variables)
|
193
207
|
CREATE TABLE `books` (
|
194
|
-
`id`
|
208
|
+
`id` <%= @sql_int_type %> NOT NULL AUTO_INCREMENT,
|
195
209
|
`title` varchar(255) NOT NULL,
|
196
|
-
`author_id`
|
210
|
+
`author_id` <%= @sql_int_type %> NOT NULL,
|
197
211
|
PRIMARY KEY (`id`),
|
198
212
|
KEY `idx_author_id` (`author_id`) USING BTREE
|
199
213
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
200
|
-
|
214
|
+
EOS
|
201
215
|
|
202
216
|
migrated, sql = delta.migrate(:noop => true)
|
203
217
|
expect(migrated).to be_truthy
|
204
|
-
expect(subject.dump
|
218
|
+
expect(subject.dump).to match_fuzzy dsl
|
205
219
|
|
206
|
-
expect(sql
|
220
|
+
expect(sql).to match_fuzzy "ALTER TABLE books ADD CONSTRAINT fk_author FOREIGN KEY (author_id) REFERENCES authors (id)"
|
207
221
|
|
208
|
-
expect(show_create_table(:books)
|
222
|
+
expect(show_create_table(:books)).to match_fuzzy erbh(<<-EOS, template_variables)
|
209
223
|
CREATE TABLE `books` (
|
210
|
-
`id`
|
224
|
+
`id` <%= @sql_int_type %> NOT NULL AUTO_INCREMENT,
|
211
225
|
`title` varchar(255) NOT NULL,
|
212
|
-
`author_id`
|
226
|
+
`author_id` <%= @sql_int_type %> NOT NULL,
|
213
227
|
PRIMARY KEY (`id`),
|
214
228
|
KEY `idx_author_id` (`author_id`) USING BTREE
|
215
229
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
216
|
-
|
230
|
+
EOS
|
217
231
|
}
|
218
232
|
end
|
219
233
|
|
220
234
|
context 'when not execute (noop)' do
|
221
235
|
let(:dsl) {
|
222
|
-
<<-
|
236
|
+
<<-EOS
|
223
237
|
create_table "authors", force: :cascade do |t|
|
224
238
|
t.string "name", limit: 255, null: false
|
225
239
|
end
|
@@ -231,11 +245,11 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
231
245
|
|
232
246
|
add_index "books", ["author_id"], name: "idx_author_id", using: :btree
|
233
247
|
add_foreign_key "books", "authors", name: "fk_author"
|
234
|
-
|
248
|
+
EOS
|
235
249
|
}
|
236
250
|
|
237
251
|
let(:dsl_with_execute) {
|
238
|
-
<<-
|
252
|
+
erbh(<<-EOS, template_variables)
|
239
253
|
create_table "authors", force: :cascade do |t|
|
240
254
|
t.string "name", null: false
|
241
255
|
end
|
@@ -248,11 +262,11 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
248
262
|
add_index "books", ["author_id"], name: "idx_author_id", using: :btree
|
249
263
|
|
250
264
|
execute("ALTER TABLE books ADD CONSTRAINT fk_author FOREIGN KEY (author_id) REFERENCES authors (id)") do |c|
|
251
|
-
c.raw_connection.query("SELECT 1 FROM information_schema.key_column_usage WHERE TABLE_SCHEMA = '
|
265
|
+
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?
|
252
266
|
end
|
253
267
|
|
254
268
|
add_foreign_key "books", "authors", name: "fk_author"
|
255
|
-
|
269
|
+
EOS
|
256
270
|
}
|
257
271
|
|
258
272
|
before { subject.diff(dsl_with_execute).migrate }
|
@@ -261,9 +275,9 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
261
275
|
it {
|
262
276
|
delta = subject.diff(dsl_with_execute)
|
263
277
|
expect(delta.differ?).to be_truthy
|
264
|
-
expect(subject.dump
|
278
|
+
expect(subject.dump).to match_fuzzy dsl
|
265
279
|
|
266
|
-
expect(show_create_table(:books)
|
280
|
+
expect(show_create_table(:books)).to match_fuzzy erbh(<<-EOS, template_variables)
|
267
281
|
CREATE TABLE `books` (
|
268
282
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
269
283
|
`title` varchar(255) NOT NULL,
|
@@ -272,15 +286,15 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
272
286
|
KEY `idx_author_id` (`author_id`) USING BTREE,
|
273
287
|
CONSTRAINT `fk_author` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`)
|
274
288
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
275
|
-
|
289
|
+
EOS
|
276
290
|
|
277
291
|
migrated, sql = delta.migrate(:noop => true)
|
278
292
|
expect(migrated).to be_falsey
|
279
|
-
expect(subject.dump
|
293
|
+
expect(subject.dump).to match_fuzzy dsl
|
280
294
|
|
281
|
-
expect(sql
|
295
|
+
expect(sql).to match_fuzzy ""
|
282
296
|
|
283
|
-
expect(show_create_table(:books)
|
297
|
+
expect(show_create_table(:books)).to match_fuzzy erbh(<<-EOS, template_variables)
|
284
298
|
CREATE TABLE `books` (
|
285
299
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
286
300
|
`title` varchar(255) NOT NULL,
|
@@ -289,8 +303,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
289
303
|
KEY `idx_author_id` (`author_id`) USING BTREE,
|
290
304
|
CONSTRAINT `fk_author` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`)
|
291
305
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8
|
292
|
-
|
306
|
+
EOS
|
293
307
|
}
|
294
308
|
end
|
295
309
|
end
|
296
|
-
end
|
@@ -1,15 +1,26 @@
|
|
1
|
-
unless postgresql?
|
2
1
|
describe 'Ridgepole::Client#diff -> migrate' do
|
2
|
+
let(:template_variables) {
|
3
|
+
opts = {
|
4
|
+
unsigned: {}
|
5
|
+
}
|
6
|
+
|
7
|
+
if condition(:mysql_awesome_enabled)
|
8
|
+
opts[:unsigned] = {unsigned: true}
|
9
|
+
end
|
10
|
+
|
11
|
+
opts
|
12
|
+
}
|
13
|
+
|
3
14
|
context 'when create table' do
|
4
15
|
let(:dsl) {
|
5
|
-
<<-
|
6
|
-
create_table "clubs"
|
16
|
+
erbh(<<-EOS, template_variables)
|
17
|
+
create_table "clubs", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
|
7
18
|
t.string "name", limit: 255, default: "", null: false
|
8
19
|
end
|
9
20
|
|
10
21
|
add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree
|
11
22
|
|
12
|
-
create_table "departments", primary_key: "dept_no"
|
23
|
+
create_table "departments", primary_key: "dept_no", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
|
13
24
|
t.string "dept_name", limit: 40, null: false
|
14
25
|
end
|
15
26
|
|
@@ -35,14 +46,14 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
35
46
|
add_index "dept_manager", ["dept_no"], name: "dept_no", using: :btree
|
36
47
|
add_index "dept_manager", ["emp_no"], name: "emp_no", using: :btree
|
37
48
|
|
38
|
-
create_table "employee_clubs"
|
39
|
-
t.integer "emp_no", limit: 4, null: false
|
40
|
-
t.integer "club_id", limit: 4, null: false
|
49
|
+
create_table "employee_clubs", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
|
50
|
+
t.integer "emp_no", <%= {limit: 4, null: false}.push(@unsigned).i %>
|
51
|
+
t.integer "club_id", <%= {limit: 4, null: false}.push(@unsigned).i %>
|
41
52
|
end
|
42
53
|
|
43
54
|
add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_emp_no_club_id", using: :btree
|
44
55
|
|
45
|
-
create_table "employees", primary_key: "emp_no"
|
56
|
+
create_table "employees", primary_key: "emp_no", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
|
46
57
|
t.date "birth_date", null: false
|
47
58
|
t.string "first_name", limit: 14, null: false
|
48
59
|
t.string "last_name", limit: 16, null: false
|
@@ -67,7 +78,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
67
78
|
end
|
68
79
|
|
69
80
|
add_index "titles", ["emp_no"], name: "emp_no", using: :btree
|
70
|
-
|
81
|
+
EOS
|
71
82
|
}
|
72
83
|
|
73
84
|
let(:actual_dsl) {
|
@@ -84,12 +95,11 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
84
95
|
tempfile("#{File.basename __FILE__}.#{$$}") do |path|
|
85
96
|
delta = client(log_file: path).diff(expected_dsl)
|
86
97
|
expect(delta.differ?).to be_truthy
|
87
|
-
expect(client.dump
|
98
|
+
expect(client.dump).to match_fuzzy actual_dsl
|
88
99
|
delta.migrate
|
89
|
-
expect(client.dump
|
100
|
+
expect(client.dump).to match_fuzzy expected_dsl
|
90
101
|
expect(File.size(path)).to be > 0
|
91
102
|
end
|
92
103
|
}
|
93
104
|
end
|
94
105
|
end
|
95
|
-
end
|
@@ -1,15 +1,26 @@
|
|
1
|
-
unless postgresql?
|
2
1
|
describe 'Ridgepole::Client#diff -> migrate' do
|
2
|
+
let(:template_variables) {
|
3
|
+
opts = {
|
4
|
+
unsigned: {}
|
5
|
+
}
|
6
|
+
|
7
|
+
if condition(:mysql_awesome_enabled)
|
8
|
+
opts[:unsigned] = {unsigned: true}
|
9
|
+
end
|
10
|
+
|
11
|
+
opts
|
12
|
+
}
|
13
|
+
|
3
14
|
context 'when marge table' do
|
4
15
|
let(:actual_dsl) {
|
5
|
-
<<-
|
6
|
-
create_table "clubs"
|
16
|
+
erbh(<<-EOS, template_variables)
|
17
|
+
create_table "clubs", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
|
7
18
|
t.string "name", limit: 255, default: "", null: false
|
8
19
|
end
|
9
20
|
|
10
21
|
add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree
|
11
22
|
|
12
|
-
create_table "departments", primary_key: "dept_no"
|
23
|
+
create_table "departments", primary_key: "dept_no", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
|
13
24
|
t.string "dept_name", limit: 40, null: false
|
14
25
|
end
|
15
26
|
|
@@ -35,14 +46,14 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
35
46
|
add_index "dept_manager", ["dept_no"], name: "dept_no", using: :btree
|
36
47
|
add_index "dept_manager", ["emp_no"], name: "emp_no", using: :btree
|
37
48
|
|
38
|
-
create_table "employee_clubs"
|
39
|
-
t.integer "emp_no", limit: 4, null: false
|
40
|
-
t.integer "club_id", limit: 4, null: false
|
49
|
+
create_table "employee_clubs", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
|
50
|
+
t.integer "emp_no", <%= {limit: 4, null: false}.push(@unsigned).i %>
|
51
|
+
t.integer "club_id", <%= {limit: 4, null: false}.push(@unsigned).i %>
|
41
52
|
end
|
42
53
|
|
43
54
|
add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_emp_no_club_id", using: :btree
|
44
55
|
|
45
|
-
create_table "employees", primary_key: "emp_no"
|
56
|
+
create_table "employees", primary_key: "emp_no", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
|
46
57
|
t.date "birth_date", null: false
|
47
58
|
t.string "first_name", limit: 14, null: false
|
48
59
|
t.string "last_name", limit: 16, null: false
|
@@ -67,22 +78,22 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
67
78
|
end
|
68
79
|
|
69
80
|
add_index "titles", ["emp_no"], name: "emp_no", using: :btree
|
70
|
-
|
81
|
+
EOS
|
71
82
|
}
|
72
83
|
|
73
84
|
let(:expected_dsl) {
|
74
|
-
<<-
|
75
|
-
create_table "clubs"
|
85
|
+
erbh(<<-EOS, template_variables)
|
86
|
+
create_table "clubs", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
|
76
87
|
t.string "name", limit: 255, default: "", null: false
|
77
88
|
end
|
78
89
|
|
79
90
|
add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree
|
80
91
|
|
81
|
-
create_table "clubs2"
|
92
|
+
create_table "clubs2", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
|
82
93
|
t.string "name2", limit: 255, default: "", null: false
|
83
94
|
end
|
84
95
|
|
85
|
-
create_table "departments", primary_key: "dept_no"
|
96
|
+
create_table "departments", primary_key: "dept_no", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
|
86
97
|
t.string "dept_name", limit: 40, null: false
|
87
98
|
end
|
88
99
|
|
@@ -108,14 +119,14 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
108
119
|
add_index "dept_manager", ["dept_no"], name: "dept_no", using: :btree
|
109
120
|
add_index "dept_manager", ["emp_no"], name: "emp_no", using: :btree
|
110
121
|
|
111
|
-
create_table "employee_clubs"
|
112
|
-
t.integer "emp_no", limit: 4, null: false
|
113
|
-
t.integer "club_id", limit: 4, null: false
|
122
|
+
create_table "employee_clubs", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
|
123
|
+
t.integer "emp_no", <%= {limit: 4, null: false}.push(@unsigned).i %>
|
124
|
+
t.integer "club_id", <%= {limit: 4, null: false}.push(@unsigned).i %>
|
114
125
|
end
|
115
126
|
|
116
127
|
add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_emp_no_club_id", using: :btree
|
117
128
|
|
118
|
-
create_table "employees", primary_key: "emp_no"
|
129
|
+
create_table "employees", primary_key: "emp_no", <%= {force: :cascade}.unshift(@unsigned).i %> do |t|
|
119
130
|
t.date "birth_date", null: false
|
120
131
|
t.string "first_name", limit: 14, null: false
|
121
132
|
t.string "last_name", limit: 16, null: false
|
@@ -140,7 +151,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
140
151
|
end
|
141
152
|
|
142
153
|
add_index "titles", ["emp_no"], name: "emp_no", using: :btree
|
143
|
-
|
154
|
+
EOS
|
144
155
|
}
|
145
156
|
|
146
157
|
before { subject.diff(actual_dsl).migrate }
|
@@ -149,10 +160,10 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
149
160
|
it {
|
150
161
|
delta = subject.diff(expected_dsl.delete_create_table('clubs'))
|
151
162
|
expect(delta.differ?).to be_truthy
|
152
|
-
expect(subject.dump).to
|
163
|
+
expect(subject.dump).to match_fuzzy actual_dsl
|
153
164
|
delta.migrate
|
154
165
|
# `clubs` table is not deleted
|
155
|
-
expect(subject.dump).to
|
166
|
+
expect(subject.dump).to match_fuzzy expected_dsl
|
156
167
|
}
|
157
168
|
|
158
169
|
it {
|
@@ -161,4 +172,3 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
161
172
|
}
|
162
173
|
end
|
163
174
|
end
|
164
|
-
end
|