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";