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>
This commit is contained in:
32
tools/wipe-import-data.sql
Normal file
32
tools/wipe-import-data.sql
Normal file
@@ -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 <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";
|
||||
Reference in New Issue
Block a user