"""module_type_non_null

Revision ID: b9aadc10227f
Revises: bd2c1c3d866e
Create Date: 2022-02-15 21:47:29.212329

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.orm import sessionmaker  # added by ev

# revision identifiers, used by Alembic.
revision = "b9aadc10227f"
down_revision = "bd2c1c3d866e"
branch_labels = None
depends_on = None

Session = sessionmaker()


def upgrade():
    # Added by ev: remove duplicates
    bind = op.get_bind()
    session = Session(bind=bind)
    session.execute(
        """UPDATE notes_modules SET module_type=0 WHERE module_type IS NULL;"""
    )
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column(
        "notes_modules", "module_type", existing_type=sa.INTEGER(), nullable=False
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column(
        "notes_modules", "module_type", existing_type=sa.INTEGER(), nullable=True
    )
    # ### end Alembic commands ###
