41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/sequent/migrations/executor.rb', line 41
def execute_offline(plan, current_version)
plan.replay_tables.each do |migration|
table = migration.record_class
current_table_name = table.table_name.gsub("_#{migration.version}", '')
exec_sql("ALTER TABLE IF EXISTS #{current_table_name} RENAME TO #{current_table_name}_#{current_version}")
exec_sql("ALTER TABLE #{table.table_name} RENAME TO #{current_table_name}")
table.table_name = current_table_name
table.reset_column_information
end
plan.alter_tables.each do |migration|
table = migration.record_class
sql_file = <<~EOS.chomp
#{Sequent.configuration.migration_sql_files_directory}/#{table.table_name}_#{migration.version}.sql
EOS
statements = sql_file_to_statements(sql_file)
statements.each(&method(:exec_sql))
end
end
|