Migration Squashing
Migration squashing
Migration squashing combines multiple database migrations into a single schema definition to improve database setup performance and maintain a manageable migration history.
Automation
Migration squashing is automated through GitLab Housekeeper. The Keeps::SquashMigrations keep creates MRs automatically at scheduled milestones.
The automation runs via a scheduled pipeline job in the Engineering Productivity team’s CI configuration.
Schedule
Squashing occurs at milestones ending in .2, .5, .8, and .11. These align with required stops.
The target branch is two required stops prior to the current milestone:
| Current milestone | Squashes up to |
|---|---|
| X.2 | (X-1).8 |
| X.5 | (X-1).11 |
| X.8 | X.2 |
| X.11 | X.5 |
For example, at the 18.8 required stop, migrations are squashed up to origin/18-2-stable-ee.
Manual execution
To squash migrations manually from a previous version (such as 16.10), run:
bundle exec rake "gitlab:db:squash[origin/16-10-stable-ee]"This Rake task:
- Removes all migrations from the previous version
- Updates
db/init_structure.sqlwith the squashed schema - Updates schema version references in relevant files
- Removes associated migration specs and RuboCop TODOs
- Cleans up finalized batched background migrations
Parameters
| Parameter | Description |
|---|---|
[origin/16-10-stable-ee] | The Git reference to use as a baseline for migration squashing. This should be the stable branch of the target version. |
Troubleshooting
Missing schema references
If you encounter errors related to missing schema references, check:
- Migration spec files that might reference old migrations
- Background migration files that might need manual updates
- Documentation that references specific migration versions