activerecord-postgresql-extensions 0.8.0 → 0.9.0

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: 19e521403cd36cf7625c8ccd2824cae61db46ca6
4
- data.tar.gz: 068388117de07b1cf28a342b6135cf1879ba7623
3
+ metadata.gz: 884595fe6ca7f7decbe13587cfd320816f6fe1aa
4
+ data.tar.gz: e655d1e1363ce3089488c383a1a86bf5dc7ac2a1
5
5
  SHA512:
6
- metadata.gz: 2644c7baf1ada6bae7f49c7755dc81de31db289294ddff377c7ff990a4a73f4ad3614dd9bee0981d2a463743ce50536909da4b48ff4ed885a7d1c5bb945c03b1
7
- data.tar.gz: 9deb3cd3329c7c28be94d1cf162e597e9176cfeccdf82353635153e7024b74ae739b22666760f528c93d429a95b7ab859354b73b792bfc9928ae54b6e9b7d284
6
+ metadata.gz: 1982f5f26ac5b40052c3d7a92000e6594c0a1d9b44c828e802c6f91623a106428129d74316529b9591754560254ce32f788558984f46f5bf35c95c5d0958b7ae
7
+ data.tar.gz: b3b04fa975238f7381d3f324d32bd195601fd7c38506983be39fafbe2c8656567ff12e4750459fed4f8de5a7ff2e2516cfa4c6a65e814fe7937397403f68cdc7
@@ -712,6 +712,21 @@ module ActiveRecord
712
712
  end
713
713
  alias_method_chain :add_column_options!, :expression
714
714
 
715
+ def change_column_with_using(table_name, column_name, type, options = {}) #:nodoc:
716
+ if options.has_key?(:using) && options[:using].present?
717
+ clear_cache!
718
+ quoted_table_name = quote_table_name(table_name)
719
+
720
+ execute "ALTER TABLE #{quoted_table_name} ALTER COLUMN #{quote_column_name(column_name)} TYPE #{type_to_sql(type, options[:limit], options[:precision], options[:scale])} USING #{options[:using]}"
721
+
722
+ change_column_default(table_name, column_name, options[:default]) if options_include_default?(options)
723
+ change_column_null(table_name, column_name, options[:null], options[:default]) if options.key?(:null)
724
+ else
725
+ change_column_without_using(table_name, column_name, type, options)
726
+ end
727
+ end
728
+ alias_method_chain :change_column, :using
729
+
715
730
  def change_column_default_with_expression(table_name, column_name, default) #:nodoc:
716
731
  if default.is_a?(Hash) && default.has_key?(:expression)
717
732
  execute "ALTER TABLE #{quote_table_name(table_name)} ALTER COLUMN #{quote_column_name(column_name)} SET DEFAULT #{default[:expression]};"
@@ -1,7 +1,7 @@
1
1
 
2
2
  module ActiveRecord
3
3
  module PostgreSQLExtensions
4
- VERSION = "0.8.0"
4
+ VERSION = "0.9.0"
5
5
  end
6
6
  end
7
7
 
@@ -186,6 +186,28 @@ class AdapterExtensionTests < PostgreSQLExtensionsTestCase
186
186
  end
187
187
  end
188
188
 
189
+ def test_change_column_with_using
190
+ Mig.change_column(:foo, :bar, :integer, :using => '100', :default => 100)
191
+ Mig.change_column(:foo, :bar, :integer, :using => '100', :default => {
192
+ :expression => '1 + 1'
193
+ })
194
+
195
+ Mig.change_column(:foo, :bar, :integer, :null => false, :using => '100', :default => {
196
+ :expression => '1 + 1'
197
+ })
198
+
199
+ assert_equal([
200
+ %{ALTER TABLE "foo" ALTER COLUMN "bar" TYPE integer USING 100},
201
+ %{ALTER TABLE "foo" ALTER COLUMN "bar" SET DEFAULT 100},
202
+ %{ALTER TABLE "foo" ALTER COLUMN "bar" TYPE integer USING 100},
203
+ %{ALTER TABLE "foo" ALTER COLUMN "bar" SET DEFAULT 1 + 1;},
204
+ %{ALTER TABLE "foo" ALTER COLUMN "bar" TYPE integer USING 100},
205
+ %{ALTER TABLE "foo" ALTER COLUMN "bar" SET DEFAULT 1 + 1;},
206
+ %{UPDATE "foo" SET "bar" = 1 + 1 WHERE "bar" IS NULL},
207
+ %{ALTER TABLE "foo" ALTER "bar" SET NOT NULL},
208
+ ], statements)
209
+ end
210
+
189
211
  def test_change_column_with_expression
190
212
  Mig.change_column(:foo, :bar, :integer, :default => 100)
191
213
  Mig.change_column(:foo, :bar, :integer, :default => {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-postgresql-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - J Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-28 00:00:00.000000000 Z
11
+ date: 2015-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  version: '0'
111
111
  requirements: []
112
112
  rubyforge_project:
113
- rubygems_version: 2.2.3
113
+ rubygems_version: 2.4.6
114
114
  signing_key:
115
115
  specification_version: 4
116
116
  summary: A whole bunch of extensions the ActiveRecord PostgreSQL adapter.