diff --git a/db/ops/cleanup-test-data.sql b/db/ops/cleanup-test-data.sql index 5bfb316..bc0297b 100644 --- a/db/ops/cleanup-test-data.sql +++ b/db/ops/cleanup-test-data.sql @@ -3,6 +3,8 @@ -- psql -p 5433 -d ims -v mode=run -f cleanup-test-data.sql (deletes, one transaction) -- Evidence files on disk are NOT touched (5-year retention). +\set ON_ERROR_STOP on + \if :{?mode} \else \echo 'Set -v mode=dryrun or -v mode=run' diff --git a/docs/runbooks/cleanup-test-data.md b/docs/runbooks/cleanup-test-data.md index 7189da9..5b45cb7 100644 --- a/docs/runbooks/cleanup-test-data.md +++ b/docs/runbooks/cleanup-test-data.md @@ -11,11 +11,11 @@ Owner go-ahead required before step 4. Never run during business hours without t ``` Create `/srv/apps/ims/backups` first if missing. Both files must be non-empty. 2. **Upload** `db/ops/cleanup-test-data.sql` to `/srv/apps/ims/backups/` (not into `app/`). -3. **Dry run** as the DB owner: +3. **Dry run.** Use a DB role that owns the tables and bypasses RLS (superuser, or the owner role with BYPASSRLS). The tables have FORCE RLS and no DELETE policies, so as `app_user` or a plain owner the counts can read 0 and deletes silently remove nothing. Check first: `psql -p 5433 -d ims -Atc "select rolsuper or rolbypassrls from pg_roles where rolname = current_user"` must print `t`. Then: ```bash psql -p 5433 -d ims -v mode=dryrun -f /srv/apps/ims/backups/cleanup-test-data.sql ``` - Send the admins list and the row counts to the owner. Stop here until they confirm. + Send the admins list and the row counts to the owner. If incidents or users show 0 when the app shows rows, you are on the wrong role: stop. Mention that audit_log rows written by non-admin users about other tables (zones, trucks, settings) are also removed. Stop here until they confirm. 4. **Run** after explicit confirmation: ```bash psql -p 5433 -d ims -v ON_ERROR_STOP=1 -v mode=run -f /srv/apps/ims/backups/cleanup-test-data.sql