aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-11-24 14:29:04 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2014-11-24 14:29:04 -0800
commitcdd90f39d796986dabf1678b3277b230dbe18961 (patch)
treefdf37240eced4f44f265ff335adfedc30e7b2fc0 /activerecord
parent63963801c01279d99930de1cb252a8238909bc0c (diff)
downloadrails-cdd90f39d796986dabf1678b3277b230dbe18961.tar.gz
rails-cdd90f39d796986dabf1678b3277b230dbe18961.tar.bz2
rails-cdd90f39d796986dabf1678b3277b230dbe18961.zip
allow types to be passed in for USING casts
This allows us so abstract the migration from the type that is actually used by Rails. For example, ":string" may be a varchar or something, but the framework does that translation, and the app shouldn't need to know.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb3
1 files changed, 3 insertions, 0 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 208302b365..193c950261 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
@@ -435,6 +435,9 @@ module ActiveRecord
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])})"
+ end
execute sql
change_column_default(table_name, column_name, options[:default]) if options_include_default?(options)