1.8 KiB
1.8 KiB
Cleanup: delete test incidents and non-admin users
Owner go-ahead required before step 4. Never run during business hours without telling HSE.
- Backup (on the server,
ssh -p 9321 setia@175.136.239.121):CreateD=$(date +%Y%m%d-%H%M) pg_dump -p 5433 -Fc ims > /srv/apps/ims/backups/ims-pre-cleanup-$D.dump tar -czf /srv/apps/ims/backups/evidence-pre-cleanup-$D.tgz /var/lib/ims-evidence ls -lh /srv/apps/ims/backups/*pre-cleanup-$D*/srv/apps/ims/backupsfirst if missing. Both files must be non-empty. - Upload
db/ops/cleanup-test-data.sqlto/srv/apps/ims/backups/(not intoapp/). - 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_useror 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 printt. Then: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.psql -p 5433 -d ims -v mode=dryrun -f /srv/apps/ims/backups/cleanup-test-data.sql - Run after explicit confirmation:
psql -p 5433 -d ims -v ON_ERROR_STOP=1 -v mode=run -f /srv/apps/ims/backups/cleanup-test-data.sql - Verify:
systemctl is-active imsisactive; log in as an admin at https://ims.setia.com.my/login; Incidents page is empty; Users page lists only admins. - Rollback (only if wrong):
pg_restore -p 5433 -d ims --clean --if-exists <dump>; evidence files were never touched.