lib/ridgepole/diff.rb in ridgepole-0.2.0 vs lib/ridgepole/diff.rb in ridgepole-0.2.1

- old
+ new

@@ -10,11 +10,14 @@ to.dup.each do |table_name, to_attrs| next unless target?(table_name) if (from_table_name = (to_attrs[:options] || {}).delete(:rename_from)) - next unless from.has_key?(from_table_name) + unless from.has_key?(from_table_name) + raise "Table `#{from_table_name}` not found" + end + delta[:rename] ||= {} delta[:rename][table_name] = from_table_name from.delete(from_table_name) to.delete(table_name) end @@ -48,31 +51,36 @@ def scan_change(table_name, from, to, delta) from = (from || {}).dup to = (to || {}).dup table_delta = {} - scan_options_change(from[:options], to[:options], table_delta) + scan_options_change(table_name, from[:options], to[:options], table_delta) scan_definition_change(from[:definition], to[:definition], table_delta) scan_indices_change(from[:indices], to[:indices], table_delta) unless table_delta.empty? delta[:change] ||= {} delta[:change][table_name] = table_delta end end - def scan_options_change(from, to, table_delta) - Ridgepole::Logger.instance.warn('[WARNING] Table options cannot be changed') + def scan_options_change(table_name, from, to, table_delta) + unless from == to + Ridgepole::Logger.instance.warn("[WARNING] Table `#{table_name}` options cannot be changed") + end end def scan_definition_change(from, to, table_delta) from = (from || {}).dup to = (to || {}).dup definition_delta = {} to.dup.each do |column_name, to_attrs| if (from_column_name = (to_attrs[:options] || {}).delete(:rename_from)) - next unless from.has_key?(from_column_name) + unless from.has_key?(from_column_name) + raise "Column `#{from_column_name}` not found" + end + definition_delta[:rename] ||= {} definition_delta[:rename][column_name] = from_column_name from.delete(from_column_name) to.delete(column_name) end