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
This commit is contained in:
Steven Reilly
2023-03-02 20:20:31 -05:00
committed by GitHub
parent b07b95f795
commit ff4190a8eb
141 changed files with 1108 additions and 12083 deletions

View File

@@ -26,8 +26,6 @@ from datetime import datetime
from alembic import op
from sqlalchemy.sql import text
from app.models import LetterRate
revision = '0306_letter_rates_price_rise'
down_revision = '0305_add_gp_org_type'
@@ -39,28 +37,28 @@ CHANGEOVER_DATE = datetime(2019, 9, 30, 23, 0)
def upgrade():
# all old rates are going in the bin
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 = {
'second': 30,
'first': 56,
}
op.bulk_insert(LetterRate.__table__, [
{
'id': uuid.uuid4(),
'start_date': CHANGEOVER_DATE,
'end_date': None,
'sheet_count': sheet_count,
'rate': (base_prices[post_class] + (5 * sheet_count)) / 100.0,
'crown': crown,
'post_class': post_class,
}
for sheet_count, crown, post_class in itertools.product(
range(1, 6),
[True, False],
['first', 'second']
)
])
# base_prices = {
# 'second': 30,
# 'first': 56,
# }
# op.bulk_insert('letter_rates', [
# {
# 'id': uuid.uuid4(),
# 'start_date': CHANGEOVER_DATE,
# 'end_date': None,
# 'sheet_count': sheet_count,
# 'rate': (base_prices[post_class] + (5 * sheet_count)) / 100.0,
# 'crown': crown,
# 'post_class': post_class,
# }
# for sheet_count, crown, post_class in itertools.product(
# range(1, 6),
# [True, False],
# ['first', 'second']
# )
# ])
def downgrade():

View File

@@ -6,7 +6,6 @@ Create Date: 2019-05-13 10:44:51.867661
"""
from alembic import op
from app.models import UPLOAD_LETTERS
revision = '0317_uploads_for_all'
@@ -18,7 +17,7 @@ def upgrade():
INSERT INTO
service_permissions (service_id, permission, created_at)
SELECT
id, '{permission}', now()
id, 'upload_letters', now()
FROM
services
WHERE
@@ -28,14 +27,10 @@ def upgrade():
service_permissions
WHERE
service_id = services.id and
permission = '{permission}'
permission = 'upload_letters'
)
""".format(
permission=UPLOAD_LETTERS
))
""")
def downgrade():
op.execute("DELETE from service_permissions where permission = '{}'".format(
UPLOAD_LETTERS
))
op.execute("DELETE from service_permissions where permission = 'upload_letters'")

View File

@@ -12,8 +12,6 @@ from datetime import datetime
from alembic import op
from sqlalchemy.sql import text
from app.models import LetterRate
revision = '0324_int_letter_rates'
down_revision = '0323_broadcast_message'
@@ -31,22 +29,23 @@ def upgrade():
4 sheets - £1.08
5 sheets - £1.16
"""
op.bulk_insert(LetterRate.__table__, [
{
'id': uuid.uuid4(),
'start_date': start_date,
'end_date': None,
'sheet_count': sheet_count,
'rate': (base_rate + (8 * sheet_count)) / 100.0,
'crown': crown,
'post_class': post_class,
}
for sheet_count, crown, post_class in itertools.product(
range(1, 6),
[True, False],
['europe', 'rest-of-world']
)
])
# op.bulk_insert('letter_rates', [
# {
# 'id': uuid.uuid4(),
# 'start_date': start_date,
# 'end_date': None,
# 'sheet_count': sheet_count,
# 'rate': (base_rate + (8 * sheet_count)) / 100.0,
# 'crown': crown,
# 'post_class': post_class,
# }
# for sheet_count, crown, post_class in itertools.product(
# range(1, 6),
# [True, False],
# ['europe', 'rest-of-world']
# )
# ])
pass
def downgrade():

View File

@@ -12,8 +12,6 @@ from datetime import datetime
from alembic import op
from sqlalchemy.sql import text
from app.models import LetterRate
revision = '0341_new_letter_rates'
down_revision = '0340_stub_training_broadcasts'
@@ -36,24 +34,24 @@ def get_new_rate(sheet_count, post_class):
def upgrade():
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(LetterRate.__table__, [
{
'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']
)
])
# 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!

View File

@@ -12,8 +12,6 @@ from datetime import datetime
from alembic import op
from sqlalchemy.sql import text
from app.models import LetterRate
revision = '0366_letter_rates_2022'
down_revision = '0365_add_nhs_branding'
@@ -36,24 +34,24 @@ def get_new_rate(sheet_count, post_class):
def upgrade():
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(LetterRate.__table__, [
{
'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']
)
])
# 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():

View File

@@ -12,8 +12,6 @@ from datetime import datetime
from alembic import op
from sqlalchemy.sql import text
from app.models import LetterRate
revision = '0367_add_reach'
down_revision = '0366_letter_rates_2022'

View File

@@ -12,8 +12,6 @@ from datetime import datetime
from alembic import op
from sqlalchemy.sql import text
from app.models import LetterRate
revision = '0370_remove_reach'
down_revision = '0369_update_sms_rates'

View File

@@ -0,0 +1,44 @@
"""
Revision ID: 0384_remove_letter_branding_
Revises: 0383_update_default_templates.py
Create Date: 2023-02-09 22:24:07.187569
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
revision = '0384_remove_letter_branding_'
down_revision = '0383_update_default_templates.py'
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('fk_organisation_letter_branding_id', 'organisation', type_='foreignkey')
op.drop_column('organisation', 'letter_branding_id')
op.drop_table('service_letter_branding')
op.drop_table('letter_branding')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('organisation', sa.Column('letter_branding_id', postgresql.UUID(), autoincrement=False, nullable=True))
op.create_foreign_key('fk_organisation_letter_branding_id', 'organisation', 'letter_branding', ['letter_branding_id'], ['id'])
op.create_table('service_letter_branding',
sa.Column('service_id', postgresql.UUID(), autoincrement=False, nullable=False),
sa.Column('letter_branding_id', postgresql.UUID(), autoincrement=False, nullable=False),
sa.ForeignKeyConstraint(['letter_branding_id'], ['letter_branding.id'], name='service_letter_branding_letter_branding_id_fkey'),
sa.ForeignKeyConstraint(['service_id'], ['services.id'], name='service_letter_branding_service_id_fkey'),
sa.PrimaryKeyConstraint('service_id', name='service_letter_branding_pkey')
)
op.create_table('letter_branding',
sa.Column('id', postgresql.UUID(), autoincrement=False, nullable=False),
sa.Column('name', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
sa.Column('filename', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
sa.PrimaryKeyConstraint('id', name='letter_branding_pkey'),
sa.UniqueConstraint('filename', name='letter_branding_filename_key'),
sa.UniqueConstraint('name', name='letter_branding_name_key')
)
# ### end Alembic commands ###

View File

@@ -0,0 +1,171 @@
"""
Revision ID: 0385_remove postage_.py
Revises: 0384_remove_letter_branding_
Create Date: 2023-02-10 12:20:39.411493
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
revision = '0385_remove postage_.py'
down_revision = '0384_remove_letter_branding_'
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary')
op.create_primary_key('ft_billing_pkey', 'ft_billing', ['local_date',
'template_id',
'service_id',
'notification_type',
'provider',
'rate_multiplier',
'international',
'rate'])
# we need to replace the entire notifications_all_time_view in order to update it
op.execute("DROP VIEW notifications_all_time_view;")
op.execute("""
CREATE VIEW notifications_all_time_view AS
(
SELECT
id,
job_id,
job_row_number,
service_id,
template_id,
template_version,
api_key_id,
key_type,
billable_units,
notification_type,
created_at,
sent_at,
sent_by,
updated_at,
notification_status,
reference,
client_reference,
international,
phone_prefix,
rate_multiplier,
created_by_id,
document_download_count
FROM notifications
) UNION
(
SELECT
id,
job_id,
job_row_number,
service_id,
template_id,
template_version,
api_key_id,
key_type,
billable_units,
notification_type,
created_at,
sent_at,
sent_by,
updated_at,
notification_status,
reference,
client_reference,
international,
phone_prefix,
rate_multiplier,
created_by_id,
document_download_count
FROM notification_history
)
""")
op.drop_column('notification_history', 'postage')
op.drop_column('notifications', 'postage')
op.drop_column('templates', 'postage')
op.drop_column('templates_history', 'postage')
op.drop_column('ft_billing', 'postage')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('ft_billing', sa.Column('postage', sa.VARCHAR(), autoincrement=False, nullable=True))
op.add_column('templates_history', sa.Column('postage', sa.VARCHAR(), autoincrement=False, nullable=True))
op.add_column('templates', sa.Column('postage', sa.VARCHAR(), autoincrement=False, nullable=True))
op.add_column('notifications', sa.Column('postage', sa.VARCHAR(), autoincrement=False, nullable=True))
op.add_column('notification_history', sa.Column('postage', sa.VARCHAR(), autoincrement=False, nullable=True))
op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary')
op.create_primary_key('ft_billing_pkey', 'ft_billing', ['local_date',
'template_id',
'service_id',
'notification_type',
'provider',
'rate_multiplier',
'international',
'rate',
'postage'])
op.execute("DROP VIEW notifications_all_time_view;")
op.execute("""
CREATE VIEW notifications_all_time_view AS
(
SELECT
id,
job_id,
job_row_number,
service_id,
template_id,
template_version,
api_key_id,
key_type,
billable_units,
notification_type,
created_at,
sent_at,
sent_by,
updated_at,
notification_status,
reference,
client_reference,
international,
phone_prefix,
rate_multiplier,
postage,
created_by_id,
document_download_count
FROM notifications
) UNION
(
SELECT
id,
job_id,
job_row_number,
service_id,
template_id,
template_version,
api_key_id,
key_type,
billable_units,
notification_type,
created_at,
sent_at,
sent_by,
updated_at,
notification_status,
reference,
client_reference,
international,
phone_prefix,
rate_multiplier,
postage,
created_by_id,
document_download_count
FROM notification_history
)
""")
# ### end Alembic commands ###

View File

@@ -0,0 +1,34 @@
"""
Revision ID: 0386_remove_letter_rates_.py
Revises: 0385_remove postage_.py
Create Date: 2023-02-15 10:24:55.107467
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
revision = '0386_remove_letter_rates_.py'
down_revision = '0385_remove postage_.py'
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('letter_rates')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('letter_rates',
sa.Column('id', postgresql.UUID(), autoincrement=False, nullable=False),
sa.Column('start_date', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
sa.Column('end_date', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
sa.Column('sheet_count', sa.INTEGER(), autoincrement=False, nullable=False),
sa.Column('rate', sa.NUMERIC(), autoincrement=False, nullable=False),
sa.Column('crown', sa.BOOLEAN(), autoincrement=False, nullable=False),
sa.Column('post_class', sa.VARCHAR(), autoincrement=False, nullable=False),
sa.PrimaryKeyConstraint('id', name='letter_rates_pkey')
)
# ### end Alembic commands ###

View File

@@ -0,0 +1,41 @@
"""
Revision ID: 0387_remove_letter_perms_.py
Revises: 0386_remove_letter_rates_.py
Create Date: 2023-02-17 11:56:00.993409
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
revision = '0387_remove_letter_perms_.py'
down_revision = '0386_remove_letter_rates_.py'
def upgrade():
# this is the inverse of migration 0317
op.execute("DELETE from service_permissions where permission = 'upload_letters'")
# ### end Alembic commands ###
def downgrade():
# this is the inverse of migration 0317
op.execute("""
INSERT INTO
service_permissions (service_id, permission, created_at)
SELECT
id, 'upload_letters', now()
FROM
services
WHERE
NOT EXISTS (
SELECT
FROM
service_permissions
WHERE
service_id = services.id and
permission = 'upload_letters'
)
""")
# ### end Alembic commands ###

View File

@@ -0,0 +1,45 @@
"""
Revision ID: 0388_no_serv_letter_contact.py
Revises: 0387_remove_letter_perms_.py
Create Date: 2023-02-17 14:42:52.679425
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
revision = '0388_no_serv_letter_contact.py'
down_revision = '0387_remove_letter_perms_.py'
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index('ix_service_letter_contacts_service_id', table_name='service_letter_contacts')
op.drop_constraint('templates_service_letter_contact_id_fkey', 'templates', type_='foreignkey')
op.drop_column('templates', 'service_letter_contact_id')
op.drop_constraint('templates_history_service_letter_contact_id_fkey', 'templates_history', type_='foreignkey')
op.drop_column('templates_history', 'service_letter_contact_id')
op.drop_table('service_letter_contacts')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('templates_history', sa.Column('service_letter_contact_id', postgresql.UUID(), autoincrement=False, nullable=True))
op.create_foreign_key('templates_history_service_letter_contact_id_fkey', 'templates_history', 'service_letter_contacts', ['service_letter_contact_id'], ['id'])
op.add_column('templates', sa.Column('service_letter_contact_id', postgresql.UUID(), autoincrement=False, nullable=True))
op.create_foreign_key('templates_service_letter_contact_id_fkey', 'templates', 'service_letter_contacts', ['service_letter_contact_id'], ['id'])
op.create_table('service_letter_contacts',
sa.Column('id', postgresql.UUID(), autoincrement=False, nullable=False),
sa.Column('service_id', postgresql.UUID(), autoincrement=False, nullable=False),
sa.Column('contact_block', sa.TEXT(), autoincrement=False, nullable=False),
sa.Column('is_default', sa.BOOLEAN(), autoincrement=False, nullable=False),
sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
sa.Column('updated_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
sa.Column('archived', sa.BOOLEAN(), server_default=sa.text('false'), autoincrement=False, nullable=False),
sa.ForeignKeyConstraint(['service_id'], ['services.id'], name='service_letter_contacts_service_id_fkey'),
sa.PrimaryKeyConstraint('id', name='service_letter_contacts_pkey')
)
op.create_index('ix_service_letter_contacts_service_id', 'service_letter_contacts', ['service_id'], unique=False)
# ### end Alembic commands ###

View File

@@ -0,0 +1,56 @@
"""
Revision ID: 0389_no_more_letters.py
Revises: 0388_no_serv_letter_contact.py
Create Date: 2023-02-28 08:58:38.310095
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
revision = '0389_no_more_letters.py'
down_revision = '0388_no_serv_letter_contact.py'
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index('ix_returned_letters_service_id', table_name='returned_letters')
op.drop_table('returned_letters')
op.drop_index('ix_daily_sorted_letter_billing_day', table_name='daily_sorted_letter')
op.drop_index('ix_daily_sorted_letter_file_name', table_name='daily_sorted_letter')
op.drop_table('daily_sorted_letter')
op.drop_column('services', 'volume_letter')
op.drop_column('services_history', 'volume_letter')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('services_history', sa.Column('volume_letter', sa.INTEGER(), autoincrement=False, nullable=True))
op.add_column('services', sa.Column('volume_letter', sa.INTEGER(), autoincrement=False, nullable=True))
op.create_table('daily_sorted_letter',
sa.Column('id', postgresql.UUID(), autoincrement=False, nullable=False),
sa.Column('billing_day', sa.DATE(), autoincrement=False, nullable=False),
sa.Column('unsorted_count', sa.INTEGER(), autoincrement=False, nullable=False),
sa.Column('sorted_count', sa.INTEGER(), autoincrement=False, nullable=False),
sa.Column('updated_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
sa.Column('file_name', sa.VARCHAR(), autoincrement=False, nullable=True),
sa.PrimaryKeyConstraint('id', name='daily_sorted_letter_pkey'),
sa.UniqueConstraint('file_name', 'billing_day', name='uix_file_name_billing_day')
)
op.create_index('ix_daily_sorted_letter_file_name', 'daily_sorted_letter', ['file_name'], unique=False)
op.create_index('ix_daily_sorted_letter_billing_day', 'daily_sorted_letter', ['billing_day'], unique=False)
op.create_table('returned_letters',
sa.Column('id', postgresql.UUID(), autoincrement=False, nullable=False),
sa.Column('reported_at', sa.DATE(), autoincrement=False, nullable=False),
sa.Column('service_id', postgresql.UUID(), autoincrement=False, nullable=False),
sa.Column('notification_id', postgresql.UUID(), autoincrement=False, nullable=False),
sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
sa.Column('updated_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
sa.ForeignKeyConstraint(['service_id'], ['services.id'], name='returned_letters_service_id_fkey'),
sa.PrimaryKeyConstraint('id', name='returned_letters_pkey'),
sa.UniqueConstraint('notification_id', name='returned_letters_notification_id_key')
)
op.create_index('ix_returned_letters_service_id', 'returned_letters', ['service_id'], unique=False)
# ### end Alembic commands ###

View File

@@ -0,0 +1,32 @@
"""
Revision ID: 0390_drop_dvla_provider.py
Revises: 0389_no_more_letters.py
Create Date: 2023-02-28 14:25:50.751952
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
revision = '0390_drop_dvla_provider.py'
down_revision = '0389_no_more_letters.py'
def upgrade():
# based on migration 0066, but without provider_rates
op.execute("DELETE FROM provider_details_history where display_name = 'DVLA'")
op.execute("DELETE FROM provider_details where display_name = 'DVLA'")
# ### end Alembic commands ###
def downgrade():
# migration 0066 in reverse
provider_id = str(uuid.uuid4())
op.execute(
"INSERT INTO provider_details (id, display_name, identifier, priority, notification_type, active, version) values ('{}', 'DVLA', 'dvla', 50, 'letter', true, 1)".format(provider_id)
)
op.execute(
"INSERT INTO provider_details_history (id, display_name, identifier, priority, notification_type, active, version) values ('{}', 'DVLA', 'dvla', 50, 'letter', true, 1)".format(provider_id)
)
# ### end Alembic commands ###