"""trusted messages

Revision ID: eef5f95853bf
Revises: 0bfde82697c8
Create Date: 2023-01-23 22:10:41.623055

"""
from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = "eef5f95853bf"
down_revision = "0bfde82697c8"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    #
    op.alter_column(
        "forgotten_messages", "signature", existing_type=sa.VARCHAR(), nullable=True
    )
    op.alter_column("messages", "signature", existing_type=sa.VARCHAR(), nullable=True)
    op.alter_column(
        "pending_messages", "signature", existing_type=sa.VARCHAR(), nullable=True
    )
    op.execute(
        """
        alter table pending_messages add constraint signature_not_null_if_check_message 
            CHECK(signature is not null or not check_message)
    """
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.execute(
        "alter table pending_messages drop constraint signature_not_null_if_check_message"
    )
    op.alter_column(
        "pending_messages", "signature", existing_type=sa.VARCHAR(), nullable=False
    )
    op.alter_column("messages", "signature", existing_type=sa.VARCHAR(), nullable=False)
    op.alter_column(
        "forgotten_messages", "signature", existing_type=sa.VARCHAR(), nullable=False
    )
    # ### end Alembic commands ###
