Permalink
Browse files

`change_column` for PG adapter respects `:array` option.

  • Loading branch information...
1 parent c612638 commit 754a373e301d2df0b12a11083405252722bc8366 @senny senny committed Jul 16, 2013
@@ -1,3 +1,7 @@
+* `change_column` for PostgreSQL adapter respects the `:array` option.
+
+ *Yves Senn*
+
* Remove deprecation warning from `attribute_missing` for attributes that are columns.
*Arun Agrawal*
@@ -384,8 +384,9 @@ def add_column(table_name, column_name, type, options = {})
def change_column(table_name, column_name, type, options = {})
clear_cache!
quoted_table_name = quote_table_name(table_name)
-
- execute "ALTER TABLE #{quoted_table_name} ALTER COLUMN #{quote_column_name(column_name)} TYPE #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}"
+ sql_type = type_to_sql(type, options[:limit], options[:precision], options[:scale])
+ sql_type << "[]" if options[:array]
+ execute "ALTER TABLE #{quoted_table_name} ALTER COLUMN #{quote_column_name(column_name)} TYPE #{sql_type}"
change_column_default(table_name, column_name, options[:default]) if options_include_default?(options)
change_column_null(table_name, column_name, options[:null], options[:default]) if options.key?(:null)
@@ -27,6 +27,18 @@ def test_column
assert @column.array
end
+ def test_change_column_with_array
+ @connection.add_column :pg_arrays, :snippets, :string, array: true, default: []
+ @connection.change_column :pg_arrays, :snippets, :text, array: true, default: "{}"
+
+ PgArray.reset_column_information
+ column = PgArray.columns.find { |c| c.name == 'snippets' }
+
+ assert_equal :text, column.type
+ assert_equal [], column.default
+ assert column.array
+ end
+
def test_type_cast_array
assert @column

0 comments on commit 754a373

Please sign in to comment.