Validates changes in db/structure.sql introduced without migrations
What does this MR do and why?
Uses Git hooks to validate schema changes that does not contains any migrations.
Pre Push output
Lefthook v1.3.2
RUNNING HOOK: pre-push
...
db-schema-changes: (skip) no files for inspection
...
Results:
Warnings:
Markdown:
SUMMARY: (done in 10.48 seconds)
✔️ yamllint
✔️ rubocop
✔️ danger
...
Done
This check could be overridden by setting ALLOW_SCHEMA_CHANGES=true variable or including skip-db-structure-check in the commit body when necessary.
E.G:
Skip using ENV variable
ALLOW_SCHEMA_CHANGES=true git push -u origin my-branch
Skip using commit message
git commit -m "Changed db/structure.sql skip-db-structure-check"
How to set up and validate locally
Testing default behavior:
- CD into
gitlab - Do any change to
db/structure.sql - Commit changes
git commit -m "Changed db/structure.sql" -- - Run
./scripts/validate_schema_changes-- or -- Try to push the commit - An error should happens:
Error: db/structure.sql was changed, and no migrations were added:
diff --git a/db/structure.sql b/db/structure.sql
Testing with ALLOW_SCHEMA_CHANGES=true variable:
- CD into `gitlab
- Do any change to
db/structure.sql -
git add -A -f -- db/structure.sqlandgit commit -m "Changed db/structure.sql" - Run
ALLOW_SCHEMA_CHANGES=true ./scripts/validate_schema_changes. - No schema error should be raised.
Testing with skip-db-structure-check in commit message:
- CD into `gitlab
- Do any change to
db/structure.sql -
git add -A -f -- db/structure.sqlandgit commit -m "Changed db/structure.sql - skip-db-structure-check" - Run
./scripts/validate_schema_changes. - No schema error should be raised.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #381704 (closed)
Edited by Leonardo da Rosa