18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/also_migrate/migration.rb', line 18
def method_missing_with_also_migrate(method, *arguments, &block)
args = Marshal.load(Marshal.dump(arguments))
method_missing_without_also_migrate(method, *arguments, &block)
supported = [
:add_column, :add_index, :add_timestamps, :change_column,
:change_column_default, :change_table, :create_table,
:drop_table, :remove_column, :remove_columns,
:remove_timestamps, :rename_column, :rename_table
]
if !args.empty? && supported.include?(method)
connection = ActiveRecord::Base.connection
table_name = ActiveRecord::Migrator.proper_table_name(args[0])
if ::AlsoMigrate.classes
::AlsoMigrate.classes.uniq.each do |klass|
if klass.also_migrate_config
klass.also_migrate_config.each do |config|
options = config[:options]
tables = config[:tables]
next unless config[:table_name] == table_name
options[:ignore].each do |column|
next if args.include?(column) || args.include?(column.intern)
end
config[:tables].each do |table|
if method == :create_table
ActiveRecord::Migrator::AlsoMigrate.create_tables(klass)
elsif method == :add_index && !options[:indexes].nil?
next
elsif connection.table_exists?(table)
args[0] = table
args[1] = table if method == :rename_table
begin
connection.send(method, *args, &block)
rescue Exception => e
puts "(also_migrate warning) #{e.message}"
end
end
end
end
end
end
end
end
end
|