from __future__ import annotations

import sqlite3

from backend.database.migrations.runner import Migration


def upgrade(connection: sqlite3.Connection) -> None:
    connection.execute(
        """
        CREATE TABLE watchlist_entries (
            user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
            identifier TEXT NOT NULL,
            name TEXT NOT NULL,
            sector TEXT,
            created_at TEXT NOT NULL,
            PRIMARY KEY (user_id, identifier)
        )
        """
    )


def downgrade(connection: sqlite3.Connection) -> None:
    connection.execute("DROP TABLE watchlist_entries")


MIGRATION = Migration(
    version=6,
    name="create_account_watchlists",
    signature="accounts:v2:isolated-watchlist-entries",
    upgrade=upgrade,
    downgrade=downgrade,
)
