"""Allowing reporting_start_end_dates to be null

Revision ID: 9acf8cc4e454
Revises: df2f541291a5
Create Date: 2017-07-11 14:14:03.356183

"""

# revision identifiers, used by Alembic.
revision = '9acf8cc4e454'
down_revision = 'df2f541291a5'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa

def upgrade(engine_name):
    globals()["upgrade_%s" % engine_name]()


def downgrade(engine_name):
    globals()["downgrade_%s" % engine_name]()





def upgrade_data_broker():
    ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('submission', 'reporting_end_date',
               existing_type=sa.DATE(),
               nullable=True,
               server_default=None)
    op.alter_column('submission', 'reporting_start_date',
               existing_type=sa.DATE(),
               nullable=True,
               server_default=None)
    ### end Alembic commands ###
    op.execute("UPDATE submission SET reporting_start_date = NULL "
               "WHERE reporting_start_date = '1970-01-01'")
    op.execute("UPDATE submission SET reporting_end_date = NULL "
               "WHERE reporting_end_date = '1970-01-01'")


def downgrade_data_broker():
    op.execute("UPDATE submission SET reporting_start_date = '1970-01-01' "
               "WHERE reporting_start_date IS NULL")
    op.execute("UPDATE submission SET reporting_end_date = '1970-01-01' "
               "WHERE reporting_end_date IS NULL")

    ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('submission', 'reporting_start_date',
               existing_type=sa.DATE(),
               nullable=False,
               server_default="1970-01-01")
    op.alter_column('submission', 'reporting_end_date',
               existing_type=sa.DATE(),
               nullable=False,
               server_default="1970-01-01")
    ### end Alembic commands ###


