Migration ordering
Starting with GitLab 17.1, migrations are executed using a custom ordering scheme that conforms to the GitLab release cadence. This change:
- Simplifies the upgrade process.
- Eases both maintenance and support.
Pre 17.1 logic
Migrations are executed in an order based upon the 14-digit timestamp given in the file name of the migration itself. This behavior is the default for a Rails application.
GitLab also features logic to extend standard migration behavior in these important ways:
- You can load migrations from additional folders. For example, migrations are
loaded from both the
db/post_migratefolder and thedb/migratefolder, which you need when using Post-Deployment migrations. - If you set the environment variable
SKIP_POST_DEPLOYMENT_MIGRATIONS, migrations are not loaded from anypost_migratefolder. - You must provide a GitLab minor version, or “milestone”, on all new migrations.
17.1+ logic
Migrations are executed in the following order:
- Migrations without
milestonedefined are executed first, ordered by their timestamp. - Migrations with
milestonedefined are executed in milestone order:- Regular migrations are executed before post-deployment migrations.
- Migrations of the same type and milestone are executed in order specified by their timestamp.
Example:
- Any migrations without
milestonedefined. 17.1regular migrations.17.1post-deployment migrations.17.2regular migrations.17.2post-deployment migrations.- Repeat for each milestone in the upgrade.
New behavior for post-deployment migrations
This change causes post-deployment migrations to always be sorted at the end
of a given milestone. Previously, post-deployment migrations were
interleaved with regular ones, provided SKIP_POST_DEPLOYMENT_MIGRATIONS was not set.
When SKIP_POST_DEPLOYMENT_MIGRATIONS is set, post-deployment migrations are not executed.