"""modify metrics_lifecycle_cache table

Revision ID: 8fa4d8f2277c
Revises: 6f042370e83b
Create Date: 2019-07-18 11:36:23.949486

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


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

# revision identifiers, used by Alembic.
revision = '8fa4d8f2277c'
down_revision = '6f042370e83b'
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():
    op.execute('ALTER TABLE metrics_lifecycle_cache ADD COLUMN type varchar(50) AFTER `date_inserted`;')
    op.execute('ALTER TABLE metrics_lifecycle_cache ADD COLUMN retention_modules_eligible int(11) NOT NULL AFTER `ppi_baseline_complete`;')
    op.execute('ALTER TABLE metrics_lifecycle_cache ADD COLUMN retention_modules_complete int(11) NOT NULL AFTER `retention_modules_eligible`;')
    op.execute('ALTER TABLE metrics_lifecycle_cache DROP PRIMARY KEY')
    op.execute('ALTER TABLE metrics_lifecycle_cache ADD PRIMARY KEY (`date_inserted`,`type`,`hpo_id`,`hpo_name`,`date`)')

def downgrade_rdr():
    # ### commands auto generated by Alembic - please adjust! ###
    op.execute('ALTER TABLE metrics_lifecycle_cache DROP PRIMARY KEY')
    op.drop_column('metrics_lifecycle_cache', 'type')
    op.drop_column('metrics_lifecycle_cache', 'retention_modules_eligible')
    op.drop_column('metrics_lifecycle_cache', 'retention_modules_complete')
    op.execute('ALTER TABLE metrics_lifecycle_cache ADD PRIMARY KEY (`date_inserted`,`hpo_id`,`hpo_name`,`date`)')
    # ### 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 ###


@@ -1246,16 +1246,25 @@
 char(50)
+ NOT NULL
  AFTER %60

set not null for primary key column (#1170)