"""Add customer_mode enum property to customer table

Revision ID: 4c81f6e13b5
Revises: 5cb333dc30
Create Date: 2015-07-15 18:00:10.253733

"""

# revision identifiers, used by Alembic.
revision = '4c81f6e13b5'
down_revision = '5cb333dc30'
branch_labels = None
depends_on = None

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

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


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





def upgrade_account():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('customer', sa.Column('customer_mode', sa.Enum('test', 'pending_prod', 'production'), nullable=False))
    op.execute("UPDATE customer SET customer.customer_mode='test' WHERE customer.test_period = 0")
    op.execute("UPDATE customer SET customer.customer_mode='production' WHERE customer.test_period = 1")
    op.drop_column('customer', 'test_period')
    ### end Alembic commands ###


def downgrade_account():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('customer', sa.Column('test_period', mysql.TINYINT(display_width=1), autoincrement=False, nullable=True))
    op.execute("UPDATE customer SET customer.test_period=1 WHERE customer.customer_mode IN ('test', 'pending_prod')")
    op.execute("UPDATE customer SET customer.test_period=0 WHERE customer.customer_mode = 'production'")
    op.drop_column('customer', 'customer_mode')
    ### end Alembic commands ###


def upgrade_fitter():
    pass


def downgrade_fitter():
    pass

