"""Update Article model

Revision ID: 317b6bf2a6d9
Revises: ca130161bf6a
Create Date: 2024-06-26 09:38:31.856885

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

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


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column(
        "articles",
        "created_by",
        existing_nullable=False,
        nullable=True,
        new_column_name="user_id",
    )
    op.drop_constraint("articles_created_by_fkey", "articles", type_="foreignkey")
    op.create_foreign_key(
        op.f("articles_user_id_fkey"), "articles", "users", ["user_id"], ["id"]
    )
    op.drop_column("articles", "web_view_count")
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column(
        "articles",
        "user_id",
        existing_nullable=True,
        nullable=False,
        new_column_name="created_by",
    )
    op.add_column(
        "articles",
        sa.Column("web_view_count", sa.INTEGER(), autoincrement=False, nullable=False),
    )
    op.drop_constraint(op.f("articles_user_id_fkey"), "articles", type_="foreignkey")
    op.create_foreign_key(
        "articles_created_by_fkey", "articles", "users", ["created_by"], ["id"]
    )
    # ### end Alembic commands ###
