"""create license keys

Revision ID: 11e95720e068
Revises: f8c558160179
Create Date: 2024-08-09 22:47:23.750435

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "11e95720e068"
down_revision = "f8c558160179"
branch_labels: tuple[str] | None = None
depends_on: tuple[str] | None = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "license_keys",
        sa.Column("user_id", sa.Uuid(), nullable=False),
        sa.Column("benefit_id", sa.Uuid(), nullable=False),
        sa.Column("key", sa.String(), nullable=False),
        sa.Column("status", sa.String(), nullable=False),
        sa.Column("activations", sa.Integer(), nullable=False),
        sa.Column("activation_limit", sa.Integer(), nullable=True),
        sa.Column("last_activated_at", sa.TIMESTAMP(timezone=True), nullable=True),
        sa.Column("expires_at", sa.TIMESTAMP(timezone=True), nullable=True),
        sa.Column("id", sa.Uuid(), nullable=False),
        sa.Column("created_at", sa.TIMESTAMP(timezone=True), nullable=False),
        sa.Column("modified_at", sa.TIMESTAMP(timezone=True), nullable=True),
        sa.Column("deleted_at", sa.TIMESTAMP(timezone=True), nullable=True),
        sa.ForeignKeyConstraint(
            ["benefit_id"],
            ["benefits.id"],
            name=op.f("license_keys_benefit_id_fkey"),
            ondelete="cascade",
        ),
        sa.ForeignKeyConstraint(
            ["user_id"],
            ["users.id"],
            name=op.f("license_keys_user_id_fkey"),
            ondelete="cascade",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("license_keys_pkey")),
    )
    op.create_index(
        op.f("ix_license_keys_benefit_id"), "license_keys", ["benefit_id"], unique=False
    )
    op.create_index(
        op.f("ix_license_keys_created_at"), "license_keys", ["created_at"], unique=False
    )
    op.create_index(
        op.f("ix_license_keys_deleted_at"), "license_keys", ["deleted_at"], unique=False
    )
    op.create_index(
        op.f("ix_license_keys_modified_at"),
        "license_keys",
        ["modified_at"],
        unique=False,
    )
    op.create_index(
        op.f("ix_license_keys_user_id"), "license_keys", ["user_id"], unique=False
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_license_keys_user_id"), table_name="license_keys")
    op.drop_index(op.f("ix_license_keys_modified_at"), table_name="license_keys")
    op.drop_index(op.f("ix_license_keys_deleted_at"), table_name="license_keys")
    op.drop_index(op.f("ix_license_keys_created_at"), table_name="license_keys")
    op.drop_index(op.f("ix_license_keys_benefit_id"), table_name="license_keys")
    op.drop_table("license_keys")
    # ### end Alembic commands ###
