""" Migration script to create the time_logs table. Run this once if you have an existing database. """ import sqlite3 import os db_path = os.path.join(os.path.dirname(__file__), 'bit.db') if not os.path.exists(db_path): print("No migration needed - new database will be created with the correct schema.") exit(0) conn = sqlite3.connect(db_path) cursor = conn.cursor() try: cursor.execute(""" CREATE TABLE IF NOT EXISTS time_logs ( id INTEGER PRIMARY KEY AUTOINCREMENT, task_id INTEGER NOT NULL REFERENCES tasks(id) ON DELETE CASCADE, minutes INTEGER NOT NULL, note TEXT, session_type TEXT DEFAULT 'manual', logged_at DATETIME DEFAULT CURRENT_TIMESTAMP ) """) conn.commit() print("Successfully created 'time_logs' table (or it already existed).") except Exception as e: print(f"Error during migration: {e}") conn.rollback() finally: conn.close()