Files
GerbilManager/tools/wipe-import-data.sql
Gulum bff25b4683
Some checks failed
CI / Backend Tests (.NET) (push) Successful in 1m2s
CI / Frontend Tests (Node/Vite) (push) Successful in 9m33s
CI / Docker Build & Push (push) Failing after 9s
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 <noreply@anthropic.com>
2026-06-07 21:58:11 +02:00

33 lines
1.3 KiB
PL/PgSQL

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