temp: add DB reset script (will remove after use)
This commit is contained in:
@@ -1,9 +1,16 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Run seed (creates test user if not exists)
|
# One-time DB reset (remove this block after running)
|
||||||
echo "Running database seed..."
|
if [ "$RESET_DB" = "true" ]; then
|
||||||
bun run db:seed || echo "Seed skipped or failed (may already exist)"
|
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
|
# Start the app
|
||||||
echo "Starting API..."
|
echo "Starting API..."
|
||||||
|
|||||||
0
package.json.tmp
Normal file
0
package.json.tmp
Normal file
29
src/reset-db.ts
Normal file
29
src/reset-db.ts
Normal file
@@ -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); });
|
||||||
Reference in New Issue
Block a user