ridgepole 0.7.1.beta2 → 0.7.1.beta3
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/bin/ridgepole +1 -0
- data/lib/ridgepole/delta.rb +3 -1
- data/lib/ridgepole/diff.rb +55 -8
- data/lib/ridgepole/dsl_parser/table_definition.rb +6 -4
- data/lib/ridgepole/version.rb +1 -1
- data/spec/mysql/cli/ridgepole_spec.rb +1 -0
- data/spec/mysql/migrate/migrate_change_column3_spec.rb +42 -34
- data/spec/mysql/migrate/migrate_primary_key_spec.rb +57 -0
- data/spec/postgresql/migrate/migrate_create_table_with_default_proc_spec.rb +28 -12
- data/spec/postgresql/migrate/migrate_references_spec.rb +88 -0
- data/spec/spec_const.rb +2 -2
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a71e8eef1bd9b0c5cc4380f107084a563422b7d
|
4
|
+
data.tar.gz: 5ddebfde7e3f1402fa89e3e683649cee8f19f01f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80da7be8ba5725b1e84d7a1a46d766d4e56fa1be89ccbe105b4ff298dc513db355b59c6847a59f4e3f6690c5e0fb4c9ac5113e74b58bc4af751a2b36ca907b77
|
7
|
+
data.tar.gz: 40a60f8c765b3fa48025fa8067d8258a0c173b117decf3518bbecc8575fba4fad87cb613eb55800c0618eead0dca17fa01b2ff3f74e523940a514d84d5e962b9
|
data/bin/ridgepole
CHANGED
@@ -124,6 +124,7 @@ ARGV.options do |opt|
|
|
124
124
|
opt.on('', '--check-relation-type DEF_PK') {|v| options[:check_relation_type] = v }
|
125
125
|
opt.on('', '--ignore-table-comment') { options[:ignore_table_comment] = true }
|
126
126
|
opt.on('', '--skip-column-comment-change') { options[:skip_column_comment_change] = true }
|
127
|
+
opt.on('', '--allow-pk-change') { options[:allow_pk_change] = true }
|
127
128
|
opt.on('-r', '--require LIBS', Array) {|v| v.each {|i| require i } }
|
128
129
|
opt.on('' , '--log-file LOG_FILE') {|v| options[:log_file] = v }
|
129
130
|
opt.on('' , '--verbose') { Ridgepole::Logger.verbose = true }
|
data/lib/ridgepole/delta.rb
CHANGED
@@ -284,14 +284,16 @@ execute "ALTER TABLE #{ActiveRecord::Base.connection.quote_table_name(table_name
|
|
284
284
|
|
285
285
|
def append_change(table_name, attrs, buf, pre_buf_for_fk, post_buf_for_fk)
|
286
286
|
definition = attrs[:definition] || {}
|
287
|
+
primary_key_definition = attrs[:primary_key_definition] || {}
|
287
288
|
indices = attrs[:indices] || {}
|
288
289
|
foreign_keys = attrs[:foreign_keys] || {}
|
289
290
|
table_options = attrs[:table_options]
|
290
291
|
|
291
|
-
if not definition.empty? or not indices.empty?
|
292
|
+
if not definition.empty? or not indices.empty? or not primary_key_definition.empty?
|
292
293
|
append_change_table(table_name, buf) do
|
293
294
|
append_delete_indices(table_name, indices, buf)
|
294
295
|
append_change_definition(table_name, definition, buf)
|
296
|
+
append_change_definition(table_name, primary_key_definition, buf)
|
295
297
|
append_add_indices(table_name, indices, buf)
|
296
298
|
end
|
297
299
|
end
|
data/lib/ridgepole/diff.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
class Ridgepole::Diff
|
2
|
+
PRIMARY_KEY_OPTIONS = %i(id limit default null precision scale collation unsigned comment).freeze
|
3
|
+
|
2
4
|
def initialize(options = {})
|
3
5
|
@options = options
|
4
6
|
@logger = Ridgepole::Logger.instance
|
@@ -126,6 +128,21 @@ class Ridgepole::Diff
|
|
126
128
|
to.delete(:options)
|
127
129
|
end
|
128
130
|
|
131
|
+
pk_attrs = build_primary_key_attrs_if_changed(from, to, table_name)
|
132
|
+
if pk_attrs
|
133
|
+
if @options[:allow_pk_change]
|
134
|
+
table_delta[:primary_key_definition] = {change: {id: pk_attrs}}
|
135
|
+
else
|
136
|
+
@logger.warn(<<-EOS)
|
137
|
+
[WARNING] Primary key definition of `#{table_name}` differ but `allow_pk_change` option is false
|
138
|
+
from: #{from.slice(*PRIMARY_KEY_OPTIONS)}
|
139
|
+
to: #{to.slice(*PRIMARY_KEY_OPTIONS)}
|
140
|
+
EOS
|
141
|
+
end
|
142
|
+
from = from.except(*PRIMARY_KEY_OPTIONS)
|
143
|
+
to = to.except(*PRIMARY_KEY_OPTIONS)
|
144
|
+
end
|
145
|
+
|
129
146
|
unless from == to
|
130
147
|
@logger.warn(<<-EOS)
|
131
148
|
[WARNING] No difference of schema configuration for table `#{table_name}` but table options differ.
|
@@ -135,6 +152,39 @@ class Ridgepole::Diff
|
|
135
152
|
end
|
136
153
|
end
|
137
154
|
|
155
|
+
def convert_to_primary_key_attrs(column_options)
|
156
|
+
options = column_options.dup
|
157
|
+
|
158
|
+
if options[:id]
|
159
|
+
type = options.delete(:id)
|
160
|
+
else
|
161
|
+
type = Ridgepole::DSLParser::TableDefinition::DEFAULT_PRIMARY_KEY_TYPE
|
162
|
+
end
|
163
|
+
|
164
|
+
if [:integer, :bigint].include?(type) && !options.key?(:default)
|
165
|
+
options[:auto_increment] = true
|
166
|
+
end
|
167
|
+
|
168
|
+
{type: type, options: options}
|
169
|
+
end
|
170
|
+
|
171
|
+
def build_attrs_if_changed(to_attrs, from_attrs, table_name, primary_key: false)
|
172
|
+
normalize_column_options!(from_attrs, primary_key)
|
173
|
+
normalize_column_options!(to_attrs, primary_key)
|
174
|
+
|
175
|
+
unless compare_column_attrs(from_attrs, to_attrs)
|
176
|
+
new_to_attrs = fix_change_column_options(table_name, from_attrs, to_attrs)
|
177
|
+
end
|
178
|
+
new_to_attrs
|
179
|
+
end
|
180
|
+
|
181
|
+
def build_primary_key_attrs_if_changed(from, to, table_name)
|
182
|
+
from_column_attrs = convert_to_primary_key_attrs(from.slice(*PRIMARY_KEY_OPTIONS))
|
183
|
+
to_column_attrs = convert_to_primary_key_attrs(to.slice(*PRIMARY_KEY_OPTIONS))
|
184
|
+
return if from_column_attrs == to_column_attrs
|
185
|
+
build_attrs_if_changed(to_column_attrs, from_column_attrs, table_name, primary_key: true)
|
186
|
+
end
|
187
|
+
|
138
188
|
def scan_definition_change(from, to, from_indices, table_name, table_options, table_delta)
|
139
189
|
from = (from || {}).dup
|
140
190
|
to = (to || {}).dup
|
@@ -150,12 +200,9 @@ class Ridgepole::Diff
|
|
150
200
|
|
151
201
|
to.each do |column_name, to_attrs|
|
152
202
|
if (from_attrs = from.delete(column_name))
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
unless compare_column_attrs(from_attrs, to_attrs)
|
203
|
+
to_attrs = build_attrs_if_changed(to_attrs, from_attrs, table_name)
|
204
|
+
if to_attrs
|
157
205
|
definition_delta[:change] ||= {}
|
158
|
-
to_attrs = fix_change_column_options(table_name, from_attrs, to_attrs)
|
159
206
|
definition_delta[:change][column_name] = to_attrs
|
160
207
|
end
|
161
208
|
else
|
@@ -304,14 +351,14 @@ class Ridgepole::Diff
|
|
304
351
|
end
|
305
352
|
end
|
306
353
|
|
307
|
-
def normalize_column_options!(attrs)
|
354
|
+
def normalize_column_options!(attrs, primary_key = false)
|
308
355
|
opts = attrs[:options]
|
309
|
-
opts[:null] = true
|
356
|
+
opts[:null] = true if not opts.has_key?(:null) and not primary_key
|
310
357
|
default_limit = Ridgepole::DefaultsLimit.default_limit(attrs[:type], @options)
|
311
358
|
opts.delete(:limit) if opts[:limit] == default_limit
|
312
359
|
|
313
360
|
# XXX: MySQL only?
|
314
|
-
if not opts.has_key?(:default)
|
361
|
+
if not opts.has_key?(:default) and not primary_key
|
315
362
|
opts[:default] = nil
|
316
363
|
end
|
317
364
|
|
@@ -17,6 +17,8 @@ class Ridgepole::DSLParser
|
|
17
17
|
}
|
18
18
|
end
|
19
19
|
|
20
|
+
DEFAULT_PRIMARY_KEY_TYPE = Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('5.1') ? :bigint : :integer
|
21
|
+
|
20
22
|
TYPES = [
|
21
23
|
# https://github.com/rails/rails/blob/v4.2.1/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb#L274
|
22
24
|
:string,
|
@@ -121,15 +123,15 @@ class Ridgepole::DSLParser
|
|
121
123
|
def references(*args)
|
122
124
|
options = args.extract_options!
|
123
125
|
polymorphic = options.delete(:polymorphic)
|
124
|
-
index_options = options.delete(:index)
|
125
|
-
type = options.delete(:type) ||
|
126
|
+
index_options = options.has_key?(:index) ? options.delete(:index) : true
|
127
|
+
type = options.delete(:type) || DEFAULT_PRIMARY_KEY_TYPE
|
126
128
|
|
127
129
|
args.each do |col|
|
128
130
|
column("#{col}_id", type, options)
|
129
131
|
column("#{col}_type", :string, polymorphic.is_a?(Hash) ? polymorphic : options) if polymorphic
|
130
132
|
if index_options
|
131
|
-
|
132
|
-
index(
|
133
|
+
columns = polymorphic ? ["#{col}_type", "#{col}_id"] : ["#{col}_id"]
|
134
|
+
index(columns, index_options.is_a?(Hash) ? index_options : {})
|
133
135
|
end
|
134
136
|
end
|
135
137
|
end
|
data/lib/ridgepole/version.rb
CHANGED
@@ -90,15 +90,17 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
90
90
|
|
91
91
|
context 'when use references (no change)' do
|
92
92
|
let(:actual_dsl) {
|
93
|
-
<<-EOS
|
93
|
+
erbh(<<-EOS)
|
94
94
|
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
95
|
-
t.date
|
96
|
-
t.string
|
97
|
-
t.string
|
98
|
-
t.string
|
99
|
-
t.date
|
100
|
-
t.integer "products_id"
|
101
|
-
t.integer "user_id"
|
95
|
+
t.date "birth_date", null: false
|
96
|
+
t.string "first_name", limit: 14, null: false
|
97
|
+
t.string "last_name", limit: 16, null: false
|
98
|
+
t.string "gender", limit: 1, null: false
|
99
|
+
t.date "hire_date", null: false
|
100
|
+
t.<%= cond(5.1, 'bigint', 'integer') %> "products_id"
|
101
|
+
t.<%= cond(5.1, 'bigint', 'integer') %> "user_id"
|
102
|
+
t.index "products_id"
|
103
|
+
t.index "user_id"
|
102
104
|
end
|
103
105
|
EOS
|
104
106
|
}
|
@@ -127,17 +129,19 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
127
129
|
|
128
130
|
context 'when use references with polymorphic (no change)' do
|
129
131
|
let(:actual_dsl) {
|
130
|
-
<<-EOS
|
132
|
+
erbh(<<-EOS)
|
131
133
|
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
132
|
-
t.date
|
133
|
-
t.string
|
134
|
-
t.string
|
135
|
-
t.string
|
136
|
-
t.date
|
137
|
-
t.integer
|
138
|
-
t.string
|
139
|
-
t.integer
|
140
|
-
t.string
|
134
|
+
t.date "birth_date", null: false
|
135
|
+
t.string "first_name", limit: 14, null: false
|
136
|
+
t.string "last_name", limit: 16, null: false
|
137
|
+
t.string "gender", limit: 1, null: false
|
138
|
+
t.date "hire_date", null: false
|
139
|
+
t.<%= cond(5.1, 'bigint', 'integer') %> "products_id"
|
140
|
+
t.string "products_type"
|
141
|
+
t.<%= cond(5.1, 'bigint', 'integer') %> "user_id"
|
142
|
+
t.string "user_type"
|
143
|
+
t.index ["products_type", "products_id"]
|
144
|
+
t.index ["user_type", "user_id"]
|
141
145
|
end
|
142
146
|
EOS
|
143
147
|
}
|
@@ -193,13 +197,15 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
193
197
|
let(:expected_dsl) {
|
194
198
|
erbh(<<-EOS)
|
195
199
|
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
196
|
-
t.date
|
197
|
-
t.string
|
198
|
-
t.string
|
199
|
-
t.string
|
200
|
-
t.date
|
201
|
-
t.integer "products_id"
|
202
|
-
t.integer "user_id"
|
200
|
+
t.date "birth_date", null: false
|
201
|
+
t.string "first_name", limit: 14, null: false
|
202
|
+
t.string "last_name", limit: 16, null: false
|
203
|
+
t.string "gender", limit: 1, null: false
|
204
|
+
t.date "hire_date", null: false
|
205
|
+
t.<%= cond(5.1, 'bigint', 'integer') %> "products_id"
|
206
|
+
t.<%= cond(5.1, 'bigint', 'integer') %> "user_id"
|
207
|
+
t.index ["products_id"], name: "index_employees_on_products_id", <%= i cond(5.0, using: :btree) %>
|
208
|
+
t.index ["user_id"], name: "index_employees_on_user_id", <%= i cond(5.0, using: :btree) %>
|
203
209
|
end
|
204
210
|
EOS
|
205
211
|
}
|
@@ -245,15 +251,17 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
245
251
|
let(:expected_dsl) {
|
246
252
|
erbh(<<-EOS)
|
247
253
|
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
248
|
-
t.date
|
249
|
-
t.string
|
250
|
-
t.string
|
251
|
-
t.string
|
252
|
-
t.date
|
253
|
-
t.integer "products_id"
|
254
|
-
t.string
|
255
|
-
t.integer "user_id"
|
256
|
-
t.string
|
254
|
+
t.date "birth_date", null: false
|
255
|
+
t.string "first_name", limit: 14, null: false
|
256
|
+
t.string "last_name", limit: 16, null: false
|
257
|
+
t.string "gender", limit: 1, null: false
|
258
|
+
t.date "hire_date", null: false
|
259
|
+
t.<%= cond(5.1, 'bigint', 'integer') %> "products_id"
|
260
|
+
t.string "products_type"
|
261
|
+
t.<%= cond(5.1, 'bigint', 'integer') %> "user_id"
|
262
|
+
t.string "user_type"
|
263
|
+
t.index ["products_type", "products_id"], name: "index_employees_on_products_type_and_products_id", <%= i cond(5.0, using: :btree) %>
|
264
|
+
t.index ["user_type", "user_id"], name: "index_employees_on_user_type_and_user_id", <%= i cond(5.0, using: :btree) %>
|
257
265
|
end
|
258
266
|
EOS
|
259
267
|
}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
2
|
+
let(:actual_dsl) {
|
3
|
+
erbh(<<-EOS)
|
4
|
+
create_table "employees", id: :integer, unsigned: true, force: :cascade do |t|
|
5
|
+
end
|
6
|
+
EOS
|
7
|
+
}
|
8
|
+
|
9
|
+
before { subject.diff(actual_dsl).migrate }
|
10
|
+
subject { client(allow_pk_change: allow_pk_change) }
|
11
|
+
|
12
|
+
context 'when allow_pk_change option is false' do
|
13
|
+
let(:allow_pk_change) { false }
|
14
|
+
let(:expected_dsl) {
|
15
|
+
erbh(<<-EOS)
|
16
|
+
create_table "employees", id: :bigint, unsigned: true, force: :cascade do |t|
|
17
|
+
end
|
18
|
+
EOS
|
19
|
+
}
|
20
|
+
|
21
|
+
it {
|
22
|
+
expect(Ridgepole::Logger.instance).to receive(:warn).with(<<-EOS)
|
23
|
+
[WARNING] Primary key definition of `employees` differ but `allow_pk_change` option is false
|
24
|
+
from: {:id=>:integer, :unsigned=>true}
|
25
|
+
to: {:id=>:bigint, :unsigned=>true}
|
26
|
+
EOS
|
27
|
+
|
28
|
+
delta = subject.diff(expected_dsl)
|
29
|
+
expect(delta.differ?).to be_falsey
|
30
|
+
delta.migrate
|
31
|
+
expect(subject.dump).to match_fuzzy actual_dsl
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when allow_pk_change option is false' do
|
36
|
+
let(:allow_pk_change) { true }
|
37
|
+
let(:expected_dsl) {
|
38
|
+
erbh(<<-EOS)
|
39
|
+
create_table "employees", id: :bigint, unsigned: true, force: :cascade do |t|
|
40
|
+
end
|
41
|
+
|
42
|
+
create_table "salaries", force: :cascade do |t|
|
43
|
+
t.bigint "employee_id", null: false, unsigned: true
|
44
|
+
t.index ["employee_id"], name: "fk_salaries_employees", <%= i cond(5.0, using: :btree) %>
|
45
|
+
end
|
46
|
+
add_foreign_key "salaries", "employees", name: "fk_salaries_employees"
|
47
|
+
EOS
|
48
|
+
}
|
49
|
+
|
50
|
+
it {
|
51
|
+
delta = subject.diff(expected_dsl)
|
52
|
+
expect(delta.differ?).to be_truthy
|
53
|
+
delta.migrate
|
54
|
+
expect(subject.dump).to match_fuzzy expected_dsl
|
55
|
+
}
|
56
|
+
end
|
57
|
+
end
|
@@ -53,7 +53,7 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
53
53
|
}
|
54
54
|
end
|
55
55
|
|
56
|
-
context 'when migrate table with default proc' do
|
56
|
+
context 'when migrate table with default proc change' do
|
57
57
|
let(:actual_dsl) {
|
58
58
|
erbh(<<-EOS)
|
59
59
|
create_table "users", id: :uuid, default: -> { "uuid_generate_v1()" }, force: :cascade do |t|
|
@@ -75,20 +75,36 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
75
75
|
}
|
76
76
|
|
77
77
|
before { subject.diff(actual_dsl).migrate }
|
78
|
-
subject { client }
|
78
|
+
subject { client(allow_pk_change: allow_pk_change) }
|
79
79
|
|
80
|
-
|
81
|
-
|
82
|
-
|
80
|
+
context 'when allow_pk_change option is false' do
|
81
|
+
let(:allow_pk_change) { false }
|
82
|
+
|
83
|
+
it {
|
84
|
+
expect(Ridgepole::Logger.instance).to receive(:warn).with(<<-EOS)
|
85
|
+
[WARNING] Primary key definition of `users` differ but `allow_pk_change` option is false
|
83
86
|
from: {:id=>:uuid, :default=>"uuid_generate_v1()"}
|
84
87
|
to: {:id=>:uuid, :default=>"uuid_generate_v4()"}
|
85
|
-
|
88
|
+
EOS
|
86
89
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
90
|
+
delta = subject.diff(expected_dsl)
|
91
|
+
expect(delta.differ?).to be_falsey
|
92
|
+
expect(subject.dump).to match_fuzzy actual_dsl
|
93
|
+
delta.migrate
|
94
|
+
expect(subject.dump).to match_fuzzy actual_dsl
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'when allow_pk_change option is true' do
|
99
|
+
let(:allow_pk_change) { true }
|
100
|
+
|
101
|
+
it {
|
102
|
+
delta = subject.diff(expected_dsl)
|
103
|
+
expect(delta.differ?).to be_truthy
|
104
|
+
expect(subject.dump).to match_fuzzy actual_dsl
|
105
|
+
delta.migrate
|
106
|
+
expect(subject.dump).to match_fuzzy expected_dsl
|
107
|
+
}
|
108
|
+
end
|
93
109
|
end
|
94
110
|
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
2
|
+
context 'when use references (no change)' do
|
3
|
+
let(:actual_dsl) {
|
4
|
+
erbh(<<-EOS)
|
5
|
+
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
6
|
+
t.<%= cond(5.1, 'bigint', 'integer') %> "products_id"
|
7
|
+
t.<%= cond(5.1, 'bigint', 'integer') %> "user_id"
|
8
|
+
t.index "products_id"
|
9
|
+
t.index "user_id"
|
10
|
+
end
|
11
|
+
EOS
|
12
|
+
}
|
13
|
+
|
14
|
+
let(:expected_dsl) {
|
15
|
+
<<-EOS
|
16
|
+
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
17
|
+
t.references :products, :user, index: true
|
18
|
+
end
|
19
|
+
EOS
|
20
|
+
}
|
21
|
+
|
22
|
+
before { subject.diff(actual_dsl).migrate }
|
23
|
+
subject { client }
|
24
|
+
|
25
|
+
it {
|
26
|
+
delta = subject.diff(expected_dsl)
|
27
|
+
expect(delta.differ?).to be_falsey
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when use references with polymorphic (no change)' do
|
32
|
+
let(:actual_dsl) {
|
33
|
+
erbh(<<-EOS)
|
34
|
+
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
35
|
+
t.<%= cond(5.1, 'bigint', 'integer') %> "products_id"
|
36
|
+
t.string "products_type"
|
37
|
+
t.<%= cond(5.1, 'bigint', 'integer') %> "user_id"
|
38
|
+
t.string "user_type"
|
39
|
+
t.index ["products_type", "products_id"]
|
40
|
+
t.index ["user_type", "user_id"]
|
41
|
+
end
|
42
|
+
EOS
|
43
|
+
}
|
44
|
+
|
45
|
+
let(:expected_dsl) {
|
46
|
+
<<-EOS
|
47
|
+
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
48
|
+
t.references :products, :user, index: true, polymorphic: true
|
49
|
+
end
|
50
|
+
EOS
|
51
|
+
}
|
52
|
+
|
53
|
+
before { subject.diff(actual_dsl).migrate }
|
54
|
+
subject { client }
|
55
|
+
|
56
|
+
it {
|
57
|
+
delta = subject.diff(expected_dsl)
|
58
|
+
expect(delta.differ?).to be_falsey
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when use references with index false (no change)' do
|
63
|
+
let(:actual_dsl) {
|
64
|
+
erbh(<<-EOS)
|
65
|
+
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
66
|
+
t.<%= cond(5.1, 'bigint', 'integer') %> "products_id"
|
67
|
+
t.<%= cond(5.1, 'bigint', 'integer') %> "user_id"
|
68
|
+
end
|
69
|
+
EOS
|
70
|
+
}
|
71
|
+
|
72
|
+
let(:expected_dsl) {
|
73
|
+
<<-EOS
|
74
|
+
create_table "employees", primary_key: "emp_no", force: :cascade do |t|
|
75
|
+
t.references :products, :user, index: false
|
76
|
+
end
|
77
|
+
EOS
|
78
|
+
}
|
79
|
+
|
80
|
+
before { subject.diff(actual_dsl).migrate }
|
81
|
+
subject { client }
|
82
|
+
|
83
|
+
it {
|
84
|
+
delta = subject.diff(expected_dsl)
|
85
|
+
expect(delta.differ?).to be_falsey
|
86
|
+
}
|
87
|
+
end
|
88
|
+
end
|
data/spec/spec_const.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
TEST_MYSQL_HOST = '127.0.0.1'
|
1
|
+
TEST_MYSQL_HOST = ENV['DOCKER_HOST'] ? ENV['DOCKER_HOST'].gsub(%r{\Atcp://|:\d+\z}, '') : '127.0.0.1'
|
2
2
|
TEST_MYSQL_PORT = ENV['MYSQL57'] == '1' ? 13317 : 13316
|
3
3
|
TEST_MYSQL_USER = 'root'
|
4
4
|
TEST_MYSQL_PASS = 'password'
|
5
5
|
|
6
6
|
MYSQL_CLI = "mysql -h #{TEST_MYSQL_HOST} -P #{TEST_MYSQL_PORT} -u #{TEST_MYSQL_USER} -p#{TEST_MYSQL_PASS} 2>/dev/null"
|
7
7
|
|
8
|
-
TEST_PG_HOST = '127.0.0.1'
|
8
|
+
TEST_PG_HOST = ENV['DOCKER_HOST'] ? ENV['DOCKER_HOST'].gsub(%r{\Atcp://|:\d+\z}, '') : '127.0.0.1'
|
9
9
|
TEST_PG_PORT = 15442
|
10
10
|
TEST_PG_USER = 'postgres'
|
11
11
|
TEST_PG_PASS = 'password'
|
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.7.1.
|
4
|
+
version: 0.7.1.beta3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -307,6 +307,7 @@ files:
|
|
307
307
|
- spec/mysql/migrate/migrate_log_file_spec.rb
|
308
308
|
- spec/mysql/migrate/migrate_merge_mode_spec.rb
|
309
309
|
- spec/mysql/migrate/migrate_noop_spec.rb
|
310
|
+
- spec/mysql/migrate/migrate_primary_key_spec.rb
|
310
311
|
- spec/mysql/migrate/migrate_rename_column_spec.rb
|
311
312
|
- spec/mysql/migrate/migrate_rename_table_spec.rb
|
312
313
|
- spec/mysql/migrate/migrate_same_default_null_spec.rb
|
@@ -355,6 +356,7 @@ files:
|
|
355
356
|
- spec/postgresql/migrate/migrate_drop_index_spec.rb
|
356
357
|
- spec/postgresql/migrate/migrate_drop_table_spec.rb
|
357
358
|
- spec/postgresql/migrate/migrate_ext_cols_spec.rb
|
359
|
+
- spec/postgresql/migrate/migrate_references_spec.rb
|
358
360
|
- spec/postgresql/migrate/migrate_rename_column_spec.rb
|
359
361
|
- spec/postgresql/migrate/migrate_rename_table_spec.rb
|
360
362
|
- spec/postgresql/migrate/migrate_same_spec.rb
|
@@ -387,7 +389,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
387
389
|
version: 1.3.1
|
388
390
|
requirements: []
|
389
391
|
rubyforge_project:
|
390
|
-
rubygems_version: 2.
|
392
|
+
rubygems_version: 2.5.2
|
391
393
|
signing_key:
|
392
394
|
specification_version: 4
|
393
395
|
summary: Ridgepole is a tool to manage DB schema.
|
@@ -457,6 +459,7 @@ test_files:
|
|
457
459
|
- spec/mysql/migrate/migrate_log_file_spec.rb
|
458
460
|
- spec/mysql/migrate/migrate_merge_mode_spec.rb
|
459
461
|
- spec/mysql/migrate/migrate_noop_spec.rb
|
462
|
+
- spec/mysql/migrate/migrate_primary_key_spec.rb
|
460
463
|
- spec/mysql/migrate/migrate_rename_column_spec.rb
|
461
464
|
- spec/mysql/migrate/migrate_rename_table_spec.rb
|
462
465
|
- spec/mysql/migrate/migrate_same_default_null_spec.rb
|
@@ -505,6 +508,7 @@ test_files:
|
|
505
508
|
- spec/postgresql/migrate/migrate_drop_index_spec.rb
|
506
509
|
- spec/postgresql/migrate/migrate_drop_table_spec.rb
|
507
510
|
- spec/postgresql/migrate/migrate_ext_cols_spec.rb
|
511
|
+
- spec/postgresql/migrate/migrate_references_spec.rb
|
508
512
|
- spec/postgresql/migrate/migrate_rename_column_spec.rb
|
509
513
|
- spec/postgresql/migrate/migrate_rename_table_spec.rb
|
510
514
|
- spec/postgresql/migrate/migrate_same_spec.rb
|