"""user latest record

Revision ID: 7c2a518ed636
Revises: fe2df95ee61a
Create Date: 2021-11-27 15:37:54.561822

"""
import sqlalchemy as sa
import sqlmodel
import sqlmodel.sql.sqltypes
from alembic import op

# revision identifiers, used by Alembic.
revision = "7c2a518ed636"
down_revision = "fe2df95ee61a"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "user_latest_records",
        sa.Column(
            "created_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("TIMEZONE('utc', CURRENT_TIMESTAMP)"),
            nullable=False,
        ),
        sa.Column(
            "updated_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("TIMEZONE('utc', CURRENT_TIMESTAMP)"),
            nullable=False,
        ),
        sa.Column("user_id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
        sa.Column("problem_id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
        sa.Column("problem_set_id", sqlmodel.sql.sqltypes.GUID(), nullable=True),
        sa.Column("record_id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
        sa.Column("id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
        sa.ForeignKeyConstraint(["problem_id"], ["problems.id"], ondelete="CASCADE"),
        sa.ForeignKeyConstraint(
            ["problem_set_id"], ["problem_sets.id"], ondelete="CASCADE"
        ),
        sa.ForeignKeyConstraint(["record_id"], ["records.id"], ondelete="CASCADE"),
        sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="CASCADE"),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("user_id", "problem_id", "problem_set_id", "record_id"),
    )
    op.create_index(
        op.f("ix_user_latest_records_created_at"),
        "user_latest_records",
        ["created_at"],
        unique=False,
    )
    op.create_index(
        op.f("ix_user_latest_records_id"), "user_latest_records", ["id"], unique=False
    )
    op.create_index(
        op.f("ix_user_latest_records_updated_at"),
        "user_latest_records",
        ["updated_at"],
        unique=False,
    )
    op.add_column(
        "problem_configs",
        sa.Column(
            "commit_message",
            sqlmodel.sql.sqltypes.AutoString(),
            server_default="",
            nullable=False,
        ),
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column("problem_configs", "commit_message")
    op.drop_index(
        op.f("ix_user_latest_records_updated_at"), table_name="user_latest_records"
    )
    op.drop_index(op.f("ix_user_latest_records_id"), table_name="user_latest_records")
    op.drop_index(
        op.f("ix_user_latest_records_created_at"), table_name="user_latest_records"
    )
    op.drop_table("user_latest_records")
    # ### end Alembic commands ###

alembic.op.drop_table sqlalchemy.DateTime alembic.op.f sqlmodel.sql.sqltypes.AutoString sqlalchemy.PrimaryKeyConstraint sqlmodel.sql.sqltypes.GUID alembic.op.drop_column sqlalchemy.text sqlalchemy.UniqueConstraint sqlalchemy.ForeignKeyConstraint
[((2542, 2593), 'alembic.op.drop_column', 'op.drop_column', (['"""problem_configs"""', '"""commit_message"""'], {}), "('problem_configs', 'commit_message')\n", (2556, 2593), False, 'from alembic import op\n'), ((2903, 2939), 'alembic.op.drop_table', 'op.drop_table', (['"""user_latest_records"""'], {}), "('user_latest_records')\n", (2916, 2939), False, 'from alembic import op\n'), ((1279, 1355), 'sqlalchemy.ForeignKeyConstraint', 'sa.ForeignKeyConstraint', (["['problem_id']", "['problems.id']"], {'ondelete': '"""CASCADE"""'}), "(['problem_id'], ['problems.id'], ondelete='CASCADE')\n", (1302, 1355), True, 'import sqlalchemy as sa\n'), ((1365, 1454), 'sqlalchemy.ForeignKeyConstraint', 'sa.ForeignKeyConstraint', (["['problem_set_id']", "['problem_sets.id']"], {'ondelete': '"""CASCADE"""'}), "(['problem_set_id'], ['problem_sets.id'], ondelete=\n    'CASCADE')\n", (1388, 1454), True, 'import sqlalchemy as sa\n'), ((1481, 1555), 'sqlalchemy.ForeignKeyConstraint', 'sa.ForeignKeyConstraint', (["['record_id']", "['records.id']"], {'ondelete': '"""CASCADE"""'}), "(['record_id'], ['records.id'], ondelete='CASCADE')\n", (1504, 1555), True, 'import sqlalchemy as sa\n'), ((1565, 1635), 'sqlalchemy.ForeignKeyConstraint', 'sa.ForeignKeyConstraint', (["['user_id']", "['users.id']"], {'ondelete': '"""CASCADE"""'}), "(['user_id'], ['users.id'], ondelete='CASCADE')\n", (1588, 1635), True, 'import sqlalchemy as sa\n'), ((1645, 1674), 'sqlalchemy.PrimaryKeyConstraint', 'sa.PrimaryKeyConstraint', (['"""id"""'], {}), "('id')\n", (1668, 1674), True, 'import sqlalchemy as sa\n'), ((1684, 1759), 'sqlalchemy.UniqueConstraint', 'sa.UniqueConstraint', (['"""user_id"""', '"""problem_id"""', '"""problem_set_id"""', '"""record_id"""'], {}), "('user_id', 'problem_id', 'problem_set_id', 'record_id')\n", (1703, 1759), True, 'import sqlalchemy as sa\n'), ((1796, 1837), 'alembic.op.f', 'op.f', (['"""ix_user_latest_records_created_at"""'], {}), "('ix_user_latest_records_created_at')\n", (1800, 1837), False, 'from alembic import op\n'), ((1951, 1984), 'alembic.op.f', 'op.f', (['"""ix_user_latest_records_id"""'], {}), "('ix_user_latest_records_id')\n", (1955, 1984), False, 'from alembic import op\n'), ((2065, 2106), 'alembic.op.f', 'op.f', (['"""ix_user_latest_records_updated_at"""'], {}), "('ix_user_latest_records_updated_at')\n", (2069, 2106), False, 'from alembic import op\n'), ((2621, 2662), 'alembic.op.f', 'op.f', (['"""ix_user_latest_records_updated_at"""'], {}), "('ix_user_latest_records_updated_at')\n", (2625, 2662), False, 'from alembic import op\n'), ((2721, 2754), 'alembic.op.f', 'op.f', (['"""ix_user_latest_records_id"""'], {}), "('ix_user_latest_records_id')\n", (2725, 2754), False, 'from alembic import op\n'), ((2817, 2858), 'alembic.op.f', 'op.f', (['"""ix_user_latest_records_created_at"""'], {}), "('ix_user_latest_records_created_at')\n", (2821, 2858), False, 'from alembic import op\n'), ((546, 572), 'sqlalchemy.DateTime', 'sa.DateTime', ([], {'timezone': '(True)'}), '(timezone=True)\n', (557, 572), True, 'import sqlalchemy as sa\n'), ((744, 770), 'sqlalchemy.DateTime', 'sa.DateTime', ([], {'timezone': '(True)'}), '(timezone=True)\n', (755, 770), True, 'import sqlalchemy as sa\n'), ((914, 942), 'sqlmodel.sql.sqltypes.GUID', 'sqlmodel.sql.sqltypes.GUID', ([], {}), '()\n', (940, 942), False, 'import sqlmodel\n'), ((993, 1021), 'sqlmodel.sql.sqltypes.GUID', 'sqlmodel.sql.sqltypes.GUID', ([], {}), '()\n', (1019, 1021), False, 'import sqlmodel\n'), ((1076, 1104), 'sqlmodel.sql.sqltypes.GUID', 'sqlmodel.sql.sqltypes.GUID', ([], {}), '()\n', (1102, 1104), False, 'import sqlmodel\n'), ((1153, 1181), 'sqlmodel.sql.sqltypes.GUID', 'sqlmodel.sql.sqltypes.GUID', ([], {}), '()\n', (1179, 1181), False, 'import sqlmodel\n'), ((1224, 1252), 'sqlmodel.sql.sqltypes.GUID', 'sqlmodel.sql.sqltypes.GUID', ([], {}), '()\n', (1250, 1252), False, 'import sqlmodel\n'), ((2298, 2332), 'sqlmodel.sql.sqltypes.AutoString', 'sqlmodel.sql.sqltypes.AutoString', ([], {}), '()\n', (2330, 2332), False, 'import sqlmodel\n'), ((601, 646), 'sqlalchemy.text', 'sa.text', (['"""TIMEZONE(\'utc\', CURRENT_TIMESTAMP)"""'], {}), '("TIMEZONE(\'utc\', CURRENT_TIMESTAMP)")\n', (608, 646), True, 'import sqlalchemy as sa\n'), ((799, 844), 'sqlalchemy.text', 'sa.text', (['"""TIMEZONE(\'utc\', CURRENT_TIMESTAMP)"""'], {}), '("TIMEZONE(\'utc\', CURRENT_TIMESTAMP)")\n', (806, 844), True, 'import sqlalchemy as sa\n')]