aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2016-10-11 10:01:40 +0900
committerRyuta Kamizono <kamipo@gmail.com>2016-10-11 10:01:40 +0900
commit1fa97c76d6b528d0c1f9affe0ebb0092f39eecf8 (patch)
tree1e908a28daa184dd62ddb47a39b7557d3af2017e /activerecord/lib/active_record
parentc2fa53606d3c98ac8dd079a1e5b22da3290a513b (diff)
downloadrails-1fa97c76d6b528d0c1f9affe0ebb0092f39eecf8.tar.gz
rails-1fa97c76d6b528d0c1f9affe0ebb0092f39eecf8.tar.bz2
rails-1fa97c76d6b528d0c1f9affe0ebb0092f39eecf8.zip
Extract `format_colspec` to format column spec
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb4
-rw-r--r--activerecord/lib/active_record/schema_dumper.rb18
2 files changed, 10 insertions, 12 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb
index bc378c0476..06c89ca072 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb
@@ -7,9 +7,7 @@ module ActiveRecord
# Adapter level by over-writing this code inside the database specific adapters
module ColumnDumper
def column_spec(column)
- spec = Hash[prepare_column_options(column).map { |k, v| [k, "#{k}: #{v}"] }]
- spec[:type] = schema_type(column).to_s
- spec
+ [schema_type(column), prepare_column_options(column)]
end
def column_spec_for_primary_key(column)
diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb
index 6f24e6d182..c1c6519cfa 100644
--- a/activerecord/lib/active_record/schema_dumper.rb
+++ b/activerecord/lib/active_record/schema_dumper.rb
@@ -115,9 +115,7 @@ HEADER
pkcol = columns.detect { |c| c.name == pk }
pkcolspec = @connection.column_spec_for_primary_key(pkcol)
if pkcolspec.present?
- pkcolspec.each do |key, value|
- tbl.print ", #{key}: #{value}"
- end
+ tbl.print ", #{format_colspec(pkcolspec)}"
end
when Array
tbl.print ", primary_key: #{pk.inspect}"
@@ -133,16 +131,14 @@ HEADER
tbl.puts " do |t|"
- # find all migration keys used in this table
- keys = @connection.migration_keys
-
# then dump all non-primary key columns
columns.each do |column|
raise StandardError, "Unknown type '#{column.sql_type}' for column '#{column.name}'" unless @connection.valid_type?(column.type)
next if column.name == pk
- colspec = @connection.column_spec(column)
- values = [column.name.inspect] + keys.map { |key| colspec[key] }.compact
- tbl.puts " t.#{colspec[:type]} #{values.join(", ")}"
+ type, colspec = @connection.column_spec(column)
+ tbl.print " t.#{type} #{column.name.inspect}"
+ tbl.print ", #{format_colspec(colspec)}" if colspec.present?
+ tbl.puts
end
indexes_in_create(table, tbl)
@@ -228,6 +224,10 @@ HEADER
end
end
+ def format_colspec(colspec)
+ colspec.map { |key, value| "#{key}: #{value}" }.join(", ")
+ end
+
def format_options(options)
options.map { |key, value| "#{key}: #{value.inspect}" }.join(", ")
end