doc/development/database/dbcheck-migrations-job.md
This job runs on the test stage of a merge request pipeline. It checks:
db/structure.sql
file that the author committed. This check validates that it contains all the expected changes
in the migration.db/schema_migrations that the author committed and the
one that the script generated after running migrations. This check validates that everything
was properly committed.This job is not allowed to fail, but it can throw some false positives.
Examples:
In such cases it's safer to add pipeline:skip-check-migrations label to the MR to skip this job.
This failure often happens if your working branch is behind the target branch. A real scenario:
%%{init: { "fontFamily": "GitLab Sans" }}%%
graph LR
accTitle: Schema dump comparison fails after rollback
accDescr: Diagram showing how schema dump comparison failures occur if a working branch is behind the target branch
Main((main
commit A)) ===> |remove constraint
fk_rails_dbebdaa8fe| MainB((main
commit B))
Main((main
commit A)) --> |checkout
dev| DevA((dev
commit A)):::dev
DevA((dev
commit A)) --> |add column
dependency_proxy_size| DevC((dev
commit C)):::dev
DevC -.-> |CI pipeline
executes| JOB-FAILED((JOB FAILED!)):::error
dev working branch from the main target branch. At this point,
each branch has their HEAD at commit A.main branch and drops the fk_rails_dbebdaa8fe constraint,
thus creating commit B on main.dependency_proxy_size to your dev branch.db:check-migrations job fails for your dev branch's CI/CD pipeline, because
the structure.sql file did not rollback to its expected state.This happened because branch dev contained commits A and C, not B. Its database schema
did not know about the removal of the fk_rails_dbebdaa8fe constraint. When comparing the two
schemas, the dev branch contained this constraint while the main branch didn't.
This example really happened. Read the job failure logs.
To fix these kind of issues, rebase the working branch onto the target branch to get the latest changes.