Last active
August 10, 2022 16:54
-
-
Save matthieuprat/bc164339e8d6066bf8d598ec508cc0c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version = 3.months.ago.utc.strftime("%Y%m%d%H%M%S") | |
puts "Deleting migrations before version #{version.inspect}" | |
migrations = | |
ActiveRecord::MigrationContext.new(['db/migrate']) | |
.migrations | |
.take_while { |migration| migration.version < version } | |
File.delete(*migrations.map(&:filename)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
class DeleteOldSchemaMigrationVersions < ActiveRecord::Migration[5.2] | |
def up | |
ActiveRecord::SchemaMigration.where("version < ?", <version>).delete_all | |
end | |
def down; end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment