1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #23961 from kamipo/exclude_name_and_type_from_prepare_column_options

Exclude `:name` and `:type` from `prepare_column_options`
This commit is contained in:
Rafael França 2016-03-01 15:33:05 -03:00
commit 7acb695653
3 changed files with 8 additions and 8 deletions

View file

@ -7,15 +7,16 @@ module ActiveRecord
# Adapter level by over-writing this code inside the database specific adapters
module ColumnDumper
def column_spec(column)
spec = prepare_column_options(column)
(spec.keys - [:name, :type]).each{ |k| spec[k].insert(0, "#{k}: ")}
spec = Hash[prepare_column_options(column).map { |k, v| [k, "#{k}: #{v}"] }]
spec[:name] = column.name.inspect
spec[:type] = schema_type(column).to_s
spec
end
def column_spec_for_primary_key(column)
return if column.type == :integer
spec = { id: schema_type(column).inspect }
spec.merge!(prepare_column_options(column).delete_if { |key, _| [:name, :type].include?(key) })
spec.merge!(prepare_column_options(column))
end
# This can be overridden on an Adapter level basis to support other
@ -23,9 +24,6 @@ module ActiveRecord
# PostgreSQL::ColumnDumper)
def prepare_column_options(column)
spec = {}
spec[:name] = column.name.inspect
spec[:type] = schema_type(column).to_s
spec[:null] = 'false' unless column.null
if limit = schema_limit(column)
spec[:limit] = limit
@ -42,6 +40,8 @@ module ActiveRecord
default = schema_default(column) if column.has_default?
spec[:default] = default unless default.nil?
spec[:null] = 'false' unless column.null
if collation = schema_collation(column)
spec[:collation] = collation
end

View file

@ -13,7 +13,7 @@ module ActiveRecord
return if spec.empty?
else
spec[:id] = schema_type(column).inspect
spec.merge!(prepare_column_options(column).delete_if { |key, _| [:name, :type, :null].include?(key) })
spec.merge!(prepare_column_options(column).delete_if { |key, _| key == :null })
end
spec
end

View file

@ -12,7 +12,7 @@ module ActiveRecord
spec[:default] = schema_default(column) || 'nil'
else
spec[:id] = schema_type(column).inspect
spec.merge!(prepare_column_options(column).delete_if { |key, _| [:name, :type, :null].include?(key) })
spec.merge!(prepare_column_options(column).delete_if { |key, _| key == :null })
end
spec
end