From 3e60e5095a68fa931e1627d1e4180bb92f6f402d Mon Sep 17 00:00:00 2001 From: CC1 Date: Tue, 5 May 2026 08:52:07 +0200 Subject: [PATCH] CC1 audit fixes #6/#8/#9 from CONSOLIDATED.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #9 sportas trailing-slash (verified clean): Frontend constructs /sportas/{id}/profil cleanly (sport2.html:L1582). Live test: 200 on /sportas/449/profil; 307 on trailing-slash variant (FastAPI auto-redirect, harmless). No fix needed. #8 [VERIFY]/[UNRESOLVED] klubovi surfaced to audit log: 3 manual_review klubovi (2619 Čavle, 2630 Opatija, 4426 empty) inserted into pgz_sport.sys_audit with action='klub.manual_review_pending', visible in /audit page for human triage. Total audit rows: 633. #6 backup-table archival: Moved 26 *_backup_*/*_premerge_*/*_pre_*/*_dedup_*/*_deprecated_*/*_garbage_* tables (~97k rows) from pgz_sport → pgz_sport_archive schema. - Snapshot dump: _audit/db_snapshots/backup_tables_20260505_085057.sql.gz (56 MB) - Script: scripts/archive_backup_tables.sql (idempotent, with rollback) - pgz_sport canonical tables: 112 → 86 - All live API endpoints still 200, db=ok, errors_logged stable at 23 - Josip Zec test 257/182/15 still PASS .gitignore: exclude _audit/db_snapshots/ (large pg_dump archives) Co-Authored-By: Claude Opus 4.7 (1M context) --- .gitignore | 1 + scripts/archive_backup_tables.sql | 44 +++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 scripts/archive_backup_tables.sql diff --git a/.gitignore b/.gitignore index da5a509..dc10ea5 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ cc_tasks/ *.b64 chunk_*.bin chunk_*.b64 +_audit/db_snapshots/ diff --git a/scripts/archive_backup_tables.sql b/scripts/archive_backup_tables.sql new file mode 100644 index 0000000..01bae8d --- /dev/null +++ b/scripts/archive_backup_tables.sql @@ -0,0 +1,44 @@ +-- archive_backup_tables.sql — moved 26 backup/snapshot tables out of pgz_sport +-- Author: cc1@rinet.one Date: 2026-05-05 +-- Re-runnable (idempotent — only moves tables that still match pattern in pgz_sport) +-- +-- Snapshot dump kept at: _audit/db_snapshots/backup_tables_20260505_085057.sql.gz (56 MB) +-- +-- Patterns matched: _backup_ _premerge_ _pre_ _dedup_ _deprecated_ _garbage_ +-- _pre_godisnjak _pre_b_switch +-- +-- After this: +-- pgz_sport canonical tables: 86 (was 112) +-- pgz_sport_archive holds: 26 +-- ~97k rows of stale data archived (no DROP — recoverable via ALTER ... SET SCHEMA back) +-- +-- Rollback any single table: +-- ALTER TABLE pgz_sport_archive. SET SCHEMA pgz_sport; +-- +-- Rollback all: +-- DO $$ DECLARE r record; BEGIN +-- FOR r IN SELECT relname FROM pg_stat_user_tables WHERE schemaname='pgz_sport_archive' LOOP +-- EXECUTE format('ALTER TABLE pgz_sport_archive.%I SET SCHEMA pgz_sport', r.relname); +-- END LOOP; END $$; +-- +-- Permanent drop (after confidence period): +-- DROP SCHEMA pgz_sport_archive CASCADE; + +BEGIN; +CREATE SCHEMA IF NOT EXISTS pgz_sport_archive; + +DO $$ +DECLARE r record; +BEGIN + FOR r IN + SELECT relname FROM pg_stat_user_tables + WHERE schemaname='pgz_sport' + AND (relname ~ '_backup_|_premerge_|_pre_|_dedup_|_deprecated_|_garbage_|_pre_godisnjak|_pre_b_switch') + ORDER BY relname + LOOP + EXECUTE format('ALTER TABLE pgz_sport.%I SET SCHEMA pgz_sport_archive', r.relname); + RAISE NOTICE 'moved %', r.relname; + END LOOP; +END $$; + +COMMIT;