From ee3cfa263f69084bd4d7cd0d683b28971f657b98 Mon Sep 17 00:00:00 2001 From: Hammer Date: Fri, 30 Jan 2026 04:15:01 +0000 Subject: [PATCH] temp: add DB reset script (will remove after use) --- entrypoint.sh | 13 ++++++++++--- package.json.tmp | 0 src/reset-db.ts | 29 +++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 package.json.tmp create mode 100644 src/reset-db.ts diff --git a/entrypoint.sh b/entrypoint.sh index fb89576..74d77e2 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,9 +1,16 @@ #!/bin/bash set -e -# Run seed (creates test user if not exists) -echo "Running database seed..." -bun run db:seed || echo "Seed skipped or failed (may already exist)" +# One-time DB reset (remove this block after running) +if [ "$RESET_DB" = "true" ]; then + echo "🔴 RESETTING DATABASE..." + bun run src/reset-db.ts + echo "✅ Database reset complete" +fi + +# Push schema +echo "Running db:push..." +bun run db:push || echo "db:push skipped" # Start the app echo "Starting API..." diff --git a/package.json.tmp b/package.json.tmp new file mode 100644 index 0000000..e69de29 diff --git a/src/reset-db.ts b/src/reset-db.ts new file mode 100644 index 0000000..9cf5ec2 --- /dev/null +++ b/src/reset-db.ts @@ -0,0 +1,29 @@ +import { db } from './db'; +import { sql } from 'drizzle-orm'; + +async function resetDatabase() { + console.log('Clearing all data...'); + + // Disable FK constraints temporarily + await db.execute(sql`SET session_replication_role = 'replica'`); + + // Get all tables + const tables = await db.execute(sql` + SELECT tablename FROM pg_tables WHERE schemaname = 'public' + `); + + for (const row of tables.rows) { + const table = (row as any).tablename; + if (table === '__drizzle_migrations' || table === 'pg_boss') continue; + console.log(` Truncating ${table}...`); + await db.execute(sql.raw(`TRUNCATE TABLE "${table}" CASCADE`)); + } + + // Re-enable FK constraints + await db.execute(sql`SET session_replication_role = 'origin'`); + + console.log('Database cleared!'); + process.exit(0); +} + +resetDatabase().catch(e => { console.error(e); process.exit(1); });