lib/rom/sql/migration/schema_diff.rb in rom-sql-3.6.4 vs lib/rom/sql/migration/schema_diff.rb in rom-sql-4.0.0.alpha1

- old
+ new

@@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'rom/sql/type_serializer' +require "rom/sql/type_serializer" module ROM module SQL module Migration # @api private @@ -44,11 +44,10 @@ option :foreign_keys, default: -> { EMPTY_ARRAY } end class TableAltered < TableDiff - option :attribute_changes, default: -> { EMPTY_ARRAY } option :index_changes, default: -> { EMPTY_ARRAY } option :foreign_key_changes, default: -> { EMPTY_ARRAY } @@ -133,22 +132,22 @@ end class IndexAdded < IndexDiff def options options = {} - options[:name] = index.name if !index.name.nil? + options[:name] = index.name unless index.name.nil? options[:unique] = true if index.unique? - options[:type] = index.type if !index.type.nil? - options[:where] = index.predicate if !index.predicate.nil? + options[:type] = index.type unless index.type.nil? + options[:where] = index.predicate unless index.predicate.nil? options end end class IndexRemoved < IndexDiff def options options = {} - options[:name] = index.name if !index.name.nil? + options[:name] = index.name unless index.name.nil? options end end class ForeignKeyDiff @@ -208,11 +207,11 @@ changed_attributes = target.select { |name, attr| current.key?(name) && !attributes_equal?(current[name], attr) }.map { |name, target_attr| [name, [target_attr, current[name]]] }.to_h - added_attributes = target.select { |name, _| !current.key?(name) } - removed_attributes = current.select { |name, _| !target.key?(name) } + added_attributes = target.reject { |name, _| current.key?(name) } + removed_attributes = current.reject { |name, _| target.key?(name) } map_attributes(removed_attributes, AttributeRemoved) + map_attributes(added_attributes, AttributeAdded) + map_attributes(changed_attributes, AttributeChanged) end