lib/ridgepole/diff.rb in ridgepole-0.4.4 vs lib/ridgepole/diff.rb in ridgepole-0.4.5

- old
+ new

@@ -73,11 +73,11 @@ to = (to || {}).dup table_delta = {} scan_options_change(table_name, from[:options], to[:options], table_delta) scan_definition_change(from[:definition], to[:definition], from[:indices], table_delta) - scan_indices_change(from[:indices], to[:indices], to[:definition], table_delta) + scan_indices_change(from[:indices], to[:indices], to[:definition], table_delta, from[:options], to[:options]) unless table_delta.empty? delta[:change] ||= {} delta[:change][table_name] = table_delta end @@ -169,11 +169,11 @@ to.delete(column_name) end end end - def scan_indices_change(from, to, to_columns, table_delta) + def scan_indices_change(from, to, to_columns, table_delta, from_table_options, to_table_options) from = (from || {}).dup to = (to || {}).dup indices_delta = {} to.each do |index_name, to_attrs| @@ -195,11 +195,11 @@ if from_attrs != to_attrs indices_delta[:add] ||= {} indices_delta[:add][index_name] = to_attrs unless @options[:merge] - if from_attrs[:column_name].all? {|i| to_columns[i] } + if columns_all_include?(from_attrs[:column_name], to_columns.keys, to_table_options) indices_delta[:delete] ||= {} indices_delta[:delete][index_name] = from_attrs end end end @@ -209,11 +209,11 @@ end end unless @options[:merge] from.each do |index_name, from_attrs| - if from_attrs[:column_name].all? {|i| to_columns[i] } + if columns_all_include?(from_attrs[:column_name], to_columns.keys, to_table_options) indices_delta[:delete] ||= {} indices_delta[:delete][index_name] = from_attrs end end end @@ -243,7 +243,15 @@ end def normalize_index_options!(opts) # XXX: MySQL only? opts[:using] = :btree unless opts.has_key?(:using) + end + + def columns_all_include?(expected_columns, actual_columns, table_options) + if table_options[:id] != false + actual_columns = actual_columns + [(table_options[:primary_key] || 'id').to_s] + end + + expected_columns.all? {|i| actual_columns.include?(i) } end end