Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb
  • Loading branch information...
commit b489dbf9e361c73397bd457edaae9fe3f0bc0479 1 parent 23fb530
@senny senny authored
View
6 activerecord/CHANGELOG.md
@@ -1,3 +1,9 @@
+* `change_column_default` allows `[]` as argument to `change_column_default`.
+
+ Fixes #11586.
+
+ *Yves Senn*
+
* Fix `PostgreSQLAdapter::OID::Float#type_cast` to convert Infinity and
NaN PostgreSQL values into a native Ruby `Float::INFINITY` and `Float::NAN`
View
2  activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb
@@ -188,7 +188,7 @@ def quote_default_value(value, column) #:nodoc:
if column.type == :uuid && value =~ /\(\)/
value
else
- quote(value)
+ quote(value, column)
end
end
end
View
1  activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
@@ -411,6 +411,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
@@ -58,7 +58,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' }
@@ -77,6 +77,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 b489dbf

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