The application uses Flyway to manage the database schema automatically.
The PostgreSQL database uses the hampex schema.
The Flyway migration history is stored in flyway_schema_history and must never be manually deleted.
pg_dump available (included in the Postgres container)docker exec <postgres-container-name> \
pg_dump -U hampex hampex \
> backup_$(date +%Y%m%d_%H%M%S).sql
Store the backup in a safe location before proceeding.
---
Step 2 — Option A: Clear Data Only (Recommended)
This removes all customer/test data while keeping the schema and Flyway history intact.
docker exec -i <postgres-container-name> \
psql -U hampex -d hampex << 'EOF'
SET search_path TO hampex;
TRUNCATE TABLE
invoice_item,
invoice,
cash_transaction,
cash_register,
proposal_item,
proposal,
article_group,
article,
category,
container,
shop,
app_user
RESTART IDENTITY CASCADE;
EOF
What this does:
- Deletes all rows in the correct dependency order
- Resets all auto-increment sequences to 1
- CASCADE ensures no foreign key violations
- Flyway history is untouched — no re-migration needed
---
Step 2 — Option B: Full Reset (Nuclear Option)
Use this only if the schema itself is broken or you want a completely clean slate.
▎ ⚠️ Warning: This also deletes all Keycloak users and realm configuration.
▎ You must re-import the Keycloak realm after this step.
# Stop all containers
docker compose -f deployment/docker/docker-compose.yml down
# Remove the database volume
docker volume rm hampex-postgres-data
# Start again — Flyway rebuilds schema from V1 to V38
docker compose -f deployment/docker/docker-compose.yml up -d
# Re-import Keycloak realm
# (see: Keycloak Configuration page)
---
Step 3 — Verify
After clearing the data, verify the application starts correctly:
# Check backend logs for Flyway output
docker compose logs backend --tail=50
# Expected output:
# Flyway: Successfully validated 38 migrations
# Flyway: Current version of schema "hampex": 38
---
What NOT to Do
┌──────────────────────────────────────┬────────────────────────────────────┐
│ Action │ Risk │
├──────────────────────────────────────┼────────────────────────────────────┤
│ DROP SCHEMA hampex CASCADE │ Destroys schema + Flyway history │
├──────────────────────────────────────┼────────────────────────────────────┤
│ docker volume rm without backup │ Unrecoverable data loss │
├──────────────────────────────────────┼────────────────────────────────────┤
│ Delete from tables in wrong order │ Foreign key constraint errors │
├──────────────────────────────────────┼────────────────────────────────────┤
│ Run seed_test_data.sql in production │ Adds dummy articles and categories │
└──────────────────────────────────────┴────────────────────────────────────┘