Files
notifications-api/migrations/versions/0341_new_letter_rates.py
Steven Reilly ff4190a8eb Remove letters-related code (#175)
This deletes a big ol' chunk of code related to letters. It's not everything—there are still a few things that might be tied to sms/email—but it's the the heart of letters function. SMS and email function should be untouched by this.

Areas affected:

- Things obviously about letters
- PDF tasks, used for precompiling letters
- Virus scanning, used for those PDFs
- FTP, used to send letters to the printer
- Postage stuff
2023-03-02 20:20:31 -05:00

61 lines
1.7 KiB
Python

"""
Revision ID: 0341_new_letter_rates
Revises: 0340_stub_training_broadcasts
Create Date: 2021-01-27 11:58:21.393227
"""
import itertools
import uuid
from datetime import datetime
from alembic import op
from sqlalchemy.sql import text
revision = '0341_new_letter_rates'
down_revision = '0340_stub_training_broadcasts'
CHANGEOVER_DATE = datetime(2021, 2, 1, 0, 0)
def get_new_rate(sheet_count, post_class):
base_prices = {
'second': 34,
'first': 64,
'europe': 81,
'rest-of-world': 81,
}
multiplier = 5 if post_class in ('first', 'second') else 8
return (base_prices[post_class] + (multiplier * sheet_count)) / 100.0
def upgrade():
conn = op.get_bind()
# conn.execute(text("UPDATE letter_rates SET end_date = :start WHERE end_date IS NULL"), start=CHANGEOVER_DATE)
# op.bulk_insert('letter_rates', [
# {
# 'id': uuid.uuid4(),
# 'start_date': CHANGEOVER_DATE,
# 'end_date': None,
# 'sheet_count': sheet_count,
# 'rate': get_new_rate(sheet_count, post_class),
# 'crown': crown,
# 'post_class': post_class,
# }
# for sheet_count, crown, post_class in itertools.product(
# range(1, 6),
# [True, False],
# ['first', 'second', 'europe', 'rest-of-world']
# )
# ])
def downgrade():
# Make sure you've thought about billing implications etc before downgrading!
conn = op.get_bind()
conn.execute(text("DELETE FROM letter_rates WHERE start_date = :start"), start=CHANGEOVER_DATE)
conn.execute(text("UPDATE letter_rates SET end_date = NULL WHERE end_date = :start"), start=CHANGEOVER_DATE)