temp: add DB reset script (will remove after use)
Some checks failed
CI/CD / check (push) Failing after 30s
CI/CD / deploy (push) Has been skipped

This commit is contained in:
2026-01-30 04:15:01 +00:00
parent 0ccfa8d0fc
commit ee3cfa263f
3 changed files with 39 additions and 3 deletions

29
src/reset-db.ts Normal file
View 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); });