diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2016-10-10 22:31:49 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-10 22:31:49 -0300 |
commit | 469dd36af14ec20197910fb5cd2fd47f7612ef09 (patch) | |
tree | 523e45dcbfe398a1f047c3e5305a0742f4481e0d /activerecord | |
parent | 3c8f26ac14eb8fc8db45cf5ed020ce1227ce3859 (diff) | |
parent | 1fa97c76d6b528d0c1f9affe0ebb0092f39eecf8 (diff) | |
download | rails-469dd36af14ec20197910fb5cd2fd47f7612ef09.tar.gz rails-469dd36af14ec20197910fb5cd2fd47f7612ef09.tar.bz2 rails-469dd36af14ec20197910fb5cd2fd47f7612ef09.zip |
Merge pull request #26756 from kamipo/extract_format_colspec
Extract `format_colspec` to format column spec
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/schema_dumper.rb | 18 |
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 |