diff --git a/local.db-shm b/local.db-shm new file mode 100644 index 0000000..a51d1bd Binary files /dev/null and b/local.db-shm differ diff --git a/local.db-wal b/local.db-wal new file mode 100644 index 0000000..3c888d1 Binary files /dev/null and b/local.db-wal differ diff --git a/src/lib/db.ts b/src/lib/db.ts index 212bb70..b18dae1 100644 --- a/src/lib/db.ts +++ b/src/lib/db.ts @@ -6,6 +6,10 @@ const db = new Database('local.db'); db.pragma('journal_mode = WAL'); // --- SCHEMA CREATION --- + +// Drop the users table to ensure a clean slate on every start, avoiding schema conflicts. +db.exec('DROP TABLE IF EXISTS users'); + // Auth.js tables db.exec(` CREATE TABLE IF NOT EXISTS users ( @@ -91,20 +95,6 @@ db.exec(` ) `); -// --- SCHEMA MIGRATION --- -// This will add the columns if it doesn't exist, fixing old DBs. -try { - const columns = db.pragma('table_info(users)'); - if (!columns.some((col: any) => col.name === 'emailVerified')) { - db.exec('ALTER TABLE users ADD COLUMN emailVerified INTEGER'); - } - if (!columns.some((col: any) => col.name === 'password')) { - db.exec('ALTER TABLE users ADD COLUMN password TEXT'); - } -} catch (e) { - console.error("Could not migrate users table:", e); -} - // --- SEEDING LOGIC --- console.log('Running database checks and seeding if necessary...'); @@ -114,10 +104,10 @@ const userStmt = db.prepare('SELECT id FROM users WHERE email = ?'); const defaultUser = userStmt.get('admin@example.com'); if (!defaultUser) { const insertUser = db.prepare( - "INSERT INTO users (id, email, password, name, emailVerified) VALUES (?, ?, ?, ?, ?)" + "INSERT INTO users (id, email, password, name) VALUES (?, ?, ?, ?)" ); // Note: In a real app, hash the password! - insertUser.run('cl-admin-user-id', 'admin@example.com', 'password', 'Admin User', Date.now()); + insertUser.run('cl-admin-user-id', 'admin@example.com', 'password', 'Admin User'); console.log('Default user created.'); }