M44: harden release integrity and assurance
This commit is contained in:
Executable
+44
@@ -0,0 +1,44 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
backup_file="${1:-}"
|
||||
[ -f "$backup_file" ] || { echo "Restore-drill backup not found: $backup_file" >&2; exit 1; }
|
||||
|
||||
timestamp="$(date -u +%Y%m%d%H%M%S)"
|
||||
drill_database="mobilityops_restore_drill_$timestamp"
|
||||
source_database="${POSTGRES_DB:-mobilityops}"
|
||||
database_host="${POSTGRES_HOST:-db}"
|
||||
|
||||
cleanup() {
|
||||
dropdb --if-exists --force --host="$database_host" --username="$POSTGRES_USER" \
|
||||
"$drill_database" > /dev/null 2>&1 || true
|
||||
}
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
source_revision="$(psql --host="$database_host" --username="$POSTGRES_USER" \
|
||||
--dbname="$source_database" --tuples-only --no-align \
|
||||
--command='SELECT version_num FROM alembic_version')"
|
||||
[ -n "$source_revision" ] || { echo "Source Alembic revision is unavailable" >&2; exit 1; }
|
||||
|
||||
createdb --host="$database_host" --username="$POSTGRES_USER" "$drill_database"
|
||||
pg_restore --no-owner --no-acl --host="$database_host" --username="$POSTGRES_USER" \
|
||||
--dbname="$drill_database" "$backup_file"
|
||||
|
||||
restored_revision="$(psql --host="$database_host" --username="$POSTGRES_USER" \
|
||||
--dbname="$drill_database" --tuples-only --no-align \
|
||||
--command='SELECT version_num FROM alembic_version')"
|
||||
[ "$restored_revision" = "$source_revision" ] || {
|
||||
echo "Restored Alembic revision does not match production" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
counts="$(psql --host="$database_host" --username="$POSTGRES_USER" \
|
||||
--dbname="$drill_database" --tuples-only --no-align --field-separator=, \
|
||||
--command='SELECT (SELECT count(*) FROM users), (SELECT count(*) FROM vehicles), (SELECT count(*) FROM bookings), (SELECT count(*) FROM audit_events)')"
|
||||
case "$counts" in
|
||||
0,*|*,0,*|*,*,0,*|*,*,*,0) echo "Restored database is missing canonical records: $counts" >&2; exit 1 ;;
|
||||
esac
|
||||
|
||||
cleanup
|
||||
trap - EXIT INT TERM
|
||||
echo "Restore drill passed: revision=$restored_revision counts=$counts"
|
||||
Reference in New Issue
Block a user