ridgepole 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ridgepole/diff.rb +12 -4
- data/lib/ridgepole/version.rb +1 -1
- data/spec/migrate/migrate_change_index4_spec.rb +116 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56ee14dd171b5e6888ea56c015bbc37c65105ec6
|
4
|
+
data.tar.gz: 39425456d6e6a931918122ef2791f55f17e03154
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be023093493f6c5ab36f58e13f7a7c4ea1482c7f9b3955d83a0727627297921cc5cf380e4f7252a16a34cb7ca409468665421cc13383c3bf55abaf5f2a1182fc
|
7
|
+
data.tar.gz: ac0a15b7d6e76bccdcb07df562cb9e7f8e16d835761d80c3783c4def499da72e35b57f2d5d5b9dc449cd9b8203a309b63e1203b3f43a61839bc870d2be45fd6d
|
data/lib/ridgepole/diff.rb
CHANGED
@@ -75,7 +75,7 @@ class Ridgepole::Diff
|
|
75
75
|
|
76
76
|
scan_options_change(table_name, from[:options], to[:options], table_delta)
|
77
77
|
scan_definition_change(from[:definition], to[:definition], from[:indices], table_delta)
|
78
|
-
scan_indices_change(from[:indices], to[:indices], to[:definition], table_delta)
|
78
|
+
scan_indices_change(from[:indices], to[:indices], to[:definition], table_delta, from[:options], to[:options])
|
79
79
|
|
80
80
|
unless table_delta.empty?
|
81
81
|
delta[:change] ||= {}
|
@@ -171,7 +171,7 @@ class Ridgepole::Diff
|
|
171
171
|
end
|
172
172
|
end
|
173
173
|
|
174
|
-
def scan_indices_change(from, to, to_columns, table_delta)
|
174
|
+
def scan_indices_change(from, to, to_columns, table_delta, from_table_options, to_table_options)
|
175
175
|
from = (from || {}).dup
|
176
176
|
to = (to || {}).dup
|
177
177
|
indices_delta = {}
|
@@ -197,7 +197,7 @@ class Ridgepole::Diff
|
|
197
197
|
indices_delta[:add][index_name] = to_attrs
|
198
198
|
|
199
199
|
unless @options[:merge]
|
200
|
-
if from_attrs[:column_name]
|
200
|
+
if columns_all_include?(from_attrs[:column_name], to_columns.keys, to_table_options)
|
201
201
|
indices_delta[:delete] ||= {}
|
202
202
|
indices_delta[:delete][index_name] = from_attrs
|
203
203
|
end
|
@@ -211,7 +211,7 @@ class Ridgepole::Diff
|
|
211
211
|
|
212
212
|
unless @options[:merge]
|
213
213
|
from.each do |index_name, from_attrs|
|
214
|
-
if from_attrs[:column_name]
|
214
|
+
if columns_all_include?(from_attrs[:column_name], to_columns.keys, to_table_options)
|
215
215
|
indices_delta[:delete] ||= {}
|
216
216
|
indices_delta[:delete][index_name] = from_attrs
|
217
217
|
end
|
@@ -246,4 +246,12 @@ class Ridgepole::Diff
|
|
246
246
|
# XXX: MySQL only?
|
247
247
|
opts[:using] = :btree unless opts.has_key?(:using)
|
248
248
|
end
|
249
|
+
|
250
|
+
def columns_all_include?(expected_columns, actual_columns, table_options)
|
251
|
+
if table_options[:id] != false
|
252
|
+
actual_columns = actual_columns + [(table_options[:primary_key] || 'id').to_s]
|
253
|
+
end
|
254
|
+
|
255
|
+
expected_columns.all? {|i| actual_columns.include?(i) }
|
256
|
+
end
|
249
257
|
end
|
data/lib/ridgepole/version.rb
CHANGED
@@ -0,0 +1,116 @@
|
|
1
|
+
describe 'Ridgepole::Client#diff -> migrate' do
|
2
|
+
context 'when change index (same name)' do
|
3
|
+
let(:actual_dsl) {
|
4
|
+
<<-RUBY
|
5
|
+
create_table "salaries", force: true do |t|
|
6
|
+
t.integer "emp_no", null: false
|
7
|
+
t.integer "salary", null: false
|
8
|
+
t.date "from_date", null: false
|
9
|
+
t.date "to_date", null: false
|
10
|
+
end
|
11
|
+
|
12
|
+
add_index "salaries", ["emp_no", "id"], name: "emp_no", using: :btree
|
13
|
+
RUBY
|
14
|
+
}
|
15
|
+
|
16
|
+
let(:expected_dsl) {
|
17
|
+
<<-RUBY
|
18
|
+
create_table "salaries", force: true do |t|
|
19
|
+
t.integer "emp_no", null: false
|
20
|
+
t.integer "salary", null: false
|
21
|
+
t.date "from_date", null: false
|
22
|
+
t.date "to_date", null: false
|
23
|
+
end
|
24
|
+
|
25
|
+
add_index "salaries", ["salary", "id"], name: "emp_no", using: :btree
|
26
|
+
RUBY
|
27
|
+
}
|
28
|
+
|
29
|
+
before { subject.diff(actual_dsl).migrate }
|
30
|
+
subject { client }
|
31
|
+
|
32
|
+
it {
|
33
|
+
delta = subject.diff(expected_dsl)
|
34
|
+
expect(delta.differ?).to be_truthy
|
35
|
+
expect(subject.dump.delete_empty_lines).to eq actual_dsl.strip_heredoc.strip.delete_empty_lines
|
36
|
+
delta.migrate
|
37
|
+
expect(subject.dump.delete_empty_lines).to eq expected_dsl.strip_heredoc.strip.delete_empty_lines
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when change index (same name) (2)' do
|
42
|
+
let(:actual_dsl) {
|
43
|
+
<<-RUBY
|
44
|
+
create_table "salaries", id: false, force: true do |t|
|
45
|
+
t.integer "emp_no", null: false
|
46
|
+
t.integer "salary", null: false
|
47
|
+
t.date "from_date", null: false
|
48
|
+
t.date "to_date", null: false
|
49
|
+
end
|
50
|
+
|
51
|
+
add_index "salaries", ["emp_no"], name: "emp_no", using: :btree
|
52
|
+
RUBY
|
53
|
+
}
|
54
|
+
|
55
|
+
let(:expected_dsl) {
|
56
|
+
<<-RUBY
|
57
|
+
create_table "salaries", id: false, force: true do |t|
|
58
|
+
t.integer "emp_no", null: false
|
59
|
+
t.integer "salary", null: false
|
60
|
+
t.date "from_date", null: false
|
61
|
+
t.date "to_date", null: false
|
62
|
+
end
|
63
|
+
|
64
|
+
add_index "salaries", ["salary"], name: "emp_no", using: :btree
|
65
|
+
RUBY
|
66
|
+
}
|
67
|
+
|
68
|
+
before { subject.diff(actual_dsl).migrate }
|
69
|
+
subject { client }
|
70
|
+
|
71
|
+
it {
|
72
|
+
delta = subject.diff(expected_dsl)
|
73
|
+
expect(delta.differ?).to be_truthy
|
74
|
+
expect(subject.dump.delete_empty_lines).to eq actual_dsl.strip_heredoc.strip.delete_empty_lines
|
75
|
+
delta.migrate
|
76
|
+
expect(subject.dump.delete_empty_lines).to eq expected_dsl.strip_heredoc.strip.delete_empty_lines
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'when change index (same name) (3)' do
|
81
|
+
let(:actual_dsl) {
|
82
|
+
<<-RUBY
|
83
|
+
create_table "salaries", primary_key: "emp_no", force: true do |t|
|
84
|
+
t.integer "salary", null: false
|
85
|
+
t.date "from_date", null: false
|
86
|
+
t.date "to_date", null: false
|
87
|
+
end
|
88
|
+
|
89
|
+
add_index "salaries", ["salary", "emp_no"], name: "emp_no", using: :btree
|
90
|
+
RUBY
|
91
|
+
}
|
92
|
+
|
93
|
+
let(:expected_dsl) {
|
94
|
+
<<-RUBY
|
95
|
+
create_table "salaries", primary_key: "emp_no", force: true do |t|
|
96
|
+
t.integer "salary", null: false
|
97
|
+
t.date "from_date", null: false
|
98
|
+
t.date "to_date", null: false
|
99
|
+
end
|
100
|
+
|
101
|
+
add_index "salaries", ["from_date", "emp_no"], name: "emp_no", using: :btree
|
102
|
+
RUBY
|
103
|
+
}
|
104
|
+
|
105
|
+
before { subject.diff(actual_dsl).migrate }
|
106
|
+
subject { client }
|
107
|
+
|
108
|
+
it {
|
109
|
+
delta = subject.diff(expected_dsl)
|
110
|
+
expect(delta.differ?).to be_truthy
|
111
|
+
expect(subject.dump.delete_empty_lines).to eq actual_dsl.strip_heredoc.strip.delete_empty_lines
|
112
|
+
delta.migrate
|
113
|
+
expect(subject.dump.delete_empty_lines).to eq expected_dsl.strip_heredoc.strip.delete_empty_lines
|
114
|
+
}
|
115
|
+
end
|
116
|
+
end
|
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.4.
|
4
|
+
version: 0.4.5
|
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-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -136,6 +136,7 @@ files:
|
|
136
136
|
- spec/migrate/migrate_change_column_spec.rb
|
137
137
|
- spec/migrate/migrate_change_index2_spec.rb
|
138
138
|
- spec/migrate/migrate_change_index3_spec.rb
|
139
|
+
- spec/migrate/migrate_change_index4_spec.rb
|
139
140
|
- spec/migrate/migrate_change_index_spec.rb
|
140
141
|
- spec/migrate/migrate_change_table_option_spec.rb
|
141
142
|
- spec/migrate/migrate_create_index_spec.rb
|
@@ -186,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
187
|
version: '0'
|
187
188
|
requirements: []
|
188
189
|
rubyforge_project:
|
189
|
-
rubygems_version: 2.
|
190
|
+
rubygems_version: 2.0.14
|
190
191
|
signing_key:
|
191
192
|
specification_version: 4
|
192
193
|
summary: Ridgepole is a tool to manage DB schema.
|
@@ -204,6 +205,7 @@ test_files:
|
|
204
205
|
- spec/migrate/migrate_change_column_spec.rb
|
205
206
|
- spec/migrate/migrate_change_index2_spec.rb
|
206
207
|
- spec/migrate/migrate_change_index3_spec.rb
|
208
|
+
- spec/migrate/migrate_change_index4_spec.rb
|
207
209
|
- spec/migrate/migrate_change_index_spec.rb
|
208
210
|
- spec/migrate/migrate_change_table_option_spec.rb
|
209
211
|
- spec/migrate/migrate_create_index_spec.rb
|