mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
pg, change_column_default
accepts []
. Closes #11586.
This commit is contained in:
parent
711af75234
commit
096be96db8
4 changed files with 18 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -187,8 +187,8 @@ module ActiveRecord
|
|||
def quote_default_value(value, column) #:nodoc:
|
||||
if column.type == :uuid && value =~ /\(\)/
|
||||
value
|
||||
else
|
||||
quote(value)
|
||||
else
|
||||
quote(value, column)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -405,6 +405,7 @@ module ActiveRecord
|
|||
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
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ class PostgresqlArrayTest < ActiveRecord::TestCase
|
|||
|
||||
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 @@ class PostgresqlArrayTest < ActiveRecord::TestCase
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue