Implement gitlab:db:validate_schema rake task with exit-code contract
Summary
Implement (or extend) the gitlab:db:validate_schema rake task with a well-defined exit-code contract so that omnibus-gitlab's preinst can use it as a pre-upgrade DB schema consistency gate.
This is a prerequisite for the omnibus-gitlab warn-only release. The GitLab version that ships this task becomes SCHEMA_CHECK_MIN_SOURCE_VERSION in omnibus.
Exit-code contract
| Exit code | Meaning | Phase 1 (warn-only) | Phase 2 (blocking) |
|---|---|---|---|
0 |
Schema consistent with db/structure.sql |
Continue | Continue |
1 |
Inconsistencies found; details on stdout/stderr | Warn and continue | Block (unless bypassed) |
2 |
Operational error — couldn't connect/boot/run | Warn and continue | Warn and continue (never block) |
Exit
2is reserved for the blocking release but should be emitted from the start so Phase 2 requires no follow-up upstream change.
Task name
gitlab:db:validate_schema (confirmed, no namespace change).
Acceptance criteria
- Exits
0when the live DB schema is consistent withdb/structure.sql - Exits
1with human-readable inconsistency detail on stdout/stderr when drift is detected - Exits
2for operational errors (DB unreachable, Rails boot failure, etc.) - RSpec tests: clean schema → exit
0, injected drift → exit1with detail output - The introduced GitLab minor version is noted in the MR description (needed for
SCHEMA_CHECK_MIN_SOURCE_VERSIONin omnibus)
Scope
mainDB only (GeogeoDB is out of scope)- No auto-remediation — report only
Part of
Epic: gitlab-org#22667
Edited by Krasimir Angelov