import Database from "better-sqlite3"; const db = new Database("./data/database.sqlite"); console.log("Adding user tracking columns to notes table...\n"); try { console.log("Adding created_by column..."); db.exec(`ALTER TABLE notes ADD COLUMN created_by TEXT;`); console.log("āœ“ created_by column added"); } catch (e) { console.log("created_by column already exists or error:", e.message); } try { console.log("Adding is_system column..."); db.exec(`ALTER TABLE notes ADD COLUMN is_system INTEGER DEFAULT 0;`); console.log("āœ“ is_system column added"); } catch (e) { console.log("is_system column already exists or error:", e.message); } console.log("\nVerifying columns were added..."); const schema = db.prepare("PRAGMA table_info(notes)").all(); const hasCreatedBy = schema.some((col) => col.name === "created_by"); const hasIsSystem = schema.some((col) => col.name === "is_system"); console.log("created_by exists:", hasCreatedBy); console.log("is_system exists:", hasIsSystem); if (hasCreatedBy && hasIsSystem) { console.log("\nāœ… All columns are now present!"); // Test a manual insert console.log("\nTesting manual note insert..."); try { const result = db .prepare( ` INSERT INTO notes (project_id, note, created_by, is_system, note_date) VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP) ` ) .run(1, "Test note with user tracking", "test-user-id", 0); console.log("Insert successful, ID:", result.lastInsertRowid); // Clean up db.prepare("DELETE FROM notes WHERE note_id = ?").run( result.lastInsertRowid ); console.log("Test record cleaned up"); } catch (error) { console.error("Insert failed:", error.message); } } else { console.log("\nāŒ Some columns are still missing"); } db.close();