36 lines
916 B
TypeScript
36 lines
916 B
TypeScript
import "dotenv/config"
|
|
import { db } from "@/shared/db"
|
|
import { sql } from "drizzle-orm"
|
|
|
|
async function reset() {
|
|
console.log("🔥 Resetting database...")
|
|
|
|
// Disable foreign key checks
|
|
await db.execute(sql`SET FOREIGN_KEY_CHECKS = 0;`)
|
|
|
|
// Get all table names
|
|
const tables = await db.execute(sql`
|
|
SELECT table_name
|
|
FROM information_schema.tables
|
|
WHERE table_schema = DATABASE();
|
|
`)
|
|
|
|
// Drop each table
|
|
for (const row of (tables[0] as unknown as any[])) {
|
|
const tableName = row.TABLE_NAME || row.table_name
|
|
console.log(`Dropping table: ${tableName}`)
|
|
await db.execute(sql.raw(`DROP TABLE IF EXISTS \`${tableName}\`;`))
|
|
}
|
|
|
|
// Re-enable foreign key checks
|
|
await db.execute(sql`SET FOREIGN_KEY_CHECKS = 1;`)
|
|
|
|
console.log("✅ Database reset complete.")
|
|
process.exit(0)
|
|
}
|
|
|
|
reset().catch((err) => {
|
|
console.error("❌ Reset failed:", err)
|
|
process.exit(1)
|
|
})
|