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;