"""Create the ``bookmarks`` table.

Revision ID: 0003
"""
from __future__ import annotations

from repo_core.migrations.builder import MigrationBuilder
from repo_core.migrations.runner import Migration

VERSION = "0003"


def get_postgres_migrations() -> list[Migration]:
    return [
        Migration(
            version="bookmark_0001",
            description="Create bookmarks table for user event bookmarks",
            up=(
                MigrationBuilder("bookmarks")
                .bigint("id", primary_key=True, nullable=False)
                .bigint("user_id", nullable=False)
                .varchar("target_type", 20, nullable=False, default="'event'")
                .varchar("target_id", 128, nullable=False)
                .timestamp("created_at", nullable=True, default="now()")
                .timestamp("updated_at", nullable=True, default="now()")
                .index(["user_id", "target_type", "target_id"], unique=True)
                .index(["target_type", "target_id"])
                .index(["user_id"])
                .foreign_key("user_id", "users")
                .create_table()
            ),
            down=MigrationBuilder("bookmarks").drop_table(),
        ),
    ]
