diff options
Diffstat (limited to 'activerecord/lib/active_record')
4 files changed, 12 insertions, 14 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 8bb7362c2e..bc378c0476 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb @@ -8,7 +8,6 @@ module ActiveRecord module ColumnDumper def column_spec(column) 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 @@ -53,7 +52,7 @@ module ActiveRecord # Lists the valid migration options def migration_keys - [:name, :limit, :precision, :scale, :default, :null, :collation, :comment] + [:limit, :precision, :scale, :default, :null, :collation, :comment] end private diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 0f1a83324b..1df20a0c56 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -120,7 +120,7 @@ module ActiveRecord checks = [] checks << lambda { |c| c.name == column_name } checks << lambda { |c| c.type == type } if type - (migration_keys - [:name]).each do |attr| + migration_keys.each do |attr| checks << lambda { |c| c.send(attr) == options[attr] } if options.key?(attr) end 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 29a77580f5..83310233f0 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb @@ -239,7 +239,9 @@ module ActiveRecord end def table_options(table_name) # :nodoc: - { comment: table_comment(table_name) } + if comment = table_comment(table_name) + { comment: comment } + end end # Returns a comment stored in database for given table diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb index fc28ac7cb0..6f24e6d182 100644 --- a/activerecord/lib/active_record/schema_dumper.rb +++ b/activerecord/lib/active_record/schema_dumper.rb @@ -133,18 +133,15 @@ HEADER tbl.puts " do |t|" - # then dump all non-primary key columns - column_specs = columns.map do |column| - raise StandardError, "Unknown type '#{column.sql_type}' for column '#{column.name}'" unless @connection.valid_type?(column.type) - next if column.name == pk - @connection.column_spec(column) - end.compact - # find all migration keys used in this table keys = @connection.migration_keys - column_specs.each do |colspec| - values = keys.map { |key| colspec[key] }.compact + # 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(", ")}" end @@ -232,7 +229,7 @@ HEADER end def format_options(options) - options.map { |key, value| "#{key}: #{value.inspect}" if value }.compact.join(", ") + options.map { |key, value| "#{key}: #{value.inspect}" }.join(", ") end def remove_prefix_and_suffix(table) |