ridgepole 0.6.5.beta10 → 0.6.5.beta11
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d9f5c2109909e6a196908e0a0990e62a5b00030
|
4
|
+
data.tar.gz: 30a539a691cf72848afa5ba2ef81c9ce8a7dc2ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a404a78077b95bd8feeac8e3cabc25910440784f9b9c1db0fa144332a9352a47465b86e0f24df5f08ecc9003e405db9e73b282cb4abd085a8fc595f22763d9c6
|
7
|
+
data.tar.gz: 597e212b753edf77db08483b1b827951dd893c5b129b75a7fd509ac317c3b49241f3797324774de04283faac3b2527ae1640c838e70e9899430b6062c45bbb71
|
data/lib/ridgepole/diff.rb
CHANGED
@@ -147,6 +147,18 @@ class Ridgepole::Diff
|
|
147
147
|
priv_column_name = column_name
|
148
148
|
end
|
149
149
|
|
150
|
+
if self.class.postgresql?
|
151
|
+
added_size = 0
|
152
|
+
to.reverse_each.with_index do |(column_name, to_attrs), i|
|
153
|
+
if to_attrs[:options].delete(:after)
|
154
|
+
if added_size != i
|
155
|
+
@logger.warn("[WARNING] PostgreSQL doesn't support adding a new column except for the last position. #{table_name}.#{column_name} will be added to the last.")
|
156
|
+
end
|
157
|
+
added_size += 1
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
150
162
|
unless @options[:merge]
|
151
163
|
from.each do |column_name, from_attrs|
|
152
164
|
definition_delta[:delete] ||= {}
|
@@ -382,4 +394,8 @@ class Ridgepole::Diff
|
|
382
394
|
|
383
395
|
diffy.to_s(:text).gsub(/\s+\z/m, '')
|
384
396
|
end
|
397
|
+
|
398
|
+
def self.postgresql?
|
399
|
+
defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
|
400
|
+
end
|
385
401
|
end
|
data/lib/ridgepole/version.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
describe 'Ridgepole::Client.diff' do
|
2
|
+
before do
|
3
|
+
allow(Ridgepole::Diff).to receive(:postgresql?).and_return(true)
|
4
|
+
end
|
5
|
+
|
2
6
|
context 'when change column' do
|
3
7
|
let(:actual_dsl) {
|
4
8
|
<<-EOS
|
@@ -148,4 +152,57 @@ describe 'Ridgepole::Client.diff' do
|
|
148
152
|
EOS
|
149
153
|
}
|
150
154
|
end
|
155
|
+
|
156
|
+
describe 'column position warning' do
|
157
|
+
subject { Ridgepole::Client }
|
158
|
+
|
159
|
+
context 'when adding a column to the last' do
|
160
|
+
let(:actual_dsl) { <<-EOS }
|
161
|
+
create_table "users", force: :cascade do |t|
|
162
|
+
t.string "name", null: false
|
163
|
+
end
|
164
|
+
EOS
|
165
|
+
|
166
|
+
let(:expected_dsl) { <<-EOS }
|
167
|
+
create_table "users", force: :cascade do |t|
|
168
|
+
t.string "name", null: false
|
169
|
+
t.datetime "created_at", null: false
|
170
|
+
t.datetime "updated_at", null: false
|
171
|
+
end
|
172
|
+
EOS
|
173
|
+
|
174
|
+
it "doesn't warn anything" do
|
175
|
+
expect(Ridgepole::Logger.instance).to_not receive(:warn)
|
176
|
+
delta = subject.diff(actual_dsl, expected_dsl)
|
177
|
+
expect(delta).to be_differ
|
178
|
+
expect(delta.script).to_not include('after')
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context 'when adding a column to the middle' do
|
183
|
+
let(:actual_dsl) { <<-EOS }
|
184
|
+
create_table "users", force: :cascade do |t|
|
185
|
+
t.datetime "created_at", null: false
|
186
|
+
end
|
187
|
+
EOS
|
188
|
+
|
189
|
+
let(:expected_dsl) { <<-EOS }
|
190
|
+
create_table "users", force: :cascade do |t|
|
191
|
+
t.string "name", null: false
|
192
|
+
t.integer "age", null: false
|
193
|
+
t.datetime "created_at", null: false
|
194
|
+
t.datetime "updated_at", null: false
|
195
|
+
end
|
196
|
+
EOS
|
197
|
+
|
198
|
+
it 'warns position' do
|
199
|
+
expect(Ridgepole::Logger.instance).to receive(:warn).with(/PostgreSQL doesn't support adding a new column .* users\.name/)
|
200
|
+
expect(Ridgepole::Logger.instance).to receive(:warn).with(/PostgreSQL doesn't support adding a new column .* users\.age/)
|
201
|
+
expect(Ridgepole::Logger.instance).to_not receive(:warn)
|
202
|
+
delta = subject.diff(actual_dsl, expected_dsl)
|
203
|
+
expect(delta).to be_differ
|
204
|
+
expect(delta.script).to_not include('after')
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
151
208
|
end
|
@@ -163,12 +163,12 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
163
163
|
expect(subject.dump).to match_fuzzy actual_dsl
|
164
164
|
expect(delta.script).to match_fuzzy <<-EOS
|
165
165
|
change_table("employee_clubs", {:bulk => true}) do |t|
|
166
|
-
t.column("any_col", :string, {:limit=>255, :null=>false
|
166
|
+
t.column("any_col", :string, {:limit=>255, :null=>false})
|
167
167
|
end
|
168
168
|
|
169
169
|
change_table("employees", {:bulk => true}) do |t|
|
170
|
-
t.column("age", :integer, {:null=>false
|
171
|
-
t.column("updated_at", :date, {
|
170
|
+
t.column("age", :integer, {:null=>false})
|
171
|
+
t.column("updated_at", :date, {})
|
172
172
|
end
|
173
173
|
EOS
|
174
174
|
delta.migrate
|
@@ -145,14 +145,14 @@ describe 'Ridgepole::Client#diff -> migrate' do
|
|
145
145
|
delta = Ridgepole::Client.diff(actual_dsl, expected_dsl, reverse: true)
|
146
146
|
expect(delta.differ?).to be_truthy
|
147
147
|
expect(delta.script).to match_fuzzy <<-EOS
|
148
|
-
add_column("dept_emp", "from_date", :date, {:null=>false
|
149
|
-
add_column("dept_emp", "to_date", :date, {:null=>false
|
148
|
+
add_column("dept_emp", "from_date", :date, {:null=>false})
|
149
|
+
add_column("dept_emp", "to_date", :date, {:null=>false})
|
150
150
|
|
151
|
-
add_column("dept_manager", "from_date", :date, {:null=>false
|
152
|
-
add_column("dept_manager", "to_date", :date, {:null=>false
|
151
|
+
add_column("dept_manager", "from_date", :date, {:null=>false})
|
152
|
+
add_column("dept_manager", "to_date", :date, {:null=>false})
|
153
153
|
|
154
|
-
add_column("employees", "last_name", :string, {:limit=>16, :null=>false
|
155
|
-
add_column("employees", "hire_date", :date, {:null=>false
|
154
|
+
add_column("employees", "last_name", :string, {:limit=>16, :null=>false})
|
155
|
+
add_column("employees", "hire_date", :date, {:null=>false})
|
156
156
|
EOS
|
157
157
|
}
|
158
158
|
|