aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2015-02-10 22:31:35 +0900
committerRyuta Kamizono <kamipo@gmail.com>2015-02-11 10:26:23 +0900
commitbb2a7c38d8db5be7ac361ef208afba889370a5a9 (patch)
treeb09c9c40859aa9cefe440cfbbfb69feb4b2cbf5d /activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
parent17d9996c91918df4c32b8ed7c67c2bbe715cfc9d (diff)
downloadrails-bb2a7c38d8db5be7ac361ef208afba889370a5a9.tar.gz
rails-bb2a7c38d8db5be7ac361ef208afba889370a5a9.tar.bz2
rails-bb2a7c38d8db5be7ac361ef208afba889370a5a9.zip
Refactor `quote_default_expression`
`quote_default_expression` and `quote_default_value` are almost the same handling for do not quote default function of `:uuid` columns. Rename `quote_default_value` to `quote_default_expression`, and remove duplicate code.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb12
1 files changed, 2 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
index 750eaeca92..81fde18f64 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
@@ -9,14 +9,6 @@ module ActiveRecord
o.sql_type << '[]' if o.array
super
end
-
- def quote_default_expression(value, column)
- if column.type == :uuid && value =~ /\(\)/
- value
- else
- super
- end
- end
end
module SchemaStatements
@@ -440,7 +432,7 @@ module ActiveRecord
# cast the default to the columns type, which leaves us with a default like "default NULL::character varying".
execute alter_column_query % "DROP DEFAULT"
else
- execute alter_column_query % "SET DEFAULT #{quote_default_value(default, column)}"
+ execute alter_column_query % "SET DEFAULT #{quote_default_expression(default, column)}"
end
end
@@ -448,7 +440,7 @@ module ActiveRecord
clear_cache!
unless null || default.nil?
column = column_for(table_name, column_name)
- execute("UPDATE #{quote_table_name(table_name)} SET #{quote_column_name(column_name)}=#{quote_default_value(default, column)} WHERE #{quote_column_name(column_name)} IS NULL") if column
+ execute("UPDATE #{quote_table_name(table_name)} SET #{quote_column_name(column_name)}=#{quote_default_expression(default, column)} WHERE #{quote_column_name(column_name)} IS NULL") if column
end
execute("ALTER TABLE #{quote_table_name(table_name)} ALTER #{quote_column_name(column_name)} #{null ? 'DROP' : 'SET'} NOT NULL")
end