Merge pull request #1133 from alphagov/fix-build

Don't drop the columns yet
This commit is contained in:
Imdad Ahad
2017-07-26 15:26:12 +01:00
committed by GitHub

View File

@@ -16,6 +16,8 @@ revision = '0112_add_start_end_dates'
def upgrade():
op.drop_index('uix_monthly_billing', 'monthly_billing')
op.alter_column('monthly_billing', 'month', nullable=True)
op.alter_column('monthly_billing', 'year', nullable=True)
op.add_column('monthly_billing', sa.Column('start_date', sa.DateTime))
op.add_column('monthly_billing', sa.Column('end_date', sa.DateTime))
conn = op.get_bind()
@@ -29,24 +31,11 @@ def upgrade():
x.id))
op.alter_column('monthly_billing', 'start_date', nullable=False)
op.alter_column('monthly_billing', 'end_date', nullable=False)
op.drop_column('monthly_billing', 'month')
op.drop_column('monthly_billing', 'year')
op.create_index(op.f('uix_monthly_billing'), 'monthly_billing', ['service_id', 'start_date', 'notification_type'],
unique=True)
def downgrade():
op.add_column('monthly_billing', sa.Column('month', sa.String(), nullable=True))
op.add_column('monthly_billing', sa.Column('year', sa.Float(), nullable=True))
conn = op.get_bind()
results = conn.execute("Select id, start_date, end_date from monthly_billing")
res = results.fetchall()
for x in res:
year = datetime.strftime(x.end_date, '%Y')
month = datetime.strftime(x.end_date, '%B')
conn.execute("update monthly_billing set month = '{}', year = {} where id = '{}'".format(month, year, x.id))
op.drop_column('monthly_billing', 'start_date')
op.drop_column('monthly_billing', 'end_date')