ridgepole 0.7.0.beta → 0.7.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -3
- data/lib/ridgepole/delta.rb +19 -13
- data/lib/ridgepole/version.rb +1 -1
- data/spec/mysql/fk/migrate_change_fk_spec.rb +82 -0
- data/spec/mysql/fk/migrate_drop_fk_spec.rb +72 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2de5f94990fb6c37ed124d73e965aefb87b65bf8
|
4
|
+
data.tar.gz: ed39dba231ba693c1631ea4d94f5d321004773ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4909ca73aee2594f904db3fa9dba647f812746265f88e875f951733636c9fdb9a5dc8b2ad694774e30d51e1fea9701afe220e21a1a3766a03e76ddc797dd4af6
|
7
|
+
data.tar.gz: 1861b9094313e0e668687f27ab5854798a97db35136cd10c8d0ab9cd88397940d01fb333f0cebe421c6d1e2405d7b6a5028a8aa4cb0071c2a5ccfa2c91fd010b
|
data/README.md
CHANGED
@@ -6,9 +6,11 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
|
|
6
6
|
(like Chef/Puppet)
|
7
7
|
|
8
8
|
[![Gem Version](https://badge.fury.io/rb/ridgepole.svg)](http://badge.fury.io/rb/ridgepole)
|
9
|
-
[![
|
10
|
-
[![
|
11
|
-
[![
|
9
|
+
[![Build Status](https://travis-ci.org/winebarrel/ridgepole.svg?branch=0.6)](https://travis-ci.org/winebarrel/ridgepole)
|
10
|
+
[![Coverage Status](https://coveralls.io/repos/github/winebarrel/ridgepole/badge.svg?branch=0.6)](https://coveralls.io/github/winebarrel/ridgepole?branch=0.6)
|
11
|
+
[![Edge Version](https://img.shields.io/badge/edge%20version-0.7.0.beta-green.svg)](https://rubygems.org/gems/ridgepole/versions/0.7.0.beta2)
|
12
|
+
[![Build Status](https://travis-ci.org/winebarrel/ridgepole.svg?branch=0.7)](https://travis-ci.org/winebarrel/ridgepole)
|
13
|
+
[![Coverage Status](https://coveralls.io/repos/github/winebarrel/ridgepole/badge.svg?branch=0.7)](https://coveralls.io/github/winebarrel/ridgepole?branch=0.7)
|
12
14
|
|
13
15
|
**Notice**
|
14
16
|
|
@@ -71,6 +73,7 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
|
|
71
73
|
* Support MySQL JSON Type and Generated Columns
|
72
74
|
* Add `--mysql-change-table-options` option
|
73
75
|
* Pass config from env
|
76
|
+
* Fix change fk order
|
74
77
|
|
75
78
|
## Installation
|
76
79
|
|
data/lib/ridgepole/delta.rb
CHANGED
@@ -22,10 +22,11 @@ class Ridgepole::Delta
|
|
22
22
|
|
23
23
|
def script
|
24
24
|
buf = StringIO.new
|
25
|
-
|
25
|
+
pre_buf_for_fk = StringIO.new
|
26
|
+
post_buf_for_fk = StringIO.new
|
26
27
|
|
27
28
|
(@delta[:add] || {}).each do |table_name, attrs|
|
28
|
-
append_create_table(table_name, attrs, buf,
|
29
|
+
append_create_table(table_name, attrs, buf, post_buf_for_fk)
|
29
30
|
end
|
30
31
|
|
31
32
|
(@delta[:rename] || {}).each do |table_name, attrs|
|
@@ -33,14 +34,18 @@ class Ridgepole::Delta
|
|
33
34
|
end
|
34
35
|
|
35
36
|
(@delta[:change] || {}).each do |table_name, attrs|
|
36
|
-
append_change(table_name, attrs, buf,
|
37
|
+
append_change(table_name, attrs, buf, pre_buf_for_fk, post_buf_for_fk)
|
37
38
|
end
|
38
39
|
|
39
40
|
(@delta[:delete] || {}).each do |table_name, attrs|
|
40
41
|
append_drop_table(table_name, attrs, buf)
|
41
42
|
end
|
42
43
|
|
43
|
-
|
44
|
+
[
|
45
|
+
pre_buf_for_fk,
|
46
|
+
buf,
|
47
|
+
post_buf_for_fk,
|
48
|
+
].map {|b| b.string.strip }.join("\n\n").strip
|
44
49
|
end
|
45
50
|
|
46
51
|
def differ?
|
@@ -211,7 +216,7 @@ class Ridgepole::Delta
|
|
211
216
|
end
|
212
217
|
end
|
213
218
|
|
214
|
-
def append_create_table(table_name, attrs, buf,
|
219
|
+
def append_create_table(table_name, attrs, buf, post_buf_for_fk)
|
215
220
|
options = attrs[:options] || {}
|
216
221
|
options[:options] ||= @options[:table_options] if @options[:table_options]
|
217
222
|
definition = attrs[:definition] || {}
|
@@ -245,12 +250,12 @@ end
|
|
245
250
|
|
246
251
|
unless (foreign_keys = attrs[:foreign_keys] || {}).empty?
|
247
252
|
foreign_keys.each do |_, foreign_key_attrs|
|
248
|
-
append_add_foreign_key(table_name, foreign_key_attrs,
|
253
|
+
append_add_foreign_key(table_name, foreign_key_attrs, post_buf_for_fk, @options)
|
249
254
|
end
|
250
255
|
end
|
251
256
|
|
252
257
|
buf.puts
|
253
|
-
|
258
|
+
post_buf_for_fk.puts
|
254
259
|
end
|
255
260
|
|
256
261
|
def append_rename_table(to_table_name, from_table_name, buf)
|
@@ -278,7 +283,7 @@ execute "ALTER TABLE #{ActiveRecord::Base.connection.quote_table_name(table_name
|
|
278
283
|
buf.puts
|
279
284
|
end
|
280
285
|
|
281
|
-
def append_change(table_name, attrs, buf,
|
286
|
+
def append_change(table_name, attrs, buf, pre_buf_for_fk, post_buf_for_fk)
|
282
287
|
definition = attrs[:definition] || {}
|
283
288
|
indices = attrs[:indices] || {}
|
284
289
|
foreign_keys = attrs[:foreign_keys] || {}
|
@@ -292,7 +297,7 @@ execute "ALTER TABLE #{ActiveRecord::Base.connection.quote_table_name(table_name
|
|
292
297
|
end
|
293
298
|
|
294
299
|
unless foreign_keys.empty?
|
295
|
-
append_change_foreign_keys(table_name, foreign_keys,
|
300
|
+
append_change_foreign_keys(table_name, foreign_keys, pre_buf_for_fk, post_buf_for_fk, @options)
|
296
301
|
end
|
297
302
|
|
298
303
|
if table_options
|
@@ -300,7 +305,8 @@ execute "ALTER TABLE #{ActiveRecord::Base.connection.quote_table_name(table_name
|
|
300
305
|
end
|
301
306
|
|
302
307
|
buf.puts
|
303
|
-
|
308
|
+
pre_buf_for_fk.puts
|
309
|
+
post_buf_for_fk.puts
|
304
310
|
end
|
305
311
|
|
306
312
|
def append_change_table(table_name, buf)
|
@@ -428,13 +434,13 @@ remove_index(#{table_name.inspect}, #{target.inspect})
|
|
428
434
|
end
|
429
435
|
end
|
430
436
|
|
431
|
-
def append_change_foreign_keys(table_name, delta,
|
437
|
+
def append_change_foreign_keys(table_name, delta, pre_buf_for_fk, post_buf_for_fk, options)
|
432
438
|
(delta[:delete] || {}).each do |_, attrs|
|
433
|
-
append_remove_foreign_key(table_name, attrs,
|
439
|
+
append_remove_foreign_key(table_name, attrs, pre_buf_for_fk, options)
|
434
440
|
end
|
435
441
|
|
436
442
|
(delta[:add] || {}).each do |_, attrs|
|
437
|
-
append_add_foreign_key(table_name, attrs,
|
443
|
+
append_add_foreign_key(table_name, attrs, post_buf_for_fk, options)
|
438
444
|
end
|
439
445
|
end
|
440
446
|
|
data/lib/ridgepole/version.rb
CHANGED
@@ -110,4 +110,86 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
110
110
|
expect(subject.dump).to match_fuzzy expected_dsl
|
111
111
|
}
|
112
112
|
end
|
113
|
+
|
114
|
+
context 'when drop/add fk with parent table' do
|
115
|
+
let(:actual_dsl) {
|
116
|
+
erbh(<<-EOS)
|
117
|
+
create_table "child", force: :cascade do |t|
|
118
|
+
t.integer "parent_id"
|
119
|
+
t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
|
120
|
+
end
|
121
|
+
|
122
|
+
create_table "parent", <%= i cond(5.1, id: :integer) %>, force: :cascade do |t|
|
123
|
+
end
|
124
|
+
|
125
|
+
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
126
|
+
EOS
|
127
|
+
}
|
128
|
+
|
129
|
+
let(:expected_dsl) {
|
130
|
+
erbh(<<-EOS)
|
131
|
+
create_table "child", force: :cascade do |t|
|
132
|
+
t.integer "parent2_id"
|
133
|
+
t.index ["parent2_id"], name: "par2_id", <%= i cond(5.0, using: :btree) %>
|
134
|
+
end
|
135
|
+
|
136
|
+
create_table "parent2", <%= i cond(5.1, id: :integer) %>, force: :cascade do |t|
|
137
|
+
end
|
138
|
+
|
139
|
+
add_foreign_key "child", "parent2", name: "child_ibfk_2"
|
140
|
+
EOS
|
141
|
+
}
|
142
|
+
|
143
|
+
before { subject.diff(actual_dsl).migrate }
|
144
|
+
subject { client }
|
145
|
+
|
146
|
+
it {
|
147
|
+
delta = subject.diff(expected_dsl)
|
148
|
+
expect(delta.differ?).to be_truthy
|
149
|
+
expect(subject.dump).to match_fuzzy actual_dsl
|
150
|
+
delta.migrate
|
151
|
+
expect(subject.dump).to match_fuzzy expected_dsl
|
152
|
+
}
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'when drop/add fk with parent table without name' do
|
156
|
+
let(:actual_dsl) {
|
157
|
+
erbh(<<-EOS)
|
158
|
+
create_table "child", force: :cascade do |t|
|
159
|
+
t.integer "parent_id"
|
160
|
+
t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
|
161
|
+
end
|
162
|
+
|
163
|
+
create_table "parent", <%= i cond(5.1, id: :integer) %>, force: :cascade do |t|
|
164
|
+
end
|
165
|
+
|
166
|
+
add_foreign_key "child", "parent"
|
167
|
+
EOS
|
168
|
+
}
|
169
|
+
|
170
|
+
let(:expected_dsl) {
|
171
|
+
erbh(<<-EOS)
|
172
|
+
create_table "child", force: :cascade do |t|
|
173
|
+
t.integer "parent2_id"
|
174
|
+
t.index ["parent2_id"], name: "par2_id", <%= i cond(5.0, using: :btree) %>
|
175
|
+
end
|
176
|
+
|
177
|
+
create_table "parent2", <%= i cond(5.1, id: :integer) %>, force: :cascade do |t|
|
178
|
+
end
|
179
|
+
|
180
|
+
add_foreign_key "child", "parent2"
|
181
|
+
EOS
|
182
|
+
}
|
183
|
+
|
184
|
+
before { subject.diff(actual_dsl).migrate }
|
185
|
+
subject { client }
|
186
|
+
|
187
|
+
it {
|
188
|
+
delta = subject.diff(expected_dsl)
|
189
|
+
expect(delta.differ?).to be_truthy
|
190
|
+
expect(subject.dump).to match_fuzzy actual_dsl
|
191
|
+
delta.migrate
|
192
|
+
expect(subject.dump).to match_fuzzy expected_dsl
|
193
|
+
}
|
194
|
+
end
|
113
195
|
end
|
@@ -208,4 +208,76 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
208
208
|
expect(subject.dump).to match_fuzzy ''
|
209
209
|
}
|
210
210
|
end
|
211
|
+
|
212
|
+
context 'when drop fk with parent table' do
|
213
|
+
let(:actual_dsl) {
|
214
|
+
erbh(<<-EOS)
|
215
|
+
create_table "child", force: :cascade do |t|
|
216
|
+
t.integer "parent_id"
|
217
|
+
t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
|
218
|
+
end
|
219
|
+
|
220
|
+
create_table "parent", <%= i cond(5.1, id: :integer) %>, force: :cascade do |t|
|
221
|
+
end
|
222
|
+
|
223
|
+
add_foreign_key "child", "parent", name: "child_ibfk_1"
|
224
|
+
EOS
|
225
|
+
}
|
226
|
+
|
227
|
+
let(:expected_dsl) {
|
228
|
+
erbh(<<-EOS)
|
229
|
+
create_table "child", force: :cascade do |t|
|
230
|
+
t.integer "parent_id"
|
231
|
+
t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
|
232
|
+
end
|
233
|
+
EOS
|
234
|
+
}
|
235
|
+
|
236
|
+
before { subject.diff(actual_dsl).migrate }
|
237
|
+
subject { client }
|
238
|
+
|
239
|
+
it {
|
240
|
+
delta = subject.diff(expected_dsl)
|
241
|
+
expect(delta.differ?).to be_truthy
|
242
|
+
expect(subject.dump).to match_fuzzy actual_dsl
|
243
|
+
delta.migrate
|
244
|
+
expect(subject.dump).to match_fuzzy expected_dsl
|
245
|
+
}
|
246
|
+
end
|
247
|
+
|
248
|
+
context 'when drop fk with parent table without name' do
|
249
|
+
let(:actual_dsl) {
|
250
|
+
erbh(<<-EOS)
|
251
|
+
create_table "child", force: :cascade do |t|
|
252
|
+
t.integer "parent_id"
|
253
|
+
t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
|
254
|
+
end
|
255
|
+
|
256
|
+
create_table "parent", <%= i cond(5.1, id: :integer) %>, force: :cascade do |t|
|
257
|
+
end
|
258
|
+
|
259
|
+
add_foreign_key "child", "parent"
|
260
|
+
EOS
|
261
|
+
}
|
262
|
+
|
263
|
+
let(:expected_dsl) {
|
264
|
+
erbh(<<-EOS)
|
265
|
+
create_table "child", force: :cascade do |t|
|
266
|
+
t.integer "parent_id"
|
267
|
+
t.index ["parent_id"], name: "par_id", <%= i cond(5.0, using: :btree) %>
|
268
|
+
end
|
269
|
+
EOS
|
270
|
+
}
|
271
|
+
|
272
|
+
before { subject.diff(actual_dsl).migrate }
|
273
|
+
subject { client }
|
274
|
+
|
275
|
+
it {
|
276
|
+
delta = subject.diff(expected_dsl)
|
277
|
+
expect(delta.differ?).to be_truthy
|
278
|
+
expect(subject.dump).to match_fuzzy actual_dsl
|
279
|
+
delta.migrate
|
280
|
+
expect(subject.dump).to match_fuzzy expected_dsl
|
281
|
+
}
|
282
|
+
end
|
211
283
|
end
|