#!/usr/bin/env python3
"""
Migration script to add score_id column to playlist_entries table.
This allows playlist entries to optionally specify which score to use for a tune.
"""

import sqlite3
import sys
from pathlib import Path

# Add the project root to the path so we can import project modules
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))

from folkugat_web.config.db import DB_FILE


def main():
    print(f"Connecting to database at: {DB_FILE}")

    with sqlite3.connect(DB_FILE) as con:
        cur = con.cursor()

        # Check if score_id column already exists
        cur.execute("PRAGMA table_info(playlist_entries)")
        columns = [column[1] for column in cur.fetchall()]

        if 'score_id' not in columns:
            print("Adding score_id column to playlist_entries table...")
            cur.execute("ALTER TABLE playlist_entries ADD COLUMN score_id INTEGER")
            print("Column added successfully.")
        else:
            print("score_id column already exists.")

        con.commit()

    print("Migration completed successfully!")


if __name__ == "__main__":
    main()
