""" Migration script to add time goals, category, and pomodoro settings to projects 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("PRAGMA table_info(projects)") columns = [column[1] for column in cursor.fetchall()] new_columns = [ ("category", "TEXT DEFAULT NULL"), ("weekly_hours_goal", "INTEGER DEFAULT NULL"), ("total_hours_goal", "INTEGER DEFAULT NULL"), ("pomodoro_work_minutes", "INTEGER DEFAULT 25"), ("pomodoro_break_minutes", "INTEGER DEFAULT 5"), ] for col_name, col_def in new_columns: if col_name in columns: print(f"Column '{col_name}' already exists. Skipping.") else: cursor.execute(f"ALTER TABLE projects ADD COLUMN {col_name} {col_def}") print(f"Successfully added '{col_name}'.") conn.commit() print("Migration complete.") except Exception as e: print(f"Error during migration: {e}") conn.rollback() finally: conn.close()