
import Database from 'better-sqlite3';

// Use DATABASE_URL if provided, else default
// DATABASE_URL from Prisma usually starts with 'file:'
let dbPath = process.env.DATABASE_URL || './prisma/test.db';
if (dbPath.startsWith('file:')) {
    dbPath = dbPath.slice(5);
}

console.log(`Resetting DB at ${dbPath}`);

try {
    const db = new Database(dbPath);
    // Enable Foreign Keys to ensure cascading deletes work
    db.pragma('foreign_keys = ON');

    // Optional: WAL mode typically used in app
    // db.pragma('journal_mode = WAL'); 

    const info = db.prepare('DELETE FROM User').run();
    console.log(`Deleted ${info.changes} users.`);
    db.close();
} catch (error) {
    console.error('Failed to reset DB:', error);
    process.exit(1);
}
