Sha256: 1f55444ecab48f348af6d2f3f09061feb7b26e1d39b331eb98236ed41b8081f9
Contents?: true
Size: 1.16 KB
Versions: 10
Compression:
Stored size: 1.16 KB
Contents
# frozen_string_literal: true require "sequel/timestamp_migrator_undo_extension" namespace :sequel do desc "Rollback migrations that were applied earlier but are not present in current release" task rollback_archived_migrations: :environment do DB.log_info("Finding applied migrations not present in current release...") Dir.mktmpdir do |tmpdir| DB[:schema_migrations_sources].each do |migration| path = File.join(tmpdir, migration.fetch(:filename)) File.write(path, migration.fetch(:source)) end migrator = Sequel::TimestampMigrator.new(DB, tmpdir, allow_missing_migration_files: true) applied_migrations = migrator.applied_migrations.map(&:to_i) filesystem_migrations = Rails.root.glob("db/migrate/*.rb").map { |x| File.basename(x).to_i } missing_migrations = applied_migrations - filesystem_migrations if missing_migrations.any? missing_migrations.sort.reverse_each do |migration| DB.log_info("Rolling back migration #{migration}...") migrator.undo(migration) end else DB.log_info("No migrations found") "No migrations found" end end end end
Version data entries
10 entries across 10 versions & 1 rubygems