aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2015-02-14 07:46:10 +0900
committerRyuta Kamizono <kamipo@gmail.com>2015-02-19 11:24:01 +0900
commit949b1336266d3de25d5d84911c7a43f7da3121bf (patch)
tree6a7f77eb1e7955fee3b3f3dc7f16a7153525121a /activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
parent95ee93892a07f90fdfd503c7ea07abf0fb397bec (diff)
downloadrails-949b1336266d3de25d5d84911c7a43f7da3121bf.tar.gz
rails-949b1336266d3de25d5d84911c7a43f7da3121bf.tar.bz2
rails-949b1336266d3de25d5d84911c7a43f7da3121bf.zip
Should handle array option for `:cast_as`
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb12
1 files changed, 8 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
index 81fde18f64..87122fc00e 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
@@ -407,12 +407,16 @@ module ActiveRecord
def change_column(table_name, column_name, type, options = {})
clear_cache!
quoted_table_name = quote_table_name(table_name)
+ quoted_column_name = quote_column_name(column_name)
sql_type = type_to_sql(type, options[:limit], options[:precision], options[:scale])
sql_type << "[]" if options[:array]
- sql = "ALTER TABLE #{quoted_table_name} ALTER COLUMN #{quote_column_name(column_name)} TYPE #{sql_type}"
- sql << " USING #{options[:using]}" if options[:using]
- if options[:cast_as]
- sql << " USING CAST(#{quote_column_name(column_name)} AS #{type_to_sql(options[:cast_as], options[:limit], options[:precision], options[:scale])})"
+ sql = "ALTER TABLE #{quoted_table_name} ALTER COLUMN #{quoted_column_name} TYPE #{sql_type}"
+ if options[:using]
+ sql << " USING #{options[:using]}"
+ elsif options[:cast_as]
+ cast_as_type = type_to_sql(options[:cast_as], options[:limit], options[:precision], options[:scale])
+ cast_as_type << "[]" if options[:array]
+ sql << " USING CAST(#{quoted_column_name} AS #{cast_as_type})"
end
execute sql