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:

  1. CD into gitlab
  2. Do any change to db/structure.sql
  3. Commit changes git commit -m "Changed db/structure.sql" --
  4. Run ./scripts/validate_schema_changes -- or -- Try to push the commit
  5. 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:

  1. CD into `gitlab
  2. Do any change to db/structure.sql
  3. git add -A -f -- db/structure.sql and git commit -m "Changed db/structure.sql"
  4. Run ALLOW_SCHEMA_CHANGES=true ./scripts/validate_schema_changes.
  5. No schema error should be raised.

Testing with skip-db-structure-check in commit message:

  1. CD into `gitlab
  2. Do any change to db/structure.sql
  3. git add -A -f -- db/structure.sql and git commit -m "Changed db/structure.sql - skip-db-structure-check"
  4. Run ./scripts/validate_schema_changes.
  5. 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.

Related to #381704 (closed)

Edited by Leonardo da Rosa

Merge request reports

Loading