"""v1-messages

Revision ID: b01986f67aa3
Revises: <KEY>
Create Date: 2022-06-01 16:00:25.954662

"""
from alembic import op
import sqlalchemy as sa
import sqlmodel
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = "<KEY>"
down_revision = "c9b007919a5d"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "message",
        sa.Column(
            "message_id",
            postgresql.UUID(as_uuid=True),
            server_default=sa.text("gen_random_uuid()"),
            nullable=False,
        ),
        sa.Column("tags", postgresql.ARRAY(sa.String()), nullable=True),
        sa.Column("sent_time", postgresql.TIMESTAMP(), nullable=True),
        sa.Column(
            "created_at",
            postgresql.TIMESTAMP(),
            server_default=sa.text("now()"),
            nullable=False,
        ),
        sa.Column(
            "updated_at",
            postgresql.TIMESTAMP(),
            server_default=sa.text("now()"),
            nullable=False,
        ),
        sa.Column("tenant_id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
        sa.Column("contact_id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
        sa.Column("status", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
        sa.Column("role", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
        sa.Column("deleted", sa.Boolean(), nullable=False),
        sa.Column("content", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
        sa.Column(
            "revocation_comment", sqlmodel.sql.sqltypes.AutoString(), nullable=True
        ),
        sa.Column("state", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
        sa.ForeignKeyConstraint(
            ["contact_id"],
            ["contact.contact_id"],
        ),
        sa.ForeignKeyConstraint(
            ["tenant_id"],
            ["tenant.id"],
        ),
        sa.PrimaryKeyConstraint("message_id"),
    )
    op.create_index(
        op.f("ix_message_contact_id"), "message", ["contact_id"], unique=False
    )
    op.create_index(
        op.f("ix_message_tenant_id"), "message", ["tenant_id"], unique=False
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_message_tenant_id"), table_name="message")
    op.drop_index(op.f("ix_message_contact_id"), table_name="message")
    op.drop_table("message")
    # ### end Alembic commands ###

alembic.op.drop_table alembic.op.f sqlmodel.sql.sqltypes.AutoString sqlalchemy.PrimaryKeyConstraint sqlalchemy.dialects.postgresql.TIMESTAMP sqlmodel.sql.sqltypes.GUID sqlalchemy.dialects.postgresql.UUID sqlalchemy.Boolean sqlalchemy.text sqlalchemy.ForeignKeyConstraint sqlalchemy.String
[((2506, 2530), 'alembic.op.drop_table', 'op.drop_table', (['"""message"""'], {}), "('message')\n", (2519, 2530), False, 'from alembic import op\n'), ((1780, 1843), 'sqlalchemy.ForeignKeyConstraint', 'sa.ForeignKeyConstraint', (["['contact_id']", "['contact.contact_id']"], {}), "(['contact_id'], ['contact.contact_id'])\n", (1803, 1843), True, 'import sqlalchemy as sa\n'), ((1888, 1941), 'sqlalchemy.ForeignKeyConstraint', 'sa.ForeignKeyConstraint', (["['tenant_id']", "['tenant.id']"], {}), "(['tenant_id'], ['tenant.id'])\n", (1911, 1941), True, 'import sqlalchemy as sa\n'), ((1986, 2023), 'sqlalchemy.PrimaryKeyConstraint', 'sa.PrimaryKeyConstraint', (['"""message_id"""'], {}), "('message_id')\n", (2009, 2023), True, 'import sqlalchemy as sa\n'), ((2060, 2089), 'alembic.op.f', 'op.f', (['"""ix_message_contact_id"""'], {}), "('ix_message_contact_id')\n", (2064, 2089), False, 'from alembic import op\n'), ((2166, 2194), 'alembic.op.f', 'op.f', (['"""ix_message_tenant_id"""'], {}), "('ix_message_tenant_id')\n", (2170, 2194), False, 'from alembic import op\n'), ((2379, 2407), 'alembic.op.f', 'op.f', (['"""ix_message_tenant_id"""'], {}), "('ix_message_tenant_id')\n", (2383, 2407), False, 'from alembic import op\n'), ((2449, 2478), 'alembic.op.f', 'op.f', (['"""ix_message_contact_id"""'], {}), "('ix_message_contact_id')\n", (2453, 2478), False, 'from alembic import op\n'), ((519, 548), 'sqlalchemy.dialects.postgresql.UUID', 'postgresql.UUID', ([], {'as_uuid': '(True)'}), '(as_uuid=True)\n', (534, 548), False, 'from sqlalchemy.dialects import postgresql\n'), ((750, 772), 'sqlalchemy.dialects.postgresql.TIMESTAMP', 'postgresql.TIMESTAMP', ([], {}), '()\n', (770, 772), False, 'from sqlalchemy.dialects import postgresql\n'), ((847, 869), 'sqlalchemy.dialects.postgresql.TIMESTAMP', 'postgresql.TIMESTAMP', ([], {}), '()\n', (867, 869), False, 'from sqlalchemy.dialects import postgresql\n'), ((1012, 1034), 'sqlalchemy.dialects.postgresql.TIMESTAMP', 'postgresql.TIMESTAMP', ([], {}), '()\n', (1032, 1034), False, 'from sqlalchemy.dialects import postgresql\n'), ((1151, 1179), 'sqlmodel.sql.sqltypes.GUID', 'sqlmodel.sql.sqltypes.GUID', ([], {}), '()\n', (1177, 1179), False, 'import sqlmodel\n'), ((1230, 1258), 'sqlmodel.sql.sqltypes.GUID', 'sqlmodel.sql.sqltypes.GUID', ([], {}), '()\n', (1256, 1258), False, 'import sqlmodel\n'), ((1305, 1339), 'sqlmodel.sql.sqltypes.AutoString', 'sqlmodel.sql.sqltypes.AutoString', ([], {}), '()\n', (1337, 1339), False, 'import sqlmodel\n'), ((1384, 1418), 'sqlmodel.sql.sqltypes.AutoString', 'sqlmodel.sql.sqltypes.AutoString', ([], {}), '()\n', (1416, 1418), False, 'import sqlmodel\n'), ((1466, 1478), 'sqlalchemy.Boolean', 'sa.Boolean', ([], {}), '()\n', (1476, 1478), True, 'import sqlalchemy as sa\n'), ((1526, 1560), 'sqlmodel.sql.sqltypes.AutoString', 'sqlmodel.sql.sqltypes.AutoString', ([], {}), '()\n', (1558, 1560), False, 'import sqlmodel\n'), ((1631, 1665), 'sqlmodel.sql.sqltypes.AutoString', 'sqlmodel.sql.sqltypes.AutoString', ([], {}), '()\n', (1663, 1665), False, 'import sqlmodel\n'), ((1719, 1753), 'sqlmodel.sql.sqltypes.AutoString', 'sqlmodel.sql.sqltypes.AutoString', ([], {}), '()\n', (1751, 1753), False, 'import sqlmodel\n'), ((577, 605), 'sqlalchemy.text', 'sa.text', (['"""gen_random_uuid()"""'], {}), "('gen_random_uuid()')\n", (584, 605), True, 'import sqlalchemy as sa\n'), ((689, 700), 'sqlalchemy.String', 'sa.String', ([], {}), '()\n', (698, 700), True, 'import sqlalchemy as sa\n'), ((898, 914), 'sqlalchemy.text', 'sa.text', (['"""now()"""'], {}), "('now()')\n", (905, 914), True, 'import sqlalchemy as sa\n'), ((1063, 1079), 'sqlalchemy.text', 'sa.text', (['"""now()"""'], {}), "('now()')\n", (1070, 1079), True, 'import sqlalchemy as sa\n')]