"""Separate last load date into start and end in external_data_load_date

Revision ID: 2cd8406116b0
Revises: 4263cb11c7ac
Create Date: 2021-10-12 13:17:23.946769

"""

# revision identifiers, used by Alembic.
revision = '2cd8406116b0'
down_revision = '4263cb11c7ac'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

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.execute("ALTER TABLE external_data_load_date RENAME COLUMN last_load_date TO last_load_date_start")
    op.add_column('external_data_load_date', sa.Column('last_load_date_end', sa.DateTime(), nullable=True))
    op.execute("UPDATE external_data_load_date SET last_load_date_end = last_load_date_start")
    # ### end Alembic commands ###


def downgrade_data_broker():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('external_data_load_date', 'last_load_date_end')
    op.execute("ALTER TABLE external_data_load_date RENAME COLUMN last_load_date_start TO last_load_date")
    # ### end Alembic commands ###

