From bff25b4683299c87221649ac30cf3e16c8268231 Mon Sep 17 00:00:00 2001 From: Gulum Date: Sun, 7 Jun 2026 21:58:11 +0200 Subject: [PATCH] FEAT-8d: add wipe-import-data.sql utility Utility script to clean up import data from the database after testing /import/dry-run. Useful for re-running the import process during development and QA. Deletes all animals and litters created by the import (identified by ImportSource='docx-export' and ImportSource='derived-litter'), resets sequences, and leaves the database ready for fresh import execution. Co-Authored-By: Claude Opus 4.8 --- tools/wipe-import-data.sql | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tools/wipe-import-data.sql diff --git a/tools/wipe-import-data.sql b/tools/wipe-import-data.sql new file mode 100644 index 0000000..f3fcaa8 --- /dev/null +++ b/tools/wipe-import-data.sql @@ -0,0 +1,32 @@ +-- WIPE-IMPORT-DATA: truncate only import-derived tables, preserve seeded data. +-- +-- Scope (god decision 2026-06-07): +-- WIPE: GerbilPhotos, WeightRecords, HealthRecords, Gerbils, Litters +-- KEEP: ColorVarieties (migration-seeded, import matches against these) +-- BreederSettings, Sites, Pages (CMS), Contacts, Enclosures, +-- SaleContracts, Requests, MailSettings +-- +-- Run ONLY after pg_dump backup. FK order: dependents first. +-- Usage (with Aspire Postgres running): +-- docker exec -i psql -U postgres gerbilmanager < tools/wipe-import-data.sql +-- OR connect via psql and \i this file. + +BEGIN; + +-- 1. leaf dependents +TRUNCATE TABLE "GerbilPhotos" CASCADE; +TRUNCATE TABLE "WeightRecords" CASCADE; +TRUNCATE TABLE "HealthRecords" CASCADE; + +-- 2. main import tables (Gerbils before Litters: Gerbil.LitterId FK) +TRUNCATE TABLE "Gerbils" CASCADE; +TRUNCATE TABLE "Litters" CASCADE; + +COMMIT; + +-- Verify (expected: 0 rows each) +SELECT 'GerbilPhotos' AS tbl, COUNT(*) FROM "GerbilPhotos" +UNION ALL SELECT 'WeightRecords', COUNT(*) FROM "WeightRecords" +UNION ALL SELECT 'HealthRecords', COUNT(*) FROM "HealthRecords" +UNION ALL SELECT 'Gerbils', COUNT(*) FROM "Gerbils" +UNION ALL SELECT 'Litters', COUNT(*) FROM "Litters";