"""empty message

Revision ID: b2a479e69d35
Revises: ce9aacd4d1df
Create Date: 2021-01-20 22:28:03.325288

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'b2a479e69d35'
down_revision = 'ce9aacd4d1df'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###

    # sqlalchemy.Column's "default" parameter doesn't work here. So added some work-around to accommondate existing data.
    op.add_column('todo_item', sa.Column('completed', sa.Boolean(), nullable=True, default=False))

    # Use IS keyword to detect NULL value in SQL
    op.execute('UPDATE todo_item SET completed = False WHERE completed IS NULL;')

    op.alter_column('todo_item','completed', nullable=False)

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('todo_item', 'completed')
    # ### end Alembic commands ###
