DEV: Promote old post-deploy migrations to pre-deploy migrations (#13477)

Having a large number of post-deploy migrations running out-of-numerical-sequence with pre-deploy migrations can be problematic. For example, if we have the sequence

- db/migrate/2017... - add column
- db/post_migrate/2018... - drop the column
- db/migrate/2021... - add the same column again

It will work fine in numerical order. But if you run the pre-deploy migrations **followed by** the post-deploy migrations, you will not get the same result.

Our post-deploy system is designed to allow for seamless upgrades of Discourse. However, it is reasonable for us to only support this totally seamless experience for a limited period of time. This commit moves all post_deploy migrations which are more than 1 year old (i.e. more than 2 major Discourse versions ago) into the regular pre-deploy migrations directory. This limits the impact of any edge cases caused by out-of-numerical-sequence migrations.
This commit is contained in:
David Taylor 2021-06-22 16:02:24 +01:00 committed by GitHub
parent 820068ddaf
commit e76c583b91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 9 additions and 2 deletions

View File

@ -6,7 +6,6 @@ class Discourse::InvalidMigration < StandardError; end
class Migration::SafeMigrate
module SafeMigration
UNSAFE_VERSION = 20180321015220
@@enable_safe = true
def self.enable_safe!
@ -19,7 +18,7 @@ class Migration::SafeMigrate
def migrate(direction)
if direction == :up &&
version && version > UNSAFE_VERSION &&
version && version > Migration::SafeMigrate.earliest_post_deploy_version &&
@@enable_safe != false &&
!is_post_deploy_migration?
@ -153,4 +152,12 @@ class Migration::SafeMigrate
raise Discourse::InvalidMigration, "Attempt was made to rename or delete column"
end
end
def self.earliest_post_deploy_version
@@earliest_post_deploy_version ||= begin
first_file = Dir.glob("#{Discourse::DB_POST_MIGRATE_PATH}/*.rb").sort.first
file_name = File.basename(first_file, ".rb")
file_name.first(14).to_i
end
end
end