avoid broken migrations that get dropped in later migration

This commit is contained in:
stvnrlly
2023-02-17 11:02:58 -05:00
parent 518e2264a6
commit da545f9a67
4 changed files with 72 additions and 71 deletions

View File

@@ -37,28 +37,28 @@ CHANGEOVER_DATE = datetime(2019, 9, 30, 23, 0)
def upgrade(): def upgrade():
# all old rates are going in the bin # all old rates are going in the bin
conn = op.get_bind() conn = op.get_bind()
conn.execute(text("UPDATE letter_rates SET end_date = :start WHERE end_date IS NULL"), start=CHANGEOVER_DATE) # conn.execute(text("UPDATE letter_rates SET end_date = :start WHERE end_date IS NULL"), start=CHANGEOVER_DATE)
base_prices = { # base_prices = {
'second': 30, # 'second': 30,
'first': 56, # 'first': 56,
} # }
op.bulk_insert('letter_rates', [ # op.bulk_insert('letter_rates', [
{ # {
'id': uuid.uuid4(), # 'id': uuid.uuid4(),
'start_date': CHANGEOVER_DATE, # 'start_date': CHANGEOVER_DATE,
'end_date': None, # 'end_date': None,
'sheet_count': sheet_count, # 'sheet_count': sheet_count,
'rate': (base_prices[post_class] + (5 * sheet_count)) / 100.0, # 'rate': (base_prices[post_class] + (5 * sheet_count)) / 100.0,
'crown': crown, # 'crown': crown,
'post_class': post_class, # 'post_class': post_class,
} # }
for sheet_count, crown, post_class in itertools.product( # for sheet_count, crown, post_class in itertools.product(
range(1, 6), # range(1, 6),
[True, False], # [True, False],
['first', 'second'] # ['first', 'second']
) # )
]) # ])
def downgrade(): def downgrade():

View File

@@ -29,22 +29,23 @@ def upgrade():
4 sheets - £1.08 4 sheets - £1.08
5 sheets - £1.16 5 sheets - £1.16
""" """
op.bulk_insert('letter_rates', [ # op.bulk_insert('letter_rates', [
{ # {
'id': uuid.uuid4(), # 'id': uuid.uuid4(),
'start_date': start_date, # 'start_date': start_date,
'end_date': None, # 'end_date': None,
'sheet_count': sheet_count, # 'sheet_count': sheet_count,
'rate': (base_rate + (8 * sheet_count)) / 100.0, # 'rate': (base_rate + (8 * sheet_count)) / 100.0,
'crown': crown, # 'crown': crown,
'post_class': post_class, # 'post_class': post_class,
} # }
for sheet_count, crown, post_class in itertools.product( # for sheet_count, crown, post_class in itertools.product(
range(1, 6), # range(1, 6),
[True, False], # [True, False],
['europe', 'rest-of-world'] # ['europe', 'rest-of-world']
) # )
]) # ])
pass
def downgrade(): def downgrade():

View File

@@ -34,24 +34,24 @@ def get_new_rate(sheet_count, post_class):
def upgrade(): def upgrade():
conn = op.get_bind() conn = op.get_bind()
conn.execute(text("UPDATE letter_rates SET end_date = :start WHERE end_date IS NULL"), start=CHANGEOVER_DATE) # conn.execute(text("UPDATE letter_rates SET end_date = :start WHERE end_date IS NULL"), start=CHANGEOVER_DATE)
op.bulk_insert('letter_rates', [ # op.bulk_insert('letter_rates', [
{ # {
'id': uuid.uuid4(), # 'id': uuid.uuid4(),
'start_date': CHANGEOVER_DATE, # 'start_date': CHANGEOVER_DATE,
'end_date': None, # 'end_date': None,
'sheet_count': sheet_count, # 'sheet_count': sheet_count,
'rate': get_new_rate(sheet_count, post_class), # 'rate': get_new_rate(sheet_count, post_class),
'crown': crown, # 'crown': crown,
'post_class': post_class, # 'post_class': post_class,
} # }
for sheet_count, crown, post_class in itertools.product( # for sheet_count, crown, post_class in itertools.product(
range(1, 6), # range(1, 6),
[True, False], # [True, False],
['first', 'second', 'europe', 'rest-of-world'] # ['first', 'second', 'europe', 'rest-of-world']
) # )
]) # ])
def downgrade(): def downgrade():
# Make sure you've thought about billing implications etc before downgrading! # Make sure you've thought about billing implications etc before downgrading!

View File

@@ -34,24 +34,24 @@ def get_new_rate(sheet_count, post_class):
def upgrade(): def upgrade():
conn = op.get_bind() conn = op.get_bind()
conn.execute(text("UPDATE letter_rates SET end_date = :start WHERE end_date IS NULL"), start=CHANGEOVER_DATE) # conn.execute(text("UPDATE letter_rates SET end_date = :start WHERE end_date IS NULL"), start=CHANGEOVER_DATE)
op.bulk_insert('letter_rates', [ # op.bulk_insert('letter_rates', [
{ # {
'id': uuid.uuid4(), # 'id': uuid.uuid4(),
'start_date': CHANGEOVER_DATE, # 'start_date': CHANGEOVER_DATE,
'end_date': None, # 'end_date': None,
'sheet_count': sheet_count, # 'sheet_count': sheet_count,
'rate': get_new_rate(sheet_count, post_class), # 'rate': get_new_rate(sheet_count, post_class),
'crown': crown, # 'crown': crown,
'post_class': post_class, # 'post_class': post_class,
} # }
for sheet_count, crown, post_class in itertools.product( # for sheet_count, crown, post_class in itertools.product(
range(1, 6), # range(1, 6),
[True, False], # [True, False],
['first', 'second', 'europe', 'rest-of-world'] # ['first', 'second', 'europe', 'rest-of-world']
) # )
]) # ])
def downgrade(): def downgrade():