"""tracking ehr records

Revision ID: f01713c9817f
Revises: 6fcdd1810837
Create Date: 2020-11-04 10:50:51.955769

"""
from alembic import op
import sqlalchemy as sa
import rdr_service.model.utils


from rdr_service.participant_enums import PhysicalMeasurementsStatus, QuestionnaireStatus, OrderStatus
from rdr_service.participant_enums import WithdrawalStatus, WithdrawalReason, SuspensionStatus, QuestionnaireDefinitionStatus
from rdr_service.participant_enums import EnrollmentStatus, Race, SampleStatus, OrganizationType, BiobankOrderStatus
from rdr_service.participant_enums import OrderShipmentTrackingStatus, OrderShipmentStatus
from rdr_service.participant_enums import MetricSetType, MetricsKey, GenderIdentity
from rdr_service.model.base import add_table_history_table, drop_table_history_table
from rdr_service.model.code import CodeType
from rdr_service.model.site_enums import SiteStatus, EnrollingStatus, DigitalSchedulingStatus, ObsoleteStatus

# revision identifiers, used by Alembic.
revision = 'f01713c9817f'
down_revision = '6fcdd1810837'
branch_labels = None
depends_on = None


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


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



def upgrade_rdr():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('participant_ehr_receipt',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('participant_id', sa.Integer(), nullable=False),
    sa.Column('file_timestamp', rdr_service.model.utils.UTCDateTime(), nullable=False),
    sa.Column('first_seen', rdr_service.model.utils.UTCDateTime(), nullable=False),
    sa.Column('last_seen', rdr_service.model.utils.UTCDateTime(), nullable=False),
    sa.ForeignKeyConstraint(['participant_id'], ['participant.participant_id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('idx_participant_ehr_receipt_participant_file_time', 'participant_ehr_receipt', ['participant_id', 'file_timestamp'], unique=False)
    # ### end Alembic commands ###


def downgrade_rdr():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index('idx_participant_ehr_receipt_participant_file_time', table_name='participant_ehr_receipt')
    op.drop_table('participant_ehr_receipt')
    # ### end Alembic commands ###


def upgrade_metrics():
    # ### commands auto generated by Alembic - please adjust! ###
    pass
    # ### end Alembic commands ###


def downgrade_metrics():
    # ### commands auto generated by Alembic - please adjust! ###
    pass
    # ### end Alembic commands ###

