"""Add filter_presets table.

Revision ID: 009_filter_presets
Revises: 008_password_reset_tokens
"""

from alembic import op
import sqlalchemy as sa

revision = "009_filter_presets"
down_revision = "008_password_reset_tokens"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.create_table(
        "filter_presets",
        sa.Column("id", sa.Integer, primary_key=True, autoincrement=True),
        sa.Column(
            "user_id",
            sa.Integer,
            sa.ForeignKey("users.id", ondelete="CASCADE"),
            nullable=False,
        ),
        sa.Column("name", sa.String(100), nullable=False),
        sa.Column("filters", sa.String(1000), nullable=False),
        sa.Column(
            "created_at",
            sa.DateTime,
            nullable=False,
            server_default=sa.func.now(),
        ),
    )
    op.create_index("idx_fp_user", "filter_presets", ["user_id"])


def downgrade() -> None:
    op.drop_index("idx_fp_user", table_name="filter_presets")
    op.drop_table("filter_presets")
