"""
创建推进器数据库表结构
"""

import sqlite3


def create_tables():
    """创建数据库表"""
    conn = sqlite3.connect("F:/openclaw-saas/tracker.db")
    cursor = conn.cursor()

    # 创建 tasks 表
    cursor.execute("""
        CREATE TABLE IF NOT EXISTS tasks (
            id INTEGER PRIMARY KEY AUTOINCREMENT,
            name TEXT NOT NULL,
            description TEXT,
            status TEXT DEFAULT 'pending',
            phase TEXT,
            milestone TEXT,
            priority TEXT DEFAULT 'medium',
            estimated_hours REAL,
            actual_hours REAL,
            created_at TEXT,
            started_at TEXT,
            completed_at TEXT,
            assigned_to TEXT,
            tags TEXT
        )
    """)

    print("[OK] tasks 表创建成功")

    # 创建 milestones 表
    cursor.execute("""
        CREATE TABLE IF NOT EXISTS milestones (
            id INTEGER PRIMARY KEY AUTOINCREMENT,
            name TEXT NOT NULL,
            phase TEXT,
            start_date TEXT,
            end_date TEXT,
            status TEXT DEFAULT 'pending',
            description TEXT
        )
    """)

    print("[OK] milestones 表创建成功")

    # 创建 logs 表
    cursor.execute("""
        CREATE TABLE IF NOT EXISTS logs (
            id INTEGER PRIMARY KEY AUTOINCREMENT,
            task_id INTEGER,
            message TEXT,
            created_at TEXT,
            FOREIGN KEY (task_id) REFERENCES tasks (id)
        )
    """)

    print("[OK] logs 表创建成功")

    conn.commit()
    conn.close()

    print("\n[SUCCESS] 数据库表结构创建完成！")


if __name__ == "__main__":
    create_tables()
