ridgepole 0.6.5.beta10 → 0.6.5.beta11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 145c30f16a0e8c3c7aa2a56ded6db3bbbabded5f
4
- data.tar.gz: 577cacc926ed818f403cc066cc6f299f8faea54c
3
+ metadata.gz: 9d9f5c2109909e6a196908e0a0990e62a5b00030
4
+ data.tar.gz: 30a539a691cf72848afa5ba2ef81c9ce8a7dc2ce
5
5
  SHA512:
6
- metadata.gz: cefea2b7ea2341fe5dd3155b81c34ea947fe4fd5e1b71ebf5436aa43d27e688d6f596b1834526617d13af74e2d8e94395ff7d9dbd63506221b49f18ebb48bd3f
7
- data.tar.gz: 9d8070a7d1cad32919673def208f8bf66956fccb3c86fe4973272d5c82ae1444dfc12dd32b2cff1e7ccf499943b77300366f2b8a135405fed9e52b6ff76c8682
6
+ metadata.gz: a404a78077b95bd8feeac8e3cabc25910440784f9b9c1db0fa144332a9352a47465b86e0f24df5f08ecc9003e405db9e73b282cb4abd085a8fc595f22763d9c6
7
+ data.tar.gz: 597e212b753edf77db08483b1b827951dd893c5b129b75a7fd509ac317c3b49241f3797324774de04283faac3b2527ae1640c838e70e9899430b6062c45bbb71
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Ridgepole
2
- VERSION = '0.6.5.beta10'
2
+ VERSION = '0.6.5.beta11'
3
3
  end
@@ -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, :after=>"club_id"})
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, :after=>"hire_date"})
171
- t.column("updated_at", :date, {:after=>"age"})
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, :after=>"dept_no"})
149
- add_column("dept_emp", "to_date", :date, {:null=>false, :after=>"from_date"})
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, :after=>"emp_no"})
152
- add_column("dept_manager", "to_date", :date, {:null=>false, :after=>"from_date"})
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, :after=>"first_name"})
155
- add_column("employees", "hire_date", :date, {:null=>false, :after=>"last_name"})
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ridgepole
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5.beta10
4
+ version: 0.6.5.beta11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara