Skip to content
Browse files

pg, `change_column_default` accepts `[]`. Closes #11586.

  • Loading branch information...
1 parent 711af75 commit 096be96db894854a199ce8cf9a8edeca0f203966 @senny senny committed May 12, 2014
View
6 activerecord/CHANGELOG.md
@@ -1,3 +1,9 @@
+* `change_column_default` allows `[]` as argument to `change_column_default`.
+
+ Fixes #11586.
+
+ *Yves Senn*
+
* Handle `name` and `"char"` column types in the PostgreSQL adapter.
`name` and `"char"` are special character types used internally by
View
4 activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb
@@ -187,8 +187,8 @@ def quoted_date(value) #:nodoc:
def quote_default_value(value, column) #:nodoc:
if column.type == :uuid && value =~ /\(\)/
value
- else
- quote(value)
+ else
+ quote(value, column)
end
end
end
View
1 activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
@@ -405,6 +405,7 @@ def change_column(table_name, column_name, type, options = {})
def change_column_default(table_name, column_name, default)
clear_cache!
column = column_for(table_name, column_name)
+
execute "ALTER TABLE #{quote_table_name(table_name)} ALTER COLUMN #{quote_column_name(column_name)} SET DEFAULT #{quote_default_value(default, column)}" if column
end
View
10 activerecord/test/cases/adapters/postgresql/array_test.rb
@@ -61,7 +61,7 @@ def test_default_strings
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: "{}"
+ @connection.change_column :pg_arrays, :snippets, :text, array: true, default: []
PgArray.reset_column_information
column = PgArray.columns.find { |c| c.name == 'snippets' }
@@ -80,6 +80,14 @@ def test_change_column_cant_make_non_array_column_to_array
end
end
+ def test_change_column_default_with_array
+ @connection.change_column_default :pg_arrays, :tags, []
+
+ PgArray.reset_column_information
+ column = PgArray.columns_hash['tags']
+ assert_equal [], column.default
+ end
+
def test_type_cast_array
data = '{1,2,3}'
oid_type = @column.instance_variable_get('@oid_type').subtype

0 comments on commit 096be96

Please sign in to comment.
Something went wrong with that request. Please try again.