#!/bin/bash
set -euo pipefail

CONTAINER="archive-db"
DB_USER="archive_user"
DB_NAME="family_archive_db"

echo "This will delete ALL documents, persons, and tags from the database."
read -rp "Type 'yes' to continue: " CONFIRM
[ "$CONFIRM" != "yes" ] && echo "Aborted." && exit 0

docker exec "$CONTAINER" psql -U "$DB_USER" -d "$DB_NAME" -c "
TRUNCATE transcription_block_versions CASCADE;
TRUNCATE transcription_blocks CASCADE;
TRUNCATE comment_mentions CASCADE;
TRUNCATE document_comments CASCADE;
TRUNCATE document_annotations CASCADE;
TRUNCATE document_versions CASCADE;
TRUNCATE notifications CASCADE;
TRUNCATE documents CASCADE;
TRUNCATE person_name_aliases CASCADE;
TRUNCATE persons CASCADE;
TRUNCATE tag CASCADE;
" --quiet

echo "Done. Database is clean."
