"""Remove Traffic

Revision ID: a2f8da11b9ce
Revises: abf0500d13b7
Create Date: 2024-10-23 17:52:55.632404

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

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


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index("idx_article_id_date", table_name="traffic")
    op.drop_index("idx_organization_id_date", table_name="traffic")
    op.drop_table("traffic")
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "traffic",
        sa.Column("id", sa.UUID(), autoincrement=False, nullable=False),
        sa.Column("article_id", sa.UUID(), autoincrement=False, nullable=True),
        sa.Column("organization_id", sa.UUID(), autoincrement=False, nullable=True),
        sa.Column("date", sa.DATE(), autoincrement=False, nullable=False),
        sa.Column("views", sa.INTEGER(), autoincrement=False, nullable=False),
        sa.Column("location_href", sa.VARCHAR(), autoincrement=False, nullable=True),
        sa.Column("referrer", sa.VARCHAR(), autoincrement=False, nullable=True),
        sa.ForeignKeyConstraint(
            ["article_id"], ["articles.id"], name="traffic_article_id_fkey"
        ),
        sa.ForeignKeyConstraint(
            ["organization_id"],
            ["organizations.id"],
            name="traffic_organization_id_fkey",
        ),
        sa.PrimaryKeyConstraint("id", name="traffic_pkey"),
        sa.UniqueConstraint(
            "organization_id",
            "article_id",
            "date",
            "location_href",
            "referrer",
            name="traffic_unique_key",
            postgresql_nulls_not_distinct=True,
        ),
    )
    op.create_index(
        "idx_organization_id_date", "traffic", ["organization_id", "date"], unique=False
    )
    op.create_index(
        "idx_article_id_date", "traffic", ["article_id", "date"], unique=False
    )
    # ### end Alembic commands ###
