Commit 9615ae8f authored by Toon Claes's avatar Toon Claes

CI check if schema changes were cleanly applied

Recently we've seen a case were schema changes were manually adapted
so the order was not matching the automatically generated
`db/structure.sql`.

To help people commit a clean schema file, I've introduced
`script/regenerate-schema`. This change uses that script to check if
the committed file matches the file automatically generated.
parent 35c09c38
......@@ -143,6 +143,7 @@ db:migrate:reset:
db:check-schema:
extends: .db-job-base
script:
- scripts/regenerate-schema
- source scripts/schema_changed.sh
db:migrate-from-v11.11.0:
......
......@@ -2,13 +2,13 @@
schema_changed() {
if [ ! -z "$(git diff --name-only -- db/structure.sql)" ]; then
printf "db/structure.sql after rake db:migrate:reset is different from one in the repository"
printf "Schema changes are not cleanly committed to db/structure.sql\n"
printf "The diff is as follows:\n"
diff=$(git diff -p --binary -- db/structure.sql)
printf "%s" "$diff"
exit 1
else
printf "db/structure.sql after rake db:migrate:reset matches one in the repository"
printf "Schema changes are correctly applied to db/structure.sql\n"
fi
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment