1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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.
This commit is contained in:
Aaron Patterson 2014-11-24 14:29:04 -08:00
parent 63963801c0
commit cdd90f39d7

View file

@ -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)