Sha256: 3326df91a064509e867e73a30c630810733ee81ddd93266d447b20a9406ac906

Contents?: true

Size: 1003 Bytes

Versions: 2

Compression:

Stored size: 1003 Bytes

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...")

    archive_path = Pathname.new(ENV.fetch("ARCHIVE_PATH")).expand_path.join("db/migrate")
    migrator = Sequel::TimestampMigrator.new(DB, archive_path, 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.each do |migration|
        DB.log_info("Rolling back migration #{migration}...")
        migrator.undo(migration)
      end
    else
      DB.log_info("No migrations found")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
umbrellio-sequel-plugins-0.12.0 lib/tasks/sequel/rollback_archived_migrations.rake
umbrellio-sequel-plugins-0.12.0.159 lib/tasks/sequel/rollback_archived_migrations.rake