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

@ -435,6 +435,9 @@ def change_column(table_name, column_name, type, options = {})
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)