Skip to content

Draft: [SPIKE] Execute migrations ordered by milestone

DO NOT MERGE!

What does this MR do and why?

This is a PoC (#416223 (closed)), to find out what we need to achieve Migrations should run in milestone, then type, ... (&10411 - closed).

We have the following migrations:

db/migrate/20230713043152_test_migration_1.rb
db/migrate/20230713043226_test_migration_3.rb
db/migrate/20230713043244_test_migration_5.rb
db/migrate/20230713043256_test_migration_6.rb
db/post_migrate/20230713043135_test_migration_4.rb
db/post_migrate/20230713043309_test_migration_2.rb
db/post_migrate/20230713043322_test_migration_7.rb

With the changes from this MR, the migrations are executed as following:

  1. Migrations with no milestone specified are executed first, ordered by their version (timestamp)
  2. Migrations with milestone specified are executed as:
    1. First, compare milestones
    2. If milestones are the same, we first execute regular migrations, then post-deployment migrations.
    3. For migrations with the same milestone, and of the same type, we sort them by version (timestamp), as what Rails does by default.

So the above migrations end up executed as this:

$ bundle exec rails db:migrate:main
main: == 20230713043152 TestMigration1: migrating ===================================
main: == 20230713043152 TestMigration1: migrated (0.0048s) ==========================

main: == 20230713043309 TestMigration2: migrating ===================================
main: == 20230713043309 TestMigration2: migrated (0.0023s) ==========================

main: == 20230713043226 TestMigration3: migrating ===================================
main: == 20230713043226 TestMigration3: migrated (0.0021s) ==========================

main: == 20230713043135 TestMigration4: migrating ===================================
main: == 20230713043135 TestMigration4: migrated (0.0019s) ==========================

main: == 20230713043244 TestMigration5: migrating ===================================
main: == 20230713043244 TestMigration5: migrated (0.0020s) ==========================

main: == 20230713043256 TestMigration6: migrating ===================================
main: == 20230713043256 TestMigration6: migrated (0.0026s) ==========================

main: == 20230713043322 TestMigration7: migrating ===================================
main: == 20230713043322 TestMigration7: migrated (0.0020s) ==========================

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Krasimir Angelov

Merge request reports