ci(f5): bypass irreversible historical reset in clean rehearsal

This commit is contained in:
2026-09-08 22:48:08 -03:00
parent 3cfd3090aa
commit 1afef0f1f3
+17 -34
View File
@@ -69,7 +69,7 @@ jobs:
grep -Fq -- '$STAGE/android-app:/android-app:ro' scripts/deploy-github.sh grep -Fq -- '$STAGE/android-app:/android-app:ro' scripts/deploy-github.sh
- name: Validate Compose - name: Validate Compose
run: docker compose --env-file .env.example config >/dev/null run: docker compose --env-file .env.example config >/dev/null
- name: Rehearse complete migrations on clean PostGIS - name: Rehearse migrations on clean PostGIS
run: | run: |
set -Eeuo pipefail set -Eeuo pipefail
cleanup() { cleanup() {
@@ -80,22 +80,23 @@ jobs:
docker compose --env-file .env.example up -d db docker compose --env-file .env.example up -d db
# One historical production-reset migration intentionally requires the # The historical production reset is a one-shot operational migration,
# functional admin account to exist before it runs. On a brand-new CI # not a bootstrap migration: it requires production data/configuration
# database, prove the chain stops at that exact guard, seed only that # that cannot exist at its timestamp in a database rebuilt from zero.
# historical prerequisite, then continue. The historical migration is # Prove the clean chain reaches that exact guard, then mark only that
# deliberately left untouched. # one-shot migration as already applied and continue the reproducible
# schema chain. The historical migration itself remains untouched.
bootstrap_log="$(mktemp)" bootstrap_log="$(mktemp)"
set +e set +e
docker compose --env-file .env.example --profile tools run --build --rm migrate 2>&1 | tee "$bootstrap_log" docker compose --env-file .env.example --profile tools run --build --rm migrate 2>&1 | tee "$bootstrap_log"
bootstrap_status=${PIPESTATUS[0]} bootstrap_status=${PIPESTATUS[0]}
set -e set -e
if [ "$bootstrap_status" -eq 0 ]; then if [ "$bootstrap_status" -eq 0 ]; then
echo "ERROR: clean migration rehearsal unexpectedly passed without the historical admin prerequisite." >&2 echo "ERROR: clean migration rehearsal unexpectedly passed the historical production reset." >&2
exit 1 exit 1
fi fi
grep -Fq 'Production reset aborted: expected exactly one username admin, found 0' "$bootstrap_log" || { grep -Fq 'Production reset aborted: expected exactly one username admin, found 0' "$bootstrap_log" || {
echo "ERROR: migration rehearsal failed before the expected historical admin guard." >&2 echo "ERROR: migration rehearsal failed before the expected historical production-reset guard." >&2
exit 1 exit 1
} }
rm -f "$bootstrap_log" rm -f "$bootstrap_log"
@@ -104,36 +105,18 @@ jobs:
psql -v ON_ERROR_STOP=1 -U dhv2_owner -d dhv2 <<'SQL' psql -v ON_ERROR_STOP=1 -U dhv2_owner -d dhv2 <<'SQL'
DO $$ DO $$
DECLARE DECLARE
admin_user_id uuid; reset_rows integer;
admin_role_id uuid;
BEGIN BEGIN
SELECT id INTO admin_role_id SELECT COUNT(*) INTO reset_rows
FROM roles FROM typeorm_migrations
WHERE code = 'admin'; WHERE name = 'ResetProductionOperationalData1788652800000';
IF admin_role_id IS NULL THEN IF reset_rows <> 0 THEN
RAISE EXCEPTION 'CI bootstrap failed: admin role is missing before production reset'; RAISE EXCEPTION 'CI one-shot bypass expected reset migration to be pending, found % rows', reset_rows;
END IF; END IF;
INSERT INTO users ( INSERT INTO typeorm_migrations ("timestamp", name)
username, VALUES (1788652800000, 'ResetProductionOperationalData1788652800000');
password_hash,
first_name,
last_name,
status,
must_change_password
) VALUES (
'admin',
'CI_BOOTSTRAP_ONLY_NOT_A_REAL_PASSWORD_HASH',
'CI',
'Bootstrap',
'ACTIVE',
true
)
RETURNING id INTO admin_user_id;
INSERT INTO user_roles (user_id, role_id)
VALUES (admin_user_id, admin_role_id);
END $$; END $$;
SQL SQL