"""deal_total_nullable_false

Revision ID: af73ea65beca
Revises: 3b56ce3d3121
Create Date: 2021-05-12 13:41:38.368553

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'af73ea65beca'
down_revision = '3b56ce3d3121'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.execute('update cmf_deal set total=0 where total is null')
    op.execute('update cmf_deal set total_without_discount=0 where total_without_discount is null')
    op.execute('update cmf_sales_order set total=0 where total is null')
    op.execute('update cmf_sales_order set total_discount=0 where total_discount is null')
    op.execute('update cmf_sales_order set total_tax=0 where total_tax is null')
    op.execute('update cmf_sales_order set total_without_discount=0 where total_without_discount is null')
    op.alter_column('cmf_deal', 'total',
               existing_type=sa.NUMERIC(precision=14, scale=2),
               nullable=False)
    op.alter_column('cmf_deal', 'total_without_discount',
               existing_type=sa.NUMERIC(precision=14, scale=2),
               nullable=False)
    op.alter_column('cmf_sales_order', 'total',
               existing_type=sa.NUMERIC(precision=14, scale=2),
               nullable=False)
    op.alter_column('cmf_sales_order', 'total_discount',
               existing_type=sa.NUMERIC(precision=14, scale=2),
               nullable=False)
    op.alter_column('cmf_sales_order', 'total_tax',
               existing_type=sa.NUMERIC(precision=14, scale=2),
               nullable=False)
    op.alter_column('cmf_sales_order', 'total_without_discount',
               existing_type=sa.NUMERIC(precision=14, scale=2),
               nullable=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('cmf_sales_order', 'total_without_discount',
               existing_type=sa.NUMERIC(precision=14, scale=2),
               nullable=True)
    op.alter_column('cmf_sales_order', 'total_tax',
               existing_type=sa.NUMERIC(precision=14, scale=2),
               nullable=True)
    op.alter_column('cmf_sales_order', 'total_discount',
               existing_type=sa.NUMERIC(precision=14, scale=2),
               nullable=True)
    op.alter_column('cmf_sales_order', 'total',
               existing_type=sa.NUMERIC(precision=14, scale=2),
               nullable=True)
    op.alter_column('cmf_deal', 'total_without_discount',
               existing_type=sa.NUMERIC(precision=14, scale=2),
               nullable=True)
    op.alter_column('cmf_deal', 'total',
               existing_type=sa.NUMERIC(precision=14, scale=2),
               nullable=True)
    # ### end Alembic commands ###
