lib/tasks/sequel/rollback_missing_migrations.rake in umbrellio-sequel-plugins-0.16.1 vs lib/tasks/sequel/rollback_missing_migrations.rake in umbrellio-sequel-plugins-0.17.0
- old
+ new
@@ -2,11 +2,13 @@
require "sequel/timestamp_migrator_undo_extension"
namespace :sequel do
desc "Rollback migrations that are absent in revision when deploying on staging"
- task rollback_missing_migrations: :environment do
+ task :rollback_missing_migrations, [:table, :use_transactions] => :environment do |_t, args|
+ use_transactions = args[:use_transactions].nil? ? nil : args[:use_transactions] == "true"
+
extract_migrations = lambda do |path|
Dir.glob("#{path}/db/migrate/*.rb").map { |filename| File.basename(filename).to_i }
end
old_migrations = extract_migrations.call(ENV.fetch("OLD_RELEASE"))
@@ -17,10 +19,15 @@
puts "Rolling back migrations:"
puts migrations_to_rollback
path = Rails.root.join("db/migrate")
- migrator = Sequel::TimestampMigrator.new(DB, path, allow_missing_migration_files: true)
+ migrator_args = {
+ table: args[:table],
+ use_transactions: use_transactions,
+ allow_missing_migration_files: false,
+ }.compact
+ migrator = Sequel::TimestampMigrator.new(DB, path, migrator_args)
applied_migrations = migrator.applied_migrations.map(&:to_i)
migrations = applied_migrations.select { |m| m.in?(migrations_to_rollback) }.sort.reverse
migrations.each { |migration| migrator.undo(migration) }
end