ridgepole 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/bin/ridgepole +4 -0
- data/lib/ridgepole/delta.rb +65 -16
- data/lib/ridgepole/version.rb +1 -1
- data/spec/migrate/migrate_add_column_spec.rb +18 -0
- data/spec/migrate/migrate_change_column_spec.rb +18 -0
- data/spec/migrate/migrate_change_index_spec.rb +263 -0
- data/spec/migrate/migrate_create_index_spec.rb +21 -0
- data/spec/migrate/migrate_drop_column_and_index_spec.rb +31 -0
- data/spec/migrate/migrate_drop_column_spec.rb +25 -0
- data/spec/migrate/migrate_drop_index_spec.rb +21 -0
- data/spec/migrate/migrate_noop_spec.rb +27 -0
- data/spec/migrate/migrate_rename_column_spec.rb +21 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f678cfdd6ac71010140d48e4d8174e93647de40f
|
4
|
+
data.tar.gz: 4463ea985e64b7eddf093cbee47c3973a2645a4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e02a89b0b5672a9d934c0dec3c550e05509e41a339a44f7c40169dc71d28733d63db2f64ac9cec55f008bea8253a31670fb8a44b93044c8b1f86dd7f107a3b33
|
7
|
+
data.tar.gz: ce27454f5a691e3dbcd87a57d2136e58ed6fbcde5af37febba2ec847768e2314bc80c8b3331e1659041fa2873150dd73aaf864134aa988250cc70d7acb9bf566
|
data/README.md
CHANGED
data/bin/ridgepole
CHANGED
@@ -47,6 +47,10 @@ ARGV.options do |opt|
|
|
47
47
|
opt.on('-f', '--file FILE') {|v| file = v }
|
48
48
|
opt.on('', '--dry-run') { options[:dry_run] = true }
|
49
49
|
opt.on('', '--table-options OPTIONS') {|v| options[:table_options] = v }
|
50
|
+
opt.on('', '--bulk-change') {
|
51
|
+
raise "Cannot use `bulk-change` in `merge`" if options[:merge]
|
52
|
+
options[:bulk_change] = true
|
53
|
+
}
|
50
54
|
opt.on('-e', '--export') { set_mode[:export] }
|
51
55
|
opt.on('', '--split') {|v| split = true }
|
52
56
|
opt.on('', '--split-with-dir') {|v| split = :with_dir }
|
data/lib/ridgepole/delta.rb
CHANGED
@@ -136,8 +136,12 @@ create_table(#{table_name.inspect}, #{options.inspect}) do |t|
|
|
136
136
|
end
|
137
137
|
EOS
|
138
138
|
|
139
|
-
indices.
|
140
|
-
|
139
|
+
unless indices.empty?
|
140
|
+
append_change_table(table_name, buf) do
|
141
|
+
indices.each do |index_name, index_attrs|
|
142
|
+
append_add_index(table_name, index_name, index_attrs, buf)
|
143
|
+
end
|
144
|
+
end
|
141
145
|
end
|
142
146
|
|
143
147
|
buf.puts
|
@@ -160,11 +164,20 @@ drop_table(#{table_name.inspect})
|
|
160
164
|
end
|
161
165
|
|
162
166
|
def append_change(table_name, attrs, buf)
|
163
|
-
|
164
|
-
|
167
|
+
append_change_table(table_name, buf) do
|
168
|
+
append_change_definition(table_name, attrs[:definition] || {}, buf)
|
169
|
+
append_change_indices(table_name, attrs[:indices] || {}, buf)
|
170
|
+
end
|
171
|
+
|
165
172
|
buf.puts
|
166
173
|
end
|
167
174
|
|
175
|
+
def append_change_table(table_name, buf)
|
176
|
+
buf.puts "change_table(#{table_name.inspect}, {:bulk => true}) do |t|" if @options[:bulk_change]
|
177
|
+
yield
|
178
|
+
buf.puts 'end' if @options[:bulk_change]
|
179
|
+
end
|
180
|
+
|
168
181
|
def append_change_definition(table_name, delta, buf)
|
169
182
|
(delta[:add] || {}).each do |column_name, attrs|
|
170
183
|
append_add_column(table_name, column_name, attrs, buf)
|
@@ -187,30 +200,54 @@ drop_table(#{table_name.inspect})
|
|
187
200
|
type = attrs.fetch(:type)
|
188
201
|
options = attrs[:options] || {}
|
189
202
|
|
190
|
-
|
203
|
+
if @options[:bulk_change]
|
204
|
+
buf.puts(<<-EOS)
|
205
|
+
t.column(#{column_name.inspect}, #{type.inspect}, #{options.inspect})
|
206
|
+
EOS
|
207
|
+
else
|
208
|
+
buf.puts(<<-EOS)
|
191
209
|
add_column(#{table_name.inspect}, #{column_name.inspect}, #{type.inspect}, #{options.inspect})
|
192
|
-
|
210
|
+
EOS
|
211
|
+
end
|
193
212
|
end
|
194
213
|
|
195
214
|
def append_rename_column(table_name, to_column_name, from_column_name, buf)
|
196
|
-
|
215
|
+
if @options[:bulk_change]
|
216
|
+
buf.puts(<<-EOS)
|
217
|
+
t.rename(#{from_column_name.inspect}, #{to_column_name.inspect})
|
218
|
+
EOS
|
219
|
+
else
|
220
|
+
buf.puts(<<-EOS)
|
197
221
|
rename_column(#{table_name.inspect}, #{from_column_name.inspect}, #{to_column_name.inspect})
|
198
|
-
|
222
|
+
EOS
|
223
|
+
end
|
199
224
|
end
|
200
225
|
|
201
226
|
def append_change_column(table_name, column_name, attrs, buf)
|
202
227
|
type = attrs.fetch(:type)
|
203
228
|
options = attrs[:options] || {}
|
204
229
|
|
205
|
-
|
230
|
+
if @options[:bulk_change]
|
231
|
+
buf.puts(<<-EOS)
|
232
|
+
t.change(#{column_name.inspect}, #{type.inspect}, #{options.inspect})
|
233
|
+
EOS
|
234
|
+
else
|
235
|
+
buf.puts(<<-EOS)
|
206
236
|
change_column(#{table_name.inspect}, #{column_name.inspect}, #{type.inspect}, #{options.inspect})
|
207
|
-
|
237
|
+
EOS
|
238
|
+
end
|
208
239
|
end
|
209
240
|
|
210
241
|
def append_remove_column(table_name, column_name, attrs, buf)
|
211
|
-
|
242
|
+
if @options[:bulk_change]
|
243
|
+
buf.puts(<<-EOS)
|
244
|
+
t.remove(#{column_name.inspect})
|
245
|
+
EOS
|
246
|
+
else
|
247
|
+
buf.puts(<<-EOS)
|
212
248
|
remove_column(#{table_name.inspect}, #{column_name.inspect})
|
213
|
-
|
249
|
+
EOS
|
250
|
+
end
|
214
251
|
end
|
215
252
|
|
216
253
|
def append_change_indices(table_name, delta, buf)
|
@@ -227,9 +264,15 @@ remove_column(#{table_name.inspect}, #{column_name.inspect})
|
|
227
264
|
column_name = attrs.fetch(:column_name)
|
228
265
|
options = attrs[:options] || {}
|
229
266
|
|
230
|
-
|
267
|
+
if @options[:bulk_change]
|
268
|
+
buf.puts(<<-EOS)
|
269
|
+
t.index(#{column_name.inspect}, #{options.inspect})
|
270
|
+
EOS
|
271
|
+
else
|
272
|
+
buf.puts(<<-EOS)
|
231
273
|
add_index(#{table_name.inspect}, #{column_name.inspect}, #{options.inspect})
|
232
|
-
|
274
|
+
EOS
|
275
|
+
end
|
233
276
|
end
|
234
277
|
|
235
278
|
def append_remove_index(table_name, index_name, attrs, buf)
|
@@ -237,8 +280,14 @@ add_index(#{table_name.inspect}, #{column_name.inspect}, #{options.inspect})
|
|
237
280
|
options = attrs[:options] || {}
|
238
281
|
target = options[:name] ? {:name => options[:name]} : column_name
|
239
282
|
|
240
|
-
|
283
|
+
if @options[:bulk_change]
|
284
|
+
buf.puts(<<-EOS)
|
285
|
+
t.remove_index(#{target.inspect})
|
286
|
+
EOS
|
287
|
+
else
|
288
|
+
buf.puts(<<-EOS)
|
241
289
|
remove_index(#{table_name.inspect}, #{target.inspect})
|
242
|
-
|
290
|
+
EOS
|
291
|
+
end
|
243
292
|
end
|
244
293
|
end
|
data/lib/ridgepole/version.rb
CHANGED
@@ -162,5 +162,23 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
162
162
|
remove_column("employees", "updated_at")
|
163
163
|
RUBY
|
164
164
|
}
|
165
|
+
|
166
|
+
it {
|
167
|
+
delta = client(:bulk_change => true).diff(expected_dsl)
|
168
|
+
expect(delta.differ?).to be_truthy
|
169
|
+
expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
|
170
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
171
|
+
change_table("employee_clubs", {:bulk => true}) do |t|
|
172
|
+
t.column("any_col", :string, {:null=>false, :after=>"club_id"})
|
173
|
+
end
|
174
|
+
|
175
|
+
change_table("employees", {:bulk => true}) do |t|
|
176
|
+
t.column("age", :integer, {:unsigned=>true, :null=>false, :after=>"hire_date"})
|
177
|
+
t.column("updated_at", :date, {:after=>"age"})
|
178
|
+
end
|
179
|
+
RUBY
|
180
|
+
delta.migrate
|
181
|
+
expect(subject.dump).to eq expected_dsl.strip_heredoc.strip
|
182
|
+
}
|
165
183
|
end
|
166
184
|
end
|
@@ -159,5 +159,23 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
159
159
|
change_column("employees", "gender", :string, {:limit=>1, :null=>false, :unsigned=>false})
|
160
160
|
RUBY
|
161
161
|
}
|
162
|
+
|
163
|
+
it {
|
164
|
+
delta = client(:bulk_change => true).diff(expected_dsl)
|
165
|
+
expect(delta.differ?).to be_truthy
|
166
|
+
expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
|
167
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
168
|
+
change_table("employee_clubs", {:bulk => true}) do |t|
|
169
|
+
t.change("club_id", :integer, {:unsigned=>false, :null=>true})
|
170
|
+
end
|
171
|
+
|
172
|
+
change_table("employees", {:bulk => true}) do |t|
|
173
|
+
t.change("last_name", :string, {:limit=>20, :default=>"XXX", :null=>false, :unsigned=>false})
|
174
|
+
t.change("gender", :string, {:limit=>2, :null=>false, :unsigned=>false})
|
175
|
+
end
|
176
|
+
RUBY
|
177
|
+
delta.migrate
|
178
|
+
expect(subject.dump).to eq expected_dsl.strip_heredoc.strip.gsub(/(\s*,\s*unsigned: false)?\s*,\s*null: true/, '')
|
179
|
+
}
|
162
180
|
end
|
163
181
|
end
|
@@ -0,0 +1,263 @@
|
|
1
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
2
|
+
context 'when create index' do
|
3
|
+
let(:dsl) {
|
4
|
+
<<-RUBY
|
5
|
+
create_table "clubs", force: true do |t|
|
6
|
+
t.string "name", default: "", null: false
|
7
|
+
end
|
8
|
+
|
9
|
+
add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree
|
10
|
+
|
11
|
+
create_table "departments", primary_key: "dept_no", force: true do |t|
|
12
|
+
t.string "dept_name", limit: 40, null: false
|
13
|
+
end
|
14
|
+
|
15
|
+
add_index "departments", ["dept_name"], name: "dept_name", unique: true, using: :btree
|
16
|
+
|
17
|
+
create_table "dept_emp", id: false, force: true do |t|
|
18
|
+
t.integer "emp_no", null: false
|
19
|
+
t.string "dept_no", limit: 4, null: false
|
20
|
+
t.date "from_date", null: false
|
21
|
+
t.date "to_date", null: false
|
22
|
+
end
|
23
|
+
|
24
|
+
add_index "dept_emp", ["dept_no"], name: "dept_no", using: :btree
|
25
|
+
add_index "dept_emp", ["emp_no"], name: "emp_no", using: :btree
|
26
|
+
|
27
|
+
create_table "dept_manager", id: false, force: true do |t|
|
28
|
+
t.string "dept_no", limit: 4, null: false
|
29
|
+
t.integer "emp_no", null: false
|
30
|
+
t.date "from_date", null: false
|
31
|
+
t.date "to_date", null: false
|
32
|
+
end
|
33
|
+
|
34
|
+
add_index "dept_manager", ["dept_no"], name: "dept_no", using: :btree
|
35
|
+
add_index "dept_manager", ["emp_no"], name: "emp_no", using: :btree
|
36
|
+
|
37
|
+
create_table "employee_clubs", force: true do |t|
|
38
|
+
t.integer "emp_no", unsigned: true, null: false
|
39
|
+
t.integer "club_id", unsigned: true, null: false
|
40
|
+
end
|
41
|
+
|
42
|
+
add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_emp_no_club_id", using: :btree
|
43
|
+
|
44
|
+
create_table "employees", primary_key: "emp_no", force: true do |t|
|
45
|
+
t.date "birth_date", null: false
|
46
|
+
t.string "first_name", limit: 14, null: false
|
47
|
+
t.string "last_name", limit: 16, null: false
|
48
|
+
t.string "gender", limit: 1, null: false
|
49
|
+
t.date "hire_date", null: false
|
50
|
+
end
|
51
|
+
|
52
|
+
create_table "salaries", id: false, force: true do |t|
|
53
|
+
t.integer "emp_no", null: false
|
54
|
+
t.integer "salary", null: false
|
55
|
+
t.date "from_date", null: false
|
56
|
+
t.date "to_date", null: false
|
57
|
+
end
|
58
|
+
|
59
|
+
add_index "salaries", ["emp_no"], name: "emp_no", using: :btree
|
60
|
+
|
61
|
+
create_table "titles", id: false, force: true do |t|
|
62
|
+
t.integer "emp_no", null: false
|
63
|
+
t.string "title", limit: 50, null: false
|
64
|
+
t.date "from_date", null: false
|
65
|
+
t.date "to_date"
|
66
|
+
end
|
67
|
+
|
68
|
+
add_index "titles", ["emp_no"], name: "emp_no", using: :btree
|
69
|
+
RUBY
|
70
|
+
}
|
71
|
+
|
72
|
+
let(:actual_dsl) {
|
73
|
+
<<-RUBY
|
74
|
+
create_table "clubs", force: true do |t|
|
75
|
+
t.string "name", default: "", null: false
|
76
|
+
end
|
77
|
+
|
78
|
+
add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree
|
79
|
+
|
80
|
+
create_table "departments", primary_key: "dept_no", force: true do |t|
|
81
|
+
t.string "dept_name", limit: 40, null: false
|
82
|
+
end
|
83
|
+
|
84
|
+
add_index "departments", ["dept_name"], name: "dept_name", unique: true, using: :btree
|
85
|
+
|
86
|
+
create_table "dept_emp", id: false, force: true do |t|
|
87
|
+
t.integer "emp_no", null: false
|
88
|
+
t.string "dept_no", limit: 4, null: false
|
89
|
+
t.date "from_date", null: false
|
90
|
+
t.date "to_date", null: false
|
91
|
+
end
|
92
|
+
|
93
|
+
add_index "dept_emp", ["dept_no"], name: "dept_no", using: :btree
|
94
|
+
add_index "dept_emp", ["emp_no"], name: "emp_no", using: :btree
|
95
|
+
|
96
|
+
create_table "dept_manager", id: false, force: true do |t|
|
97
|
+
t.string "dept_no", limit: 4, null: false
|
98
|
+
t.integer "emp_no", null: false
|
99
|
+
t.date "from_date", null: false
|
100
|
+
t.date "to_date", null: false
|
101
|
+
end
|
102
|
+
|
103
|
+
add_index "dept_manager", ["dept_no"], name: "dept_no", using: :btree
|
104
|
+
add_index "dept_manager", ["emp_no"], name: "emp_no", using: :btree
|
105
|
+
|
106
|
+
create_table "employee_clubs", force: true do |t|
|
107
|
+
t.integer "emp_no", unsigned: true, null: false
|
108
|
+
t.integer "club_id", unsigned: true, null: false
|
109
|
+
end
|
110
|
+
|
111
|
+
add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_emp_no_club_id", using: :btree
|
112
|
+
|
113
|
+
create_table "employees", primary_key: "emp_no", force: true do |t|
|
114
|
+
t.date "birth_date", null: false
|
115
|
+
t.string "first_name", limit: 14, null: false
|
116
|
+
t.string "last_name", limit: 16, null: false
|
117
|
+
t.string "gender", limit: 1, null: false
|
118
|
+
t.date "hire_date", null: false
|
119
|
+
end
|
120
|
+
|
121
|
+
create_table "salaries", id: false, force: true do |t|
|
122
|
+
t.integer "emp_no", null: false
|
123
|
+
t.integer "salary", null: false
|
124
|
+
t.date "from_date", null: false
|
125
|
+
t.date "to_date", null: false
|
126
|
+
end
|
127
|
+
|
128
|
+
add_index "salaries", ["emp_no"], name: "emp_no", using: :btree
|
129
|
+
|
130
|
+
create_table "titles", id: false, force: true do |t|
|
131
|
+
t.integer "emp_no", null: false
|
132
|
+
t.string "title", limit: 50, null: false
|
133
|
+
t.date "from_date", null: false
|
134
|
+
t.date "to_date"
|
135
|
+
end
|
136
|
+
|
137
|
+
add_index "titles", ["emp_no"], name: "emp_no", using: :btree
|
138
|
+
RUBY
|
139
|
+
}
|
140
|
+
|
141
|
+
let(:expected_dsl) {
|
142
|
+
<<-RUBY
|
143
|
+
create_table "clubs", force: true do |t|
|
144
|
+
t.string "name", default: "", null: false
|
145
|
+
end
|
146
|
+
|
147
|
+
add_index "clubs", ["name"], name: "idx_name", unique: true, using: :btree
|
148
|
+
|
149
|
+
create_table "departments", primary_key: "dept_no", force: true do |t|
|
150
|
+
t.string "dept_name", limit: 40, null: false
|
151
|
+
end
|
152
|
+
|
153
|
+
add_index "departments", ["dept_name"], name: "dept_name", unique: true, using: :btree
|
154
|
+
|
155
|
+
create_table "dept_emp", id: false, force: true do |t|
|
156
|
+
t.integer "emp_no", null: false
|
157
|
+
t.string "dept_no", limit: 4, null: false
|
158
|
+
t.date "from_date", null: false
|
159
|
+
t.date "to_date", null: false
|
160
|
+
end
|
161
|
+
|
162
|
+
add_index "dept_emp", ["dept_no"], name: "dept_no", using: :btree
|
163
|
+
add_index "dept_emp", ["from_date"], name: "emp_no", using: :btree
|
164
|
+
|
165
|
+
create_table "dept_manager", id: false, force: true do |t|
|
166
|
+
t.string "dept_no", limit: 4, null: false
|
167
|
+
t.integer "emp_no", null: false
|
168
|
+
t.date "from_date", null: false
|
169
|
+
t.date "to_date", null: false
|
170
|
+
end
|
171
|
+
|
172
|
+
add_index "dept_manager", ["dept_no"], name: "dept_no", using: :btree
|
173
|
+
add_index "dept_manager", ["from_date"], name: "emp_no", using: :btree
|
174
|
+
|
175
|
+
create_table "employee_clubs", force: true do |t|
|
176
|
+
t.integer "emp_no", unsigned: true, null: false
|
177
|
+
t.integer "club_id", unsigned: true, null: false
|
178
|
+
end
|
179
|
+
|
180
|
+
add_index "employee_clubs", ["emp_no", "club_id"], name: "idx_emp_no_club_id", using: :btree
|
181
|
+
|
182
|
+
create_table "employees", primary_key: "emp_no", force: true do |t|
|
183
|
+
t.date "birth_date", null: false
|
184
|
+
t.string "first_name", limit: 14, null: false
|
185
|
+
t.string "last_name", limit: 16, null: false
|
186
|
+
t.string "gender", limit: 1, null: false
|
187
|
+
t.date "hire_date", null: false
|
188
|
+
end
|
189
|
+
|
190
|
+
create_table "salaries", id: false, force: true do |t|
|
191
|
+
t.integer "emp_no", null: false
|
192
|
+
t.integer "salary", null: false
|
193
|
+
t.date "from_date", null: false
|
194
|
+
t.date "to_date", null: false
|
195
|
+
end
|
196
|
+
|
197
|
+
add_index "salaries", ["from_date"], name: "emp_no", using: :btree
|
198
|
+
|
199
|
+
create_table "titles", id: false, force: true do |t|
|
200
|
+
t.integer "emp_no", null: false
|
201
|
+
t.string "title", limit: 50, null: false
|
202
|
+
t.date "from_date", null: false
|
203
|
+
t.date "to_date"
|
204
|
+
end
|
205
|
+
|
206
|
+
add_index "titles", ["emp_no"], name: "emp_no", using: :btree
|
207
|
+
RUBY
|
208
|
+
}
|
209
|
+
|
210
|
+
before { subject.diff(actual_dsl).migrate }
|
211
|
+
subject { client }
|
212
|
+
|
213
|
+
it {
|
214
|
+
delta = subject.diff(expected_dsl)
|
215
|
+
expect(delta.differ?).to be_truthy
|
216
|
+
expect(subject.dump.delete_empty_lines).to eq actual_dsl.strip_heredoc.strip.delete_empty_lines
|
217
|
+
delta.migrate
|
218
|
+
expect(subject.dump.delete_empty_lines).to eq expected_dsl.strip_heredoc.strip.delete_empty_lines
|
219
|
+
}
|
220
|
+
|
221
|
+
it {
|
222
|
+
delta = Ridgepole::Client.diff(actual_dsl, expected_dsl, reverse: true)
|
223
|
+
expect(delta.differ?).to be_truthy
|
224
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
225
|
+
remove_index("dept_emp", {:name=>"emp_no"})
|
226
|
+
add_index("dept_emp", ["emp_no"], {:name=>"emp_no", :using=>:btree})
|
227
|
+
|
228
|
+
remove_index("dept_manager", {:name=>"emp_no"})
|
229
|
+
add_index("dept_manager", ["emp_no"], {:name=>"emp_no", :using=>:btree})
|
230
|
+
|
231
|
+
remove_index("salaries", {:name=>"emp_no"})
|
232
|
+
add_index("salaries", ["emp_no"], {:name=>"emp_no", :using=>:btree})
|
233
|
+
RUBY
|
234
|
+
}
|
235
|
+
|
236
|
+
it {
|
237
|
+
delta = client(:bulk_change => true).diff(expected_dsl)
|
238
|
+
expect(delta.differ?).to be_truthy
|
239
|
+
expect(subject.dump.delete_empty_lines).to eq actual_dsl.strip_heredoc.strip.delete_empty_lines
|
240
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
241
|
+
change_table("dept_emp", {:bulk => true}) do |t|
|
242
|
+
t.remove_index({:name=>"emp_no"})
|
243
|
+
t.index(["from_date"], {:name=>"emp_no", :using=>:btree})
|
244
|
+
end
|
245
|
+
|
246
|
+
change_table("dept_manager", {:bulk => true}) do |t|
|
247
|
+
t.remove_index({:name=>"emp_no"})
|
248
|
+
t.index(["from_date"], {:name=>"emp_no", :using=>:btree})
|
249
|
+
end
|
250
|
+
|
251
|
+
change_table("salaries", {:bulk => true}) do |t|
|
252
|
+
t.remove_index({:name=>"emp_no"})
|
253
|
+
t.index(["from_date"], {:name=>"emp_no", :using=>:btree})
|
254
|
+
end
|
255
|
+
RUBY
|
256
|
+
|
257
|
+
# XXX: Can not add an index of the same name
|
258
|
+
expect {
|
259
|
+
delta.migrate
|
260
|
+
}.to raise_error(/Index name 'emp_no' on table 'dept_emp' already exists/)
|
261
|
+
}
|
262
|
+
end
|
263
|
+
end
|
@@ -99,5 +99,26 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
99
99
|
remove_index("titles", {:name=>"emp_no"})
|
100
100
|
RUBY
|
101
101
|
}
|
102
|
+
|
103
|
+
it {
|
104
|
+
delta = client(:bulk_change => true).diff(expected_dsl)
|
105
|
+
expect(delta.differ?).to be_truthy
|
106
|
+
expect(subject.dump.delete_empty_lines).to eq actual_dsl.strip_heredoc.strip.delete_empty_lines
|
107
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
108
|
+
change_table("clubs", {:bulk => true}) do |t|
|
109
|
+
t.index(["name"], {:name=>"idx_name", :unique=>true, :using=>:btree})
|
110
|
+
end
|
111
|
+
|
112
|
+
change_table("employee_clubs", {:bulk => true}) do |t|
|
113
|
+
t.index(["emp_no", "club_id"], {:name=>"idx_emp_no_club_id", :using=>:btree})
|
114
|
+
end
|
115
|
+
|
116
|
+
change_table("titles", {:bulk => true}) do |t|
|
117
|
+
t.index(["emp_no"], {:name=>"emp_no", :using=>:btree})
|
118
|
+
end
|
119
|
+
RUBY
|
120
|
+
delta.migrate
|
121
|
+
expect(subject.dump.delete_empty_lines).to eq expected_dsl.strip_heredoc.strip.delete_empty_lines
|
122
|
+
}
|
102
123
|
end
|
103
124
|
end
|
@@ -144,5 +144,36 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
144
144
|
delta.migrate(:noop => true)
|
145
145
|
expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
|
146
146
|
}
|
147
|
+
|
148
|
+
it {
|
149
|
+
delta = client(:bulk_change => true).diff(expected_dsl)
|
150
|
+
expect(delta.differ?).to be_truthy
|
151
|
+
expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
|
152
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
153
|
+
change_table("dept_emp", {:bulk => true}) do |t|
|
154
|
+
t.remove("emp_no")
|
155
|
+
t.remove("from_date")
|
156
|
+
t.remove("to_date")
|
157
|
+
end
|
158
|
+
|
159
|
+
change_table("dept_manager", {:bulk => true}) do |t|
|
160
|
+
t.remove("emp_no")
|
161
|
+
t.remove("from_date")
|
162
|
+
t.remove("to_date")
|
163
|
+
end
|
164
|
+
|
165
|
+
change_table("employee_clubs", {:bulk => true}) do |t|
|
166
|
+
t.remove("club_id")
|
167
|
+
end
|
168
|
+
|
169
|
+
change_table("employees", {:bulk => true}) do |t|
|
170
|
+
t.remove("last_name")
|
171
|
+
t.remove("gender")
|
172
|
+
t.remove("hire_date")
|
173
|
+
end
|
174
|
+
RUBY
|
175
|
+
delta.migrate
|
176
|
+
expect(subject.dump).to eq expected_dsl.strip_heredoc.strip
|
177
|
+
}
|
147
178
|
end
|
148
179
|
end
|
@@ -157,5 +157,30 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
157
157
|
add_column("employees", "hire_date", :date, {:null=>false, :after=>"gender"})
|
158
158
|
RUBY
|
159
159
|
}
|
160
|
+
|
161
|
+
it {
|
162
|
+
delta = client(:bulk_change => true).diff(expected_dsl)
|
163
|
+
expect(delta.differ?).to be_truthy
|
164
|
+
expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
|
165
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
166
|
+
change_table("dept_emp", {:bulk => true}) do |t|
|
167
|
+
t.remove("from_date")
|
168
|
+
t.remove("to_date")
|
169
|
+
end
|
170
|
+
|
171
|
+
change_table("dept_manager", {:bulk => true}) do |t|
|
172
|
+
t.remove("from_date")
|
173
|
+
t.remove("to_date")
|
174
|
+
end
|
175
|
+
|
176
|
+
change_table("employees", {:bulk => true}) do |t|
|
177
|
+
t.remove("last_name")
|
178
|
+
t.remove("gender")
|
179
|
+
t.remove("hire_date")
|
180
|
+
end
|
181
|
+
RUBY
|
182
|
+
delta.migrate
|
183
|
+
expect(subject.dump).to eq expected_dsl.strip_heredoc.strip
|
184
|
+
}
|
160
185
|
end
|
161
186
|
end
|
@@ -99,5 +99,26 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
99
99
|
add_index("titles", ["emp_no"], {:name=>"emp_no", :using=>:btree})
|
100
100
|
RUBY
|
101
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 eq actual_dsl.strip_heredoc.strip
|
107
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
108
|
+
change_table("clubs", {:bulk => true}) do |t|
|
109
|
+
t.remove_index({:name=>"idx_name"})
|
110
|
+
end
|
111
|
+
|
112
|
+
change_table("employee_clubs", {:bulk => true}) do |t|
|
113
|
+
t.remove_index({:name=>"idx_emp_no_club_id"})
|
114
|
+
end
|
115
|
+
|
116
|
+
change_table("titles", {:bulk => true}) do |t|
|
117
|
+
t.remove_index({:name=>"emp_no"})
|
118
|
+
end
|
119
|
+
RUBY
|
120
|
+
delta.migrate
|
121
|
+
expect(subject.dump.each_line.select {|i| i !~ /\A\Z/ }.join).to eq expected_dsl.strip_heredoc.strip.each_line.select {|i| i !~ /\A\Z/ }.join
|
122
|
+
}
|
102
123
|
end
|
103
124
|
end
|
@@ -100,5 +100,32 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
100
100
|
CREATE INDEX `emp_no` USING btree ON `titles` (`emp_no`)
|
101
101
|
SQL
|
102
102
|
}
|
103
|
+
|
104
|
+
it {
|
105
|
+
delta = client(:bulk_change => true).diff(expected_dsl)
|
106
|
+
expect(delta.differ?).to be_truthy
|
107
|
+
sql = delta.migrate(:noop => true)
|
108
|
+
expect(subject.dump).to eq actual_dsl
|
109
|
+
|
110
|
+
sql = sql.each_line.map {|i| i.strip }.join("\n")
|
111
|
+
|
112
|
+
expect(sql).to eq <<-SQL.strip_heredoc.strip
|
113
|
+
CREATE TABLE `clubs` (`id` int(10) unsigned DEFAULT NULL auto_increment PRIMARY KEY, `name` varchar(255) DEFAULT '' NOT NULL) ENGINE=InnoDB
|
114
|
+
ALTER TABLE `clubs` ADD UNIQUE INDEX idx_name (`name`)
|
115
|
+
CREATE TABLE `departments` (`dept_no` int(10) unsigned DEFAULT NULL auto_increment PRIMARY KEY, `dept_name` varchar(40) NOT NULL) ENGINE=InnoDB
|
116
|
+
ALTER TABLE `departments` ADD UNIQUE INDEX dept_name (`dept_name`)
|
117
|
+
CREATE TABLE `dept_emp` (`emp_no` int(10) NOT NULL, `dept_no` varchar(4) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
|
118
|
+
ALTER TABLE `dept_emp` ADD INDEX dept_no (`dept_no`), ADD INDEX emp_no (`emp_no`)
|
119
|
+
CREATE TABLE `dept_manager` (`dept_no` varchar(4) NOT NULL, `emp_no` int(10) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
|
120
|
+
ALTER TABLE `dept_manager` ADD INDEX dept_no (`dept_no`), ADD INDEX emp_no (`emp_no`)
|
121
|
+
CREATE TABLE `employee_clubs` (`id` int(10) unsigned DEFAULT NULL auto_increment PRIMARY KEY, `emp_no` int(10) unsigned NOT NULL, `club_id` int(10) unsigned NOT NULL) ENGINE=InnoDB
|
122
|
+
ALTER TABLE `employee_clubs` ADD INDEX idx_emp_no_club_id (`emp_no`, `club_id`)
|
123
|
+
CREATE TABLE `employees` (`emp_no` int(10) unsigned DEFAULT NULL 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
|
124
|
+
CREATE TABLE `salaries` (`emp_no` int(10) NOT NULL, `salary` int(10) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL) ENGINE=InnoDB
|
125
|
+
ALTER TABLE `salaries` ADD INDEX emp_no (`emp_no`)
|
126
|
+
CREATE TABLE `titles` (`emp_no` int(10) NOT NULL, `title` varchar(50) NOT NULL, `from_date` date NOT NULL, `to_date` date) ENGINE=InnoDB
|
127
|
+
ALTER TABLE `titles` ADD INDEX emp_no (`emp_no`)
|
128
|
+
SQL
|
129
|
+
}
|
103
130
|
end
|
104
131
|
end
|
@@ -160,6 +160,27 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
160
160
|
rename_column("employees", "gender2", "gender")
|
161
161
|
RUBY
|
162
162
|
}
|
163
|
+
|
164
|
+
it {
|
165
|
+
delta = client(:bulk_change => true).diff(expected_dsl)
|
166
|
+
expect(delta.differ?).to be_truthy
|
167
|
+
expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
|
168
|
+
expect(delta.script).to eq <<-RUBY.strip_heredoc.strip
|
169
|
+
change_table("dept_emp", {:bulk => true}) do |t|
|
170
|
+
t.rename("from_date", "from_date2")
|
171
|
+
end
|
172
|
+
|
173
|
+
change_table("dept_manager", {:bulk => true}) do |t|
|
174
|
+
t.rename("to_date", "to_date2")
|
175
|
+
end
|
176
|
+
|
177
|
+
change_table("employees", {:bulk => true}) do |t|
|
178
|
+
t.rename("gender", "gender2")
|
179
|
+
end
|
180
|
+
RUBY
|
181
|
+
delta.migrate
|
182
|
+
expect(subject.dump).to eq expected_dsl.strip_heredoc.strip.gsub(/\s*,\s*renamed_from:.*$/, '')
|
183
|
+
}
|
163
184
|
end
|
164
185
|
|
165
186
|
context 'when rename column (not found)' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ridgepole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -131,6 +131,7 @@ files:
|
|
131
131
|
- spec/migrate/check_orphan_index_spec.rb
|
132
132
|
- spec/migrate/migrate_add_column_spec.rb
|
133
133
|
- spec/migrate/migrate_change_column_spec.rb
|
134
|
+
- spec/migrate/migrate_change_index_spec.rb
|
134
135
|
- spec/migrate/migrate_change_table_option_spec.rb
|
135
136
|
- spec/migrate/migrate_create_index_spec.rb
|
136
137
|
- spec/migrate/migrate_create_table_spec.rb
|
@@ -192,6 +193,7 @@ test_files:
|
|
192
193
|
- spec/migrate/check_orphan_index_spec.rb
|
193
194
|
- spec/migrate/migrate_add_column_spec.rb
|
194
195
|
- spec/migrate/migrate_change_column_spec.rb
|
196
|
+
- spec/migrate/migrate_change_index_spec.rb
|
195
197
|
- spec/migrate/migrate_change_table_option_spec.rb
|
196
198
|
- spec/migrate/migrate_create_index_spec.rb
|
197
199
|
- spec/migrate/migrate_create_table_spec.rb
|