lib/ridgepole/diff.rb in ridgepole-0.7.0.alpha vs lib/ridgepole/diff.rb in ridgepole-0.7.0.alpha2
- old
+ new
@@ -32,11 +32,11 @@
delta[:add] ||= {}
delta[:add][table_name] = to_attrs
end
end
- unless @options[:merge]
+ unless @options[:merge] or @options[:skip_drop_table]
from.each do |table_name, from_attrs|
next unless target?(table_name)
delta[:delete] ||= {}
delta[:delete][table_name] = from_attrs
@@ -53,10 +53,12 @@
def scan_table_rename(from, to, delta, options = {})
to.dup.each do |table_name, to_attrs|
next unless target?(table_name)
if (from_table_name = (to_attrs[:options] || {}).delete(:renamed_from))
+ from_table_name = from_table_name.to_s if from_table_name
+
# Already renamed
next if from[table_name]
# No existence checking because there is that the table to be read is limited
#unless from.has_key?(from_table_name)
@@ -193,10 +195,12 @@
end
def scan_column_rename(from, to, definition_delta)
to.dup.each do |column_name, to_attrs|
if (from_column_name = (to_attrs[:options] || {}).delete(:renamed_from))
+ from_column_name = from_column_name.to_s if from_column_name
+
# Already renamed
next if from[column_name]
unless from.has_key?(from_column_name)
raise "Column `#{from_column_name}` not found"
@@ -289,11 +293,11 @@
# XXX: MySQL only?
if not opts.has_key?(:default)
opts[:default] = nil
end
- if @options[:enable_mysql_awesome]
+ if Ridgepole::ConnectionAdapters.mysql?
opts[:unsigned] = false unless opts.has_key?(:unsigned)
end
end
def normalize_index_options!(opts)
@@ -317,32 +321,32 @@
def scan_foreign_keys_change(from, to, table_delta, options)
from = (from || {}).dup
to = (to || {}).dup
foreign_keys_delta = {}
- to.each do |foreign_key_name, to_attrs|
- from_attrs = from.delete(foreign_key_name)
+ to.each do |foreign_key_name_or_tables, to_attrs|
+ from_attrs = from.delete(foreign_key_name_or_tables)
if from_attrs
if from_attrs != to_attrs
foreign_keys_delta[:add] ||= {}
- foreign_keys_delta[:add][foreign_key_name] = to_attrs
+ foreign_keys_delta[:add][foreign_key_name_or_tables] = to_attrs
unless options[:merge]
foreign_keys_delta[:delete] ||= {}
- foreign_keys_delta[:delete][foreign_key_name] = from_attrs
+ foreign_keys_delta[:delete][foreign_key_name_or_tables] = from_attrs
end
end
else
foreign_keys_delta[:add] ||= {}
- foreign_keys_delta[:add][foreign_key_name] = to_attrs
+ foreign_keys_delta[:add][foreign_key_name_or_tables] = to_attrs
end
end
unless options[:merge]
- from.each do |foreign_key_name, from_attrs|
+ from.each do |foreign_key_name_or_tables, from_attrs|
foreign_keys_delta[:delete] ||= {}
- foreign_keys_delta[:delete][foreign_key_name] = from_attrs
+ foreign_keys_delta[:delete][foreign_key_name_or_tables] = from_attrs
end
end
unless foreign_keys_delta.empty?
table_delta[:foreign_keys] = foreign_keys_delta