aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-11-28 17:13:30 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-11-28 17:13:30 -0200
commitb2566429fe01d1037e525c78b3bbfc7f53d8d0a7 (patch)
tree6372d3dd3e9f9b07c0c1d72dcc003ecbb1a5c052 /activerecord
parent457fc61cec2b3ef2224ef673ae3e72d7d35c88ce (diff)
parent66cc7ce67c4f48f62377ad1a972581c35bcc8373 (diff)
downloadrails-b2566429fe01d1037e525c78b3bbfc7f53d8d0a7.tar.gz
rails-b2566429fe01d1037e525c78b3bbfc7f53d8d0a7.tar.bz2
rails-b2566429fe01d1037e525c78b3bbfc7f53d8d0a7.zip
Merge pull request #17799 from kamipo/refactor_add_column_options
Refactor `add_column_options!`, to move the quoting of default value for :uuid in `quote_value`.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_creation.rb4
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb16
2 files changed, 14 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_creation.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_creation.rb
index 792d49da6f..5c95b95184 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_creation.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_creation.rb
@@ -81,7 +81,7 @@ module ActiveRecord
end
def add_column_options!(sql, options)
- sql << " DEFAULT #{quote_value(options[:default], options[:column])}" if options_include_default?(options)
+ sql << " DEFAULT #{quote_default_expression(options[:default], options[:column])}" if options_include_default?(options)
# must explicitly check for :null to allow change_column to work on migrations
if options[:null] == false
sql << " NOT NULL"
@@ -92,7 +92,7 @@ module ActiveRecord
sql
end
- def quote_value(value, column)
+ def quote_default_expression(value, column)
column.sql_type ||= type_to_sql(column.type, column.limit, column.precision, column.scale)
column.cast_type ||= type_for_column(column)
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 dba905ed56..f29b793a3f 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
@@ -13,14 +13,22 @@ module ActiveRecord
sql
end
+ def column_options(o)
+ column_options = super
+ column_options[:array] = o.array
+ column_options
+ end
+
def add_column_options!(sql, options)
- if options[:array] || options[:column].try(:array)
+ if options[:array]
sql << '[]'
end
+ super
+ end
- column = options.fetch(:column) { return super }
- if column.type == :uuid && options[:default] =~ /\(\)/
- sql << " DEFAULT #{options[:default]}"
+ def quote_default_expression(value, column)
+ if column.type == :uuid && value =~ /\(\)/
+ value
else
super
end