14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/migration_data/active_record/migration.rb', line 14
def self.included(base)
base.class_eval do
def exec_migration_with_data(conn, direction)
data_before if should_run?(direction == :up, :data_before)
rollback_before if should_run?(direction == :down, :rollback_before)
origin_exec_migration(conn, direction)
::ActiveRecord::Base.connection.schema_cache.clear!
data if should_run?(direction == :up, :data)
data_after if should_run?(direction == :up, :data_after)
rollback if should_run?(direction == :down, :rollback)
rollback_after if should_run?(direction == :down, :rollback_after)
end
alias origin_exec_migration exec_migration
alias exec_migration exec_migration_with_data
private
def should_run?(is_ok_direction, method_name)
is_ok_direction && !MigrationData.config.skip && respond_to?(method_name)
end
end
end
|