diff --git a/app/celery/scheduled_tasks.py b/app/celery/scheduled_tasks.py index a8a097030..c98c7753f 100644 --- a/app/celery/scheduled_tasks.py +++ b/app/celery/scheduled_tasks.py @@ -285,13 +285,11 @@ def process_delivery_receipts(self): retry_count = self.request.retries wait_time = 3600 * 2**retry_count - current_app.logger.exception(str(ex)) - try: raise self.retry(ex=ex, countdown=wait_time) except self.MaxRetriesExceededError: current_app.logger.error( - "Failed process delivery receipts after max retries" + f"Failed process delivery receipts after max retries with exception {str(ex)}" ) diff --git a/app/dao/notifications_dao.py b/app/dao/notifications_dao.py index e32312073..325f23395 100644 --- a/app/dao/notifications_dao.py +++ b/app/dao/notifications_dao.py @@ -976,10 +976,8 @@ def dao_update_delivery_receipts(receipts, delivered): db.session.execute(stmt) db.session.commit() elapsed_time = (time() * 1000) - start_time_millis - current_app.logger.info( - f"#loadtestperformance batch update query time: \ - updated {len(receipts)} notification in {elapsed_time} ms" - ) + current_app.logger.info(f"#loadtestperformance batch update query time: \ + updated {len(receipts)} notification in {elapsed_time} ms") def dao_close_out_delivery_receipts(): diff --git a/app/service/rest.py b/app/service/rest.py index 766918f1e..a2609170b 100644 --- a/app/service/rest.py +++ b/app/service/rest.py @@ -1240,12 +1240,10 @@ def get_service_message_ratio(): messages_remaining = my_service.total_message_limit - messages_sent if my_service.total_message_limit - messages_sent < 0: - raise Exception( - f"Math error get_service_message_ratio(), \ + raise Exception(f"Math error get_service_message_ratio(), \ total {my_service.total_message_limit} \ messages_sent {messages_sent} remaining {messages_remaining} \ - service_id {service_id} current_year {current_year}" - ) + service_id {service_id} current_year {current_year}") return { "messages_sent": messages_sent, diff --git a/migrations/versions/0042_notification_history.py b/migrations/versions/0042_notification_history.py index 346964477..93f2571f0 100644 --- a/migrations/versions/0042_notification_history.py +++ b/migrations/versions/0042_notification_history.py @@ -115,8 +115,7 @@ def upgrade(): unique=False, ) - op.execute( - """ + op.execute(""" INSERT INTO notification_history ( id, @@ -154,8 +153,7 @@ def upgrade(): status, reference FROM notifications - """ - ) + """) ### end Alembic commands ### diff --git a/migrations/versions/0045_billable_units.py b/migrations/versions/0045_billable_units.py index f240b33ff..272dfc203 100644 --- a/migrations/versions/0045_billable_units.py +++ b/migrations/versions/0045_billable_units.py @@ -34,11 +34,9 @@ def upgrade(): # caveats # only adjusts notifications for services that have never been in research mode. On live, research mode was # limited to only services that we have set up ourselves so deemed this acceptable. - billable_services_query = text( - """ + billable_services_query = text(""" SELECT id FROM services_history WHERE id NOT IN (SELECT id FROM services_history WHERE research_mode) - """ - ) + """) billable_services = conn.execute(billable_services_query) # set to 'null' if there are no billable services so we don't get a syntax error in the update statement service_ids = ",".join(f"{service.id}" for service in billable_services) or "null" @@ -102,11 +100,9 @@ def downgrade(): # caveats # only adjusts notifications for services that have never been in research mode. On live, research mode was # limited to only services that we have set up ourselves - billable_services = conn.execute( - """ + billable_services = conn.execute(""" SELECT id FROM services_history WHERE id not in (select id from services_history where research_mode) - """ - ) + """) # set to 'null' if there are no billable services so we don't get a syntax error in the update statement service_ids = ",".join(f"{service.id}" for service in billable_services) or "null" diff --git a/migrations/versions/0046_organisations_and_branding.py b/migrations/versions/0046_organisations_and_branding.py index c162d3256..518164666 100644 --- a/migrations/versions/0046_organisations_and_branding.py +++ b/migrations/versions/0046_organisations_and_branding.py @@ -42,14 +42,12 @@ def upgrade(): op.execute("INSERT INTO branding_type VALUES ('govuk'), ('org'), ('both')") # insert UKVI data as initial test data. hex and crest pulled from alphagov/whitehall - op.execute( - """INSERT INTO organisation VALUES ( + op.execute("""INSERT INTO organisation VALUES ( '9d25d02d-2915-4e98-874b-974e123e8536', '#9325b2', 'ho_crest_27px_x2.png', 'UK Visas and Immigration' - )""" - ) + )""") op.execute("UPDATE services SET branding='govuk'") op.execute("UPDATE services_history SET branding='govuk'") diff --git a/migrations/versions/0070_fix_notify_user_email.py b/migrations/versions/0070_fix_notify_user_email.py index f60925f3d..26b4a6096 100644 --- a/migrations/versions/0070_fix_notify_user_email.py +++ b/migrations/versions/0070_fix_notify_user_email.py @@ -15,20 +15,16 @@ from alembic import op def upgrade(): - op.execute( - """ + op.execute(""" UPDATE users SET email_address = 'testsender@dispostable.com' WHERE email_address = 'notify-service-user@digital.cabinet-office' - """ - ) + """) def downgrade(): - op.execute( - """ + op.execute(""" UPDATE users SET email_address = 'notify-service-user@digital.cabinet-office' WHERE email_address = 'testsender@dispostable.com' - """ - ) + """) diff --git a/migrations/versions/0072_add_dvla_orgs.py b/migrations/versions/0072_add_dvla_orgs.py index 482e47260..8a9db90b4 100644 --- a/migrations/versions/0072_add_dvla_orgs.py +++ b/migrations/versions/0072_add_dvla_orgs.py @@ -24,13 +24,11 @@ def upgrade(): ) # insert initial values - HMG and Land Reg - op.execute( - """ + op.execute(""" INSERT INTO dvla_organisation VALUES ('001', 'HM Government'), ('500', 'Land Registry') - """ - ) + """) op.add_column( "services", diff --git a/migrations/versions/0095_migrate_existing_svc_perms.py b/migrations/versions/0095_migrate_existing_svc_perms.py index 7c0a03c01..61e5bfaff 100644 --- a/migrations/versions/0095_migrate_existing_svc_perms.py +++ b/migrations/versions/0095_migrate_existing_svc_perms.py @@ -39,44 +39,36 @@ def upgrade(): conn = op.get_bind() - query = text( - """ + query = text(""" INSERT INTO service_permissions (service_id, permission, created_at) SELECT id, 'sms', '2017-05-26 17:30:00.000000' FROM services WHERE id NOT IN (SELECT service_id FROM service_permissions WHERE service_id=id AND permission='sms') - """ - ) + """) conn.execute(query) - query = text( - """ + query = text(""" INSERT INTO service_permissions (service_id, permission, created_at) SELECT id, 'email', '2017-05-26 17:30:00.000000' FROM services WHERE id NOT IN (SELECT service_id FROM service_permissions WHERE service_id=id AND permission='email') - """ - ) + """) conn.execute(query) - query = text( - """ + query = text(""" INSERT INTO service_permissions (service_id, permission, created_at) SELECT id, 'letter', '2017-05-26 17:30:00.000000' FROM services WHERE can_send_letters AND id NOT IN (SELECT service_id FROM service_permissions WHERE service_id=id AND permission='letter') - """ - ) + """) conn.execute(query) - query = text( - """ + query = text(""" INSERT INTO service_permissions (service_id, permission, created_at) SELECT id, 'international_sms', '2017-05-26 17:30:00.000000' FROM services WHERE can_send_international_sms AND id NOT IN (SELECT service_id FROM service_permissions WHERE service_id=id AND permission='international_sms') - """ - ) + """) conn.execute(query) diff --git a/migrations/versions/0096_update_job_stats.py b/migrations/versions/0096_update_job_stats.py index 66bfc6373..5e49cd130 100644 --- a/migrations/versions/0096_update_job_stats.py +++ b/migrations/versions/0096_update_job_stats.py @@ -17,28 +17,24 @@ from sqlalchemy.dialects import postgresql def upgrade(): - query = text( - """ + query = text(""" UPDATE job_statistics SET sent = sms_sent + emails_sent + letters_sent, delivered = sms_delivered + emails_delivered, failed = sms_failed + emails_failed + letters_failed - """ - ) + """) conn = op.get_bind() conn.execute(query) def downgrade(): - query = text( - """ + query = text(""" UPDATE job_statistics SET sent = 0, delivered = 0, failed = 0 - """ - ) + """) conn = op.get_bind() conn.execute(query) diff --git a/migrations/versions/0099_tfl_dar.py b/migrations/versions/0099_tfl_dar.py index 6343bd7a8..653bbe1ed 100644 --- a/migrations/versions/0099_tfl_dar.py +++ b/migrations/versions/0099_tfl_dar.py @@ -23,14 +23,12 @@ def upgrade(): conn = op.get_bind() input_params = {"tfl_dar_id": TFL_DAR_ID} conn.execute( - text( - """INSERT INTO organisation VALUES ( + text("""INSERT INTO organisation VALUES ( :tfl_dar_id, '', 'tfl_dar_x2.png', 'tfl' - )""" - ), + )"""), input_params, ) @@ -39,10 +37,8 @@ def downgrade(): conn = op.get_bind() input_params = {"tfl_dar_id": TFL_DAR_ID} conn.execute( - text( - """ + text(""" DELETE FROM organisation WHERE "id" = :tfl_dar_id - """ - ), + """), input_params, ) diff --git a/migrations/versions/0101_een_logo.py b/migrations/versions/0101_een_logo.py index 589f1c7c6..c2b56da65 100644 --- a/migrations/versions/0101_een_logo.py +++ b/migrations/versions/0101_een_logo.py @@ -20,14 +20,12 @@ def upgrade(): input_params = {"network_id": ENTERPRISE_EUROPE_NETWORK_ID} conn = op.get_bind() conn.execute( - text( - """INSERT INTO organisation VALUES ( + text("""INSERT INTO organisation VALUES ( :network_id, '', 'een_x2.png', 'een' - )""" - ), + )"""), input_params, ) @@ -36,10 +34,8 @@ def downgrade(): input_params = {"network_id": ENTERPRISE_EUROPE_NETWORK_ID} conn = op.get_bind() conn.execute( - text( - """ + text(""" DELETE FROM organisation WHERE "id" = :network_id - """ - ), + """), input_params, ) diff --git a/migrations/versions/0103_add_historical_redact.py b/migrations/versions/0103_add_historical_redact.py index 47e91ca2d..20304067d 100644 --- a/migrations/versions/0103_add_historical_redact.py +++ b/migrations/versions/0103_add_historical_redact.py @@ -22,8 +22,7 @@ def upgrade(): conn = op.get_bind() input_params = {"notify_user_id": current_app.config["NOTIFY_USER_ID"]} conn.execute( - text( - """ + text(""" INSERT INTO template_redacted ( template_id, @@ -40,8 +39,7 @@ def upgrade(): templates LEFT JOIN template_redacted on template_redacted.template_id = templates.id WHERE template_redacted.template_id IS NULL - """ - ), + """), input_params, ) diff --git a/migrations/versions/0105_opg_letter_org.py b/migrations/versions/0105_opg_letter_org.py index 1b3a9f376..2a8c23766 100644 --- a/migrations/versions/0105_opg_letter_org.py +++ b/migrations/versions/0105_opg_letter_org.py @@ -17,12 +17,10 @@ from sqlalchemy.dialects import postgresql def upgrade(): - op.execute( - """ + op.execute(""" INSERT INTO dvla_organisation VALUES ('002', 'Office of the Public Guardian') - """ - ) + """) def downgrade(): diff --git a/migrations/versions/0118_service_sms_senders.py b/migrations/versions/0118_service_sms_senders.py index 6dbca2ef6..ca52affd2 100644 --- a/migrations/versions/0118_service_sms_senders.py +++ b/migrations/versions/0118_service_sms_senders.py @@ -49,13 +49,11 @@ def upgrade(): ) # populate govuk seeded service - op.execute( - """ + op.execute(""" INSERT INTO service_sms_senders (id, sms_sender, service_id, is_default, inbound_number_id, created_at, updated_at) VALUES ('286d6176-adbe-7ea7-ba26-b7606ee5e2a4', 'GOVUK', 'd6aa2c68-a2d9-4437-ab19-3ae8eb202553', true, null, now(), null) - """ - ) + """) def downgrade(): diff --git a/migrations/versions/0130_service_email_reply_to_row.py b/migrations/versions/0130_service_email_reply_to_row.py index f1e3720d1..a168a750d 100644 --- a/migrations/versions/0130_service_email_reply_to_row.py +++ b/migrations/versions/0130_service_email_reply_to_row.py @@ -25,14 +25,12 @@ def upgrade(): "notify_service_id": NOTIFY_SERVICE_ID, } conn.execute( - text( - """ + text(""" INSERT INTO service_email_reply_to (id, service_id, email_address, is_default, created_at) VALUES (:email_reply_to, :notify_service_id, 'testsender@dispostable.com', 'f', NOW()) - """ - ), + """), input_params, ) @@ -43,11 +41,9 @@ def downgrade(): "email_reply_to": EMAIL_REPLY_TO_ID, } conn.execute( - text( - """ + text(""" DELETE FROM service_email_reply_to WHERE id = :email_reply_to - """ - ), + """), input_params, ) diff --git a/migrations/versions/0133_set_services_sms_prefix.py b/migrations/versions/0133_set_services_sms_prefix.py index 752edf297..818cb8291 100644 --- a/migrations/versions/0133_set_services_sms_prefix.py +++ b/migrations/versions/0133_set_services_sms_prefix.py @@ -27,34 +27,28 @@ def upgrade(): conn = op.get_bind() input_params = {"default_sms_sender": default_sms_sender} conn.execute( - text( - """ + text(""" update services set prefix_sms = True where id in ( select service_id from service_sms_senders where is_default = True and sms_sender = :default_sms_sender ) - """ - ), + """), input_params, ) conn.execute( - text( - """ + text(""" update services set prefix_sms = False where id in ( select service_id from service_sms_senders where is_default = True and sms_sender != :default_sms_sender ) - """ - ), + """), input_params, ) def downgrade(): - op.execute( - """ + op.execute(""" UPDATE services set prefix_sms = null - """ - ) + """) diff --git a/migrations/versions/0137_notification_template_hist.py b/migrations/versions/0137_notification_template_hist.py index 9e9ea5327..906e6de9b 100644 --- a/migrations/versions/0137_notification_template_hist.py +++ b/migrations/versions/0137_notification_template_hist.py @@ -16,26 +16,22 @@ def upgrade(): op.drop_constraint( "notifications_template_id_fkey", "notifications", type_="foreignkey" ) - op.execute( - """ + op.execute(""" ALTER TABLE notifications ADD CONSTRAINT "notifications_templates_history_fkey" FOREIGN KEY ("template_id", "template_version") REFERENCES "templates_history" ("id", "version") NOT VALID - """ - ) + """) op.drop_constraint( "notification_history_template_id_fkey", "notification_history", type_="foreignkey", ) - op.execute( - """ + op.execute(""" ALTER TABLE notification_history ADD CONSTRAINT "notification_history_templates_history_fkey" FOREIGN KEY ("template_id", "template_version") REFERENCES "templates_history" ("id", "version") NOT VALID - """ - ) + """) def downgrade(): diff --git a/migrations/versions/0140_sms_prefix_non_nullable.py b/migrations/versions/0140_sms_prefix_non_nullable.py index 176e78462..4101fb8ad 100644 --- a/migrations/versions/0140_sms_prefix_non_nullable.py +++ b/migrations/versions/0140_sms_prefix_non_nullable.py @@ -20,13 +20,11 @@ def upgrade(): conn = op.get_bind() input_params = {"id": current_app.config["NOTIFY_SERVICE_ID"]} conn.execute( - text( - """ + text(""" update services set prefix_sms = false where id = :id - """ - ), + """), input_params, ) @@ -49,12 +47,10 @@ def downgrade(): conn = op.get_bind() input_params = {"id": current_app.config["NOTIFY_SERVICE_ID"]} conn.execute( - text( - """ + text(""" update services set prefix_sms = null where id = :id - """ - ), + """), input_params, ) diff --git a/migrations/versions/0149_add_crown_to_services.py b/migrations/versions/0149_add_crown_to_services.py index 5c5d4698f..5de30b56e 100644 --- a/migrations/versions/0149_add_crown_to_services.py +++ b/migrations/versions/0149_add_crown_to_services.py @@ -15,45 +15,33 @@ down_revision = "0148_add_letters_as_pdf_svc_perm" def upgrade(): op.add_column("services", sa.Column("crown", sa.Boolean(), nullable=True)) - op.execute( - """ + op.execute(""" update services set crown = True where organisation_type = 'central' - """ - ) - op.execute( - """ + """) + op.execute(""" update services set crown = True where organisation_type is null - """ - ) - op.execute( - """ + """) + op.execute(""" update services set crown = False where crown is null - """ - ) + """) op.alter_column("services", "crown", nullable=False) op.add_column("services_history", sa.Column("crown", sa.Boolean(), nullable=True)) - op.execute( - """ + op.execute(""" update services_history set crown = True where organisation_type = 'central' - """ - ) - op.execute( - """ + """) + op.execute(""" update services_history set crown = True where organisation_type is null - """ - ) - op.execute( - """ + """) + op.execute(""" update services_history set crown = False where crown is null - """ - ) + """) op.alter_column("services_history", "crown", nullable=False) diff --git a/migrations/versions/0159_add_historical_redact.py b/migrations/versions/0159_add_historical_redact.py index e449b1eaf..4a20648bb 100644 --- a/migrations/versions/0159_add_historical_redact.py +++ b/migrations/versions/0159_add_historical_redact.py @@ -22,8 +22,7 @@ def upgrade(): conn = op.get_bind() input_params = {"notify_user": current_app.config["NOTIFY_USER_ID"]} conn.execute( - text( - """ + text(""" INSERT INTO template_redacted ( template_id, @@ -40,8 +39,7 @@ def upgrade(): templates LEFT JOIN template_redacted on template_redacted.template_id = templates.id WHERE template_redacted.template_id IS NULL - """ - ), + """), input_params, ) diff --git a/migrations/versions/0161_email_branding.py b/migrations/versions/0161_email_branding.py index 0b5b1d581..178301871 100644 --- a/migrations/versions/0161_email_branding.py +++ b/migrations/versions/0161_email_branding.py @@ -40,20 +40,16 @@ def upgrade(): ), sa.PrimaryKeyConstraint("service_id"), ) - op.execute( - """ + op.execute(""" INSERT INTO email_branding (id, colour, logo, name) SELECT id, colour, logo, name FROM organisation - """ - ) - op.execute( - """ + """) + op.execute(""" INSERT INTO service_email_branding (service_id, email_branding_id) SELECT id, organisation_id FROM services where organisation_id is not null - """ - ) + """) def downgrade(): diff --git a/migrations/versions/0172_deprioritise_examples.py b/migrations/versions/0172_deprioritise_examples.py index b3367917c..2e7fb63f9 100644 --- a/migrations/versions/0172_deprioritise_examples.py +++ b/migrations/versions/0172_deprioritise_examples.py @@ -15,8 +15,7 @@ down_revision = "0171_add_org_invite_template" def upgrade(): op.get_bind() - op.execute( - """ + op.execute(""" update templates set process_type = 'normal' where templates.id in ( @@ -24,8 +23,7 @@ def upgrade(): join templates_history on templates.id=templates_history.id where templates_history.name = 'Example text message template' ) - """ - ) + """) def downgrade(): diff --git a/migrations/versions/0174_add_billing_facts.py b/migrations/versions/0174_add_billing_facts.py index ea8e09202..a2d3c1c72 100644 --- a/migrations/versions/0174_add_billing_facts.py +++ b/migrations/versions/0174_add_billing_facts.py @@ -71,8 +71,7 @@ def upgrade(): ) # Insert data into table - op.execute( - """ + op.execute(""" INSERT into dm_datetime ( SELECT datum AS bst_date, @@ -104,8 +103,7 @@ def upgrade(): ) DQ ORDER BY bst_date ); - """ - ) + """) def downgrade(): diff --git a/migrations/versions/0183_alter_primary_key.py b/migrations/versions/0183_alter_primary_key.py index 022d9e848..7015c9ad7 100644 --- a/migrations/versions/0183_alter_primary_key.py +++ b/migrations/versions/0183_alter_primary_key.py @@ -16,14 +16,11 @@ down_revision = "0182_add_upload_document_perm" def upgrade(): # Drop the old dm_datetime table and create a new one - op.execute( - """ + op.execute(""" delete from dm_datetime where 1=1; - """ - ) + """) - op.execute( - """ + op.execute(""" INSERT into dm_datetime ( SELECT datum AS bst_date, @@ -55,8 +52,7 @@ def upgrade(): ) DQ ORDER BY bst_date ); - """ - ) + """) op.drop_constraint("ft_billing_pkey", "ft_billing", type_="primary") diff --git a/migrations/versions/0203_fix_old_incomplete_jobs.py b/migrations/versions/0203_fix_old_incomplete_jobs.py index 42634ce53..d9e2cb6e7 100644 --- a/migrations/versions/0203_fix_old_incomplete_jobs.py +++ b/migrations/versions/0203_fix_old_incomplete_jobs.py @@ -14,8 +14,7 @@ from alembic import op def upgrade(): - op.execute( - """ + op.execute(""" UPDATE jobs SET @@ -24,8 +23,7 @@ def upgrade(): processing_started IS NULL AND job_status = 'in progress' - """ - ) + """) def downgrade(): diff --git a/migrations/versions/0219_default_email_branding.py b/migrations/versions/0219_default_email_branding.py index c702b3b29..59c52dc90 100644 --- a/migrations/versions/0219_default_email_branding.py +++ b/migrations/versions/0219_default_email_branding.py @@ -17,16 +17,14 @@ def upgrade(): conn = op.get_bind() input_params = {"branding_org": BrandType.ORG.value} conn.execute( - text( - """ + text(""" update email_branding set brand_type = :branding_org where brand_type is null - """ - ), + """), input_params, ) diff --git a/migrations/versions/0221_nullable_service_branding.py b/migrations/versions/0221_nullable_service_branding.py index ab8cb68ac..ddab09b79 100644 --- a/migrations/versions/0221_nullable_service_branding.py +++ b/migrations/versions/0221_nullable_service_branding.py @@ -19,25 +19,21 @@ def upgrade(): op.alter_column("services_history", "branding", nullable=True) op.alter_column("services", "branding", nullable=True) - op.execute( - """ + op.execute(""" update email_branding set brand_type = 'org' where brand_type = 'govuk' - """ - ) + """) - op.execute( - """ + op.execute(""" delete from branding_type where name = 'govuk' - """ - ) + """) def downgrade(): @@ -56,12 +52,10 @@ def downgrade(): op.alter_column("services", "branding", nullable=False) op.alter_column("services_history", "branding", nullable=False) - op.execute( - """ + op.execute(""" insert into branding_type (name) values ('govuk') - """ - ) + """) diff --git a/migrations/versions/0223_add_domain_constraint.py b/migrations/versions/0223_add_domain_constraint.py index 3c3afba81..6b64b877b 100644 --- a/migrations/versions/0223_add_domain_constraint.py +++ b/migrations/versions/0223_add_domain_constraint.py @@ -11,16 +11,14 @@ down_revision = "0222_drop_service_branding" def upgrade(): - op.execute( - """ + op.execute(""" update email_branding set domain = null where domain = '' - """ - ) + """) op.create_unique_constraint( "uq_email_branding_domain", "email_branding", ["domain"] ) diff --git a/migrations/versions/0227_postage_constraints.py b/migrations/versions/0227_postage_constraints.py index 38643c266..3727fdc60 100644 --- a/migrations/versions/0227_postage_constraints.py +++ b/migrations/versions/0227_postage_constraints.py @@ -12,14 +12,12 @@ down_revision = "0226_service_postage" def upgrade(): - op.execute( - """ + op.execute(""" update services set postage = 'second' - """ - ) + """) op.create_check_constraint( "ck_services_postage", "services", "postage in ('second', 'first')" diff --git a/migrations/versions/0230_noti_postage_constraint_1.py b/migrations/versions/0230_noti_postage_constraint_1.py index 52427535e..b9778ea29 100644 --- a/migrations/versions/0230_noti_postage_constraint_1.py +++ b/migrations/versions/0230_noti_postage_constraint_1.py @@ -13,8 +13,7 @@ down_revision = "0228_notification_postage" def upgrade(): - op.execute( - """ + op.execute(""" ALTER TABLE notifications ADD CONSTRAINT "chk_notifications_postage_null" CHECK ( CASE WHEN notification_type = 'letter' THEN @@ -24,8 +23,7 @@ def upgrade(): END ) NOT VALID - """ - ) + """) def downgrade(): diff --git a/migrations/versions/0231_noti_postage_constraint_2.py b/migrations/versions/0231_noti_postage_constraint_2.py index 2ab3130fc..379e0e683 100644 --- a/migrations/versions/0231_noti_postage_constraint_2.py +++ b/migrations/versions/0231_noti_postage_constraint_2.py @@ -13,8 +13,7 @@ down_revision = "0230_noti_postage_constraint_1" def upgrade(): - op.execute( - """ + op.execute(""" ALTER TABLE notification_history ADD CONSTRAINT "chk_notification_history_postage_null" CHECK ( CASE WHEN notification_type = 'letter' THEN @@ -24,8 +23,7 @@ def upgrade(): END ) NOT VALID - """ - ) + """) def downgrade(): diff --git a/migrations/versions/0237_add_filename_to_dvla_org.py b/migrations/versions/0237_add_filename_to_dvla_org.py index 651ee17a2..637c2ee9b 100644 --- a/migrations/versions/0237_add_filename_to_dvla_org.py +++ b/migrations/versions/0237_add_filename_to_dvla_org.py @@ -49,11 +49,9 @@ def upgrade(): ) for org_id, org_filename in LOGOS.items(): - query = text( - """ + query = text(""" UPDATE dvla_organisation SET filename = :filename WHERE id = :id - """ - ) + """) conn.execute(query, {"filename": org_filename, "id": org_id}) diff --git a/migrations/versions/0248_enable_choose_postage.py b/migrations/versions/0248_enable_choose_postage.py index a4a72eba4..e5a3d3d23 100644 --- a/migrations/versions/0248_enable_choose_postage.py +++ b/migrations/versions/0248_enable_choose_postage.py @@ -18,8 +18,7 @@ def upgrade(): op.execute("INSERT INTO service_permission_types VALUES ('choose_postage')") op.add_column("templates", sa.Column("postage", sa.String(), nullable=True)) op.add_column("templates_history", sa.Column("postage", sa.String(), nullable=True)) - op.execute( - """ + op.execute(""" ALTER TABLE templates ADD CONSTRAINT "chk_templates_postage_null" CHECK ( CASE WHEN template_type = 'letter' THEN @@ -29,10 +28,8 @@ def upgrade(): postage is null END ) - """ - ) - op.execute( - """ + """) + op.execute(""" ALTER TABLE templates_history ADD CONSTRAINT "chk_templates_history_postage_null" CHECK ( CASE WHEN template_type = 'letter' THEN @@ -42,8 +39,7 @@ def upgrade(): postage is null END ) - """ - ) + """) # ### end Alembic commands ### diff --git a/migrations/versions/0253_set_template_postage_.py b/migrations/versions/0253_set_template_postage_.py index 1b014615d..b27fc7c3d 100644 --- a/migrations/versions/0253_set_template_postage_.py +++ b/migrations/versions/0253_set_template_postage_.py @@ -15,10 +15,8 @@ down_revision = "0252_letter_branding_table" def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.execute( - """UPDATE templates SET postage = services.postage - FROM services WHERE template_type = 'letter' AND service_id = services.id""" - ) + op.execute("""UPDATE templates SET postage = services.postage + FROM services WHERE template_type = 'letter' AND service_id = services.id""") # ### end Alembic commands ### diff --git a/migrations/versions/0254_folders_for_all.py b/migrations/versions/0254_folders_for_all.py index c1f9c2034..7ab59f2a6 100644 --- a/migrations/versions/0254_folders_for_all.py +++ b/migrations/versions/0254_folders_for_all.py @@ -13,8 +13,7 @@ down_revision = "0253_set_template_postage" def upgrade(): - op.execute( - """ + op.execute(""" INSERT INTO service_permissions (service_id, permission, created_at) SELECT @@ -30,8 +29,7 @@ def upgrade(): service_id = services.id and permission = 'edit_folders' ) - """ - ) + """) def downgrade(): diff --git a/migrations/versions/0256_set_postage_tmplt_hstr.py b/migrations/versions/0256_set_postage_tmplt_hstr.py index 4eef2c7fb..19d565041 100644 --- a/migrations/versions/0256_set_postage_tmplt_hstr.py +++ b/migrations/versions/0256_set_postage_tmplt_hstr.py @@ -15,10 +15,8 @@ down_revision = "0254_folders_for_all" def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.execute( - """UPDATE templates_history SET postage = services.postage - FROM services WHERE template_type = 'letter' AND service_id = services.id""" - ) + op.execute("""UPDATE templates_history SET postage = services.postage + FROM services WHERE template_type = 'letter' AND service_id = services.id""") # ### end Alembic commands ### diff --git a/migrations/versions/0257_letter_branding_migration.py b/migrations/versions/0257_letter_branding_migration.py index bae00b333..a4cf22857 100644 --- a/migrations/versions/0257_letter_branding_migration.py +++ b/migrations/versions/0257_letter_branding_migration.py @@ -13,21 +13,17 @@ from alembic import op def upgrade(): - op.execute( - """INSERT INTO letter_branding (id, name, filename, domain) + op.execute("""INSERT INTO letter_branding (id, name, filename, domain) SELECT uuid_in(md5(random()::text)::cstring), name, filename, null - from dvla_organisation""" - ) + from dvla_organisation""") - op.execute( - """INSERT INTO service_letter_branding (service_id, letter_branding_id) + op.execute("""INSERT INTO service_letter_branding (service_id, letter_branding_id) SELECT S.id, LB.id FROM services s JOIN dvla_organisation d on (s.dvla_organisation_id = d.id) JOIN letter_branding lb on (lb.filename = d.filename) WHERE d.id != '001' - """ - ) + """) def downgrade(): diff --git a/migrations/versions/0259_remove_service_postage.py b/migrations/versions/0259_remove_service_postage.py index c399094ec..deb94d50f 100644 --- a/migrations/versions/0259_remove_service_postage.py +++ b/migrations/versions/0259_remove_service_postage.py @@ -19,13 +19,10 @@ def upgrade(): op.drop_column("services_history", "postage") op.execute("DELETE FROM service_permissions WHERE permission = 'choose_postage'") op.execute("DELETE FROM service_permission_types WHERE name = 'choose_postage'") - op.execute( - """UPDATE templates_history SET postage = templates.postage + op.execute("""UPDATE templates_history SET postage = templates.postage FROM templates WHERE templates_history.id = templates.id AND templates_history.template_type = 'letter' - AND templates_history.postage is null""" - ) - op.execute( - """ + AND templates_history.postage is null""") + op.execute(""" ALTER TABLE templates ADD CONSTRAINT "chk_templates_postage" CHECK ( CASE WHEN template_type = 'letter' THEN @@ -34,10 +31,8 @@ def upgrade(): postage is null END ) - """ - ) - op.execute( - """ + """) + op.execute(""" ALTER TABLE templates_history ADD CONSTRAINT "chk_templates_history_postage" CHECK ( CASE WHEN template_type = 'letter' THEN @@ -46,18 +41,13 @@ def upgrade(): postage is null END ) - """ - ) - op.execute( - """ + """) + op.execute(""" ALTER TABLE templates DROP CONSTRAINT "chk_templates_postage_null" - """ - ) - op.execute( - """ + """) + op.execute(""" ALTER TABLE templates_history DROP CONSTRAINT "chk_templates_history_postage_null" - """ - ) + """) # ### end Alembic commands ### @@ -76,8 +66,7 @@ def downgrade(): ), ) op.execute("INSERT INTO service_permission_types VALUES ('choose_postage')") - op.execute( - """ + op.execute(""" ALTER TABLE templates ADD CONSTRAINT "chk_templates_postage_null" CHECK ( CASE WHEN template_type = 'letter' THEN @@ -87,10 +76,8 @@ def downgrade(): postage is null END ) - """ - ) - op.execute( - """ + """) + op.execute(""" ALTER TABLE templates_history ADD CONSTRAINT "chk_templates_history_postage_null" CHECK ( CASE WHEN template_type = 'letter' THEN @@ -100,16 +87,11 @@ def downgrade(): postage is null END ) - """ - ) - op.execute( - """ + """) + op.execute(""" ALTER TABLE templates DROP CONSTRAINT "chk_templates_postage" - """ - ) - op.execute( - """ + """) + op.execute(""" ALTER TABLE templates_history DROP CONSTRAINT "chk_templates_history_postage" - """ - ) + """) # ### end Alembic commands ### diff --git a/migrations/versions/0260_remove_dvla_organisation.py b/migrations/versions/0260_remove_dvla_organisation.py index d5011a84d..82869bdca 100644 --- a/migrations/versions/0260_remove_dvla_organisation.py +++ b/migrations/versions/0260_remove_dvla_organisation.py @@ -33,8 +33,7 @@ def downgrade(): sa.PrimaryKeyConstraint("id", name="dvla_organisation_pkey"), ) # can't repopulate the services, but we can put the static data back in dvla_organisation - op.execute( - """ + op.execute(""" INSERT INTO dvla_organisation VALUES ('001', 'HM Government', 'hm-government'), ('002', 'Office of the Public Guardian', 'opg'), @@ -77,8 +76,7 @@ def downgrade(): ('528', 'North Yorkshire Council', 'north-yorkshire'), ('529', 'Redbridge Council', 'redbridge'), ('530', 'Wigan Council', 'wigan') - """ - ) + """) op.add_column( "services_history", diff --git a/migrations/versions/0262_remove_edit_folders.py b/migrations/versions/0262_remove_edit_folders.py index 3d5693adb..cec605f0d 100644 --- a/migrations/versions/0262_remove_edit_folders.py +++ b/migrations/versions/0262_remove_edit_folders.py @@ -21,8 +21,7 @@ def downgrade(): conn = op.get_bind() input_params = {"permission": "edit_folders"} conn.execute( - text( - """ + text(""" INSERT INTO service_permissions (service_id, permission, created_at) SELECT @@ -38,7 +37,6 @@ def downgrade(): service_id = services.id and permission = :permission ) - """ - ), + """), input_params, ) diff --git a/migrations/versions/0277_consent_to_research_null.py b/migrations/versions/0277_consent_to_research_null.py index 7d41c8530..1dab6c0c7 100644 --- a/migrations/versions/0277_consent_to_research_null.py +++ b/migrations/versions/0277_consent_to_research_null.py @@ -29,41 +29,33 @@ def upgrade(): nullable=True, server_default=sa.null(), ) - op.execute( - """ + op.execute(""" UPDATE services SET consent_to_research = null - """ - ) - op.execute( - """ + """) + op.execute(""" UPDATE services_history SET consent_to_research = null - """ - ) + """) def downgrade(): - op.execute( - """ + op.execute(""" UPDATE services SET consent_to_research = false - """ - ) - op.execute( - """ + """) + op.execute(""" UPDATE services_history SET consent_to_research = false - """ - ) + """) op.alter_column( "services_history", "consent_to_research", diff --git a/migrations/versions/0284_0283_retry.py b/migrations/versions/0284_0283_retry.py index e22f0d850..a9c6314d3 100644 --- a/migrations/versions/0284_0283_retry.py +++ b/migrations/versions/0284_0283_retry.py @@ -15,8 +15,7 @@ from alembic import op def upgrade(): - op.execute( - """ + op.execute(""" UPDATE services SET @@ -28,17 +27,14 @@ def upgrade(): services_history.version = 1 and services_history.created_by_id = users.id ; - """ - ) + """) def downgrade(): - op.execute( - """ + op.execute(""" UPDATE services SET count_as_live = true ; - """ - ) + """) diff --git a/migrations/versions/0285_default_org_branding.py b/migrations/versions/0285_default_org_branding.py index c8c6a2df9..68d01e32b 100644 --- a/migrations/versions/0285_default_org_branding.py +++ b/migrations/versions/0285_default_org_branding.py @@ -15,19 +15,15 @@ from alembic import op def upgrade(): - op.execute( - """UPDATE organisation SET email_branding_id = email_branding.id + op.execute("""UPDATE organisation SET email_branding_id = email_branding.id FROM email_branding WHERE email_branding.domain in (SELECT domain FROM domain WHERE domain.organisation_id = organisation.id) - """ - ) + """) - op.execute( - """UPDATE organisation SET letter_branding_id = letter_branding.id + op.execute("""UPDATE organisation SET letter_branding_id = letter_branding.id FROM letter_branding WHERE letter_branding.domain in (SELECT domain FROM domain WHERE domain.organisation_id = organisation.id) - """ - ) + """) def downgrade(): diff --git a/migrations/versions/0289_precompiled_for_all.py b/migrations/versions/0289_precompiled_for_all.py index 547bc0100..ffb654ca2 100644 --- a/migrations/versions/0289_precompiled_for_all.py +++ b/migrations/versions/0289_precompiled_for_all.py @@ -25,8 +25,7 @@ def downgrade(): op.execute("INSERT INTO service_permission_types values('precompiled_letter')") input_params = {"permission": "precompiled_letter"} conn.execute( - text( - """ + text(""" INSERT INTO service_permissions (service_id, permission, created_at) SELECT @@ -42,7 +41,6 @@ def downgrade(): service_id = services.id and permission = :permission ) - """ - ), + """), input_params, ) diff --git a/migrations/versions/0297_template_redacted_fix.py b/migrations/versions/0297_template_redacted_fix.py index c65a8a15a..b6f44f875 100644 --- a/migrations/versions/0297_template_redacted_fix.py +++ b/migrations/versions/0297_template_redacted_fix.py @@ -13,15 +13,13 @@ down_revision = "0296_agreement_signed_by_person" def upgrade(): - op.execute( - """ + op.execute(""" INSERT INTO template_redacted (template_id, redact_personalisation, updated_at, updated_by_id) SELECT templates.id, FALSE, now(), templates.created_by_id FROM templates WHERE templates.id NOT IN (SELECT template_id FROM template_redacted WHERE template_id = templates.id) ; - """ - ) + """) def downgrade(): diff --git a/migrations/versions/0298_add_mou_signed_receipt.py b/migrations/versions/0298_add_mou_signed_receipt.py index 6869ca35d..1e5c5bb34 100644 --- a/migrations/versions/0298_add_mou_signed_receipt.py +++ b/migrations/versions/0298_add_mou_signed_receipt.py @@ -136,8 +136,7 @@ def upgrade(): "user_id": current_app.config["NOTIFY_USER_ID"], } conn.execute( - text( - """ + text(""" INSERT INTO template_redacted ( template_id, @@ -145,8 +144,7 @@ def upgrade(): updated_at, updated_by_id ) VALUES ( :template_id, false, current_timestamp, :user_id ) - """ - ), + """), input_params, ) diff --git a/migrations/versions/0300_migrate_org_types.py b/migrations/versions/0300_migrate_org_types.py index 9f4bdedf5..f77f26306 100644 --- a/migrations/versions/0300_migrate_org_types.py +++ b/migrations/versions/0300_migrate_org_types.py @@ -18,27 +18,23 @@ environment = os.environ["NOTIFY_ENVIRONMENT"] def upgrade(): if environment not in ["live", "production"]: - op.execute( - """ + op.execute(""" UPDATE organisation SET organisation_type = 'nhs_local' WHERE organisation.organisation_type = 'nhs' - """ - ) + """) - op.execute( - """ + op.execute(""" UPDATE services SET organisation_type = 'nhs_local' WHERE services.organisation_type = 'nhs' - """ - ) + """) op.alter_column( "organisation_types", @@ -81,24 +77,20 @@ def downgrade(): ) if environment not in ["live", "production"]: - op.execute( - """ + op.execute(""" UPDATE organisation SET organisation_type = 'nhs' WHERE organisation_type = 'nhs_local' - """ - ) + """) - op.execute( - """ + op.execute(""" UPDATE services SET organisation_type = 'nhs' WHERE organisation_type = 'nhs_local' - """ - ) + """) diff --git a/migrations/versions/0308_delete_loadtesting_provider.py b/migrations/versions/0308_delete_loadtesting_provider.py index 8ccd6c513..ec7fdd42a 100644 --- a/migrations/versions/0308_delete_loadtesting_provider.py +++ b/migrations/versions/0308_delete_loadtesting_provider.py @@ -27,8 +27,7 @@ def upgrade(): def downgrade(): conn = op.get_bind() conn.execute( - text( - """ + text(""" INSERT INTO provider_details (id, display_name, identifier, priority, notification_type, active, version, supports_international) @@ -39,7 +38,6 @@ def downgrade(): (id, display_name, identifier, priority, notification_type, active, version, supports_international) VALUES (:uuid, 'Loadtesting', 'loadtesting', 100, 'sms', true, 1, false) - """ - ), + """), {"uuid": str(uuid.uuid4())}, ) diff --git a/migrations/versions/0314_populate_email_access.py b/migrations/versions/0314_populate_email_access.py index 972bdbf54..7ee04f06d 100644 --- a/migrations/versions/0314_populate_email_access.py +++ b/migrations/versions/0314_populate_email_access.py @@ -15,18 +15,15 @@ down_revision = "0313_email_access_validated_at" def upgrade(): # ### commands auto generated by Alembic - please adjust! ### # if user has email_auth, set email_access_validated_at on last login, else set it at user created_at date. - op.execute( - """ + op.execute(""" UPDATE users SET email_access_validated_at = created_at WHERE email_access_validated_at IS NULL - """ - ) - op.execute( - """ + """) + op.execute(""" UPDATE users SET @@ -35,8 +32,7 @@ def upgrade(): auth_type = 'email_auth' AND logged_in_at IS NOT NULL - """ - ) + """) op.alter_column("users", "email_access_validated_at", nullable=False) # ### end Alembic commands ### diff --git a/migrations/versions/0317_uploads_for_all.py b/migrations/versions/0317_uploads_for_all.py index 41c7472a2..c2c905143 100644 --- a/migrations/versions/0317_uploads_for_all.py +++ b/migrations/versions/0317_uploads_for_all.py @@ -13,8 +13,7 @@ down_revision = "0316_int_letters_permission" def upgrade(): - op.execute( - """ + op.execute(""" INSERT INTO service_permissions (service_id, permission, created_at) SELECT @@ -30,8 +29,7 @@ def upgrade(): service_id = services.id and permission = 'upload_letters' ) - """ - ) + """) def downgrade(): diff --git a/migrations/versions/0321_drop_postage_constraints.py b/migrations/versions/0321_drop_postage_constraints.py index 32a97077e..b35ca038c 100644 --- a/migrations/versions/0321_drop_postage_constraints.py +++ b/migrations/versions/0321_drop_postage_constraints.py @@ -33,8 +33,7 @@ def upgrade(): def downgrade(): # The downgrade command must not be run in production - it will lock the tables for a long time if environment not in ["live", "production"]: - op.execute( - """ + op.execute(""" ALTER TABLE notifications ADD CONSTRAINT "chk_notifications_postage_null" CHECK ( CASE WHEN notification_type = 'letter' THEN @@ -43,10 +42,8 @@ def downgrade(): postage is null END ) - """ - ) - op.execute( - """ + """) + op.execute(""" ALTER TABLE notification_history ADD CONSTRAINT "chk_notification_history_postage_null" CHECK ( CASE WHEN notification_type = 'letter' THEN @@ -55,10 +52,8 @@ def downgrade(): postage is null END ) - """ - ) - op.execute( - """ + """) + op.execute(""" ALTER TABLE templates ADD CONSTRAINT "chk_templates_postage" CHECK ( CASE WHEN template_type = 'letter' THEN @@ -67,10 +62,8 @@ def downgrade(): postage is null END ) - """ - ) - op.execute( - """ + """) + op.execute(""" ALTER TABLE templates_history ADD CONSTRAINT "chk_templates_history_postage" CHECK ( CASE WHEN template_type = 'letter' THEN @@ -79,5 +72,4 @@ def downgrade(): postage is null END ) - """ - ) + """) diff --git a/migrations/versions/0327_idx_notification_history.py b/migrations/versions/0327_idx_notification_history.py index 596974510..82d6c7177 100644 --- a/migrations/versions/0327_idx_notification_history.py +++ b/migrations/versions/0327_idx_notification_history.py @@ -43,24 +43,18 @@ def upgrade(): def downgrade(): if environment not in ["live", "production"]: - op.execute( - """ + op.execute(""" CREATE INDEX IF NOT EXISTS ix_notifications_service_id_created_at ON notifications(service_id, date(created_at)) - """ - ) - op.execute( - """ + """) + op.execute(""" CREATE INDEX IF NOT EXISTS ix_notification_history_created_at on notification_history(created_at) - """ - ) - op.execute( - """ + """) + op.execute(""" CREATE INDEX IF NOT EXISTS ix_notification_history_service_id_created_at on notification_history(created_at) - """ - ) + """) op.execute("DROP INDEX IF EXISTS ix_notification_history_service_id_composite") @@ -70,20 +64,14 @@ def downgrade(): op.execute( "CREATE INDEX IF NOT EXISTS ix_notification_history_service_id on notification_history (service_id)" ) - op.execute( - """ + op.execute(""" CREATE INDEX IF NOT EXISTS ix_notification_history_template_id on notification_history (template_id) - """ - ) - op.execute( - """ + """) + op.execute(""" CREATE INDEX IF NOT EXISTS ix_notification_history_notification_status on notification_history (notification_status) - """ - ) - op.execute( - """ + """) + op.execute(""" CREATE INDEX IF NOT EXISTS ix_notification_history_notification_type on notification_history (notification_type) - """ - ) + """) diff --git a/migrations/versions/0336_broadcast_msg_content_2.py b/migrations/versions/0336_broadcast_msg_content_2.py index 014059d00..e5903859f 100644 --- a/migrations/versions/0336_broadcast_msg_content_2.py +++ b/migrations/versions/0336_broadcast_msg_content_2.py @@ -20,9 +20,7 @@ down_revision = "0335_broadcast_msg_content" def upgrade(): conn = op.get_bind() - results = conn.execute( - sa.text( - """ + results = conn.execute(sa.text(""" UPDATE broadcast_message SET @@ -34,9 +32,7 @@ def upgrade(): broadcast_message.template_id = templates_history.id and broadcast_message.template_version = templates_history.version ; - """ - ) - ) + """)) def downgrade(): diff --git a/migrations/versions/0356_add_webautn_auth_type.py b/migrations/versions/0356_add_webautn_auth_type.py index 89bcfaa4e..70beb5025 100644 --- a/migrations/versions/0356_add_webautn_auth_type.py +++ b/migrations/versions/0356_add_webautn_auth_type.py @@ -19,13 +19,11 @@ def upgrade(): op.drop_constraint( "ck_users_mobile_or_email_auth", "users", type_=None, schema=None ) - op.execute( - """ + op.execute(""" ALTER TABLE users ADD CONSTRAINT "ck_user_has_mobile_or_other_auth" CHECK (auth_type in ('email_auth', 'webauthn_auth') or mobile_number is not null) NOT VALID - """ - ) + """) # ### end Alembic commands ### @@ -41,13 +39,11 @@ def downgrade(): op.drop_constraint( "ck_user_has_mobile_or_other_auth", "users", type_=None, schema=None ) - op.execute( - """ + op.execute(""" ALTER TABLE users ADD CONSTRAINT "ck_users_mobile_or_email_auth" CHECK (auth_type = 'email_auth' or mobile_number is not null) NOT VALID - """ - ) + """) op.execute("DELETE FROM auth_type WHERE name = 'webauthn_auth'") # ### end Alembic commands ### diff --git a/migrations/versions/0373_add_notifications_view.py b/migrations/versions/0373_add_notifications_view.py index 88c890bfd..583032862 100644 --- a/migrations/versions/0373_add_notifications_view.py +++ b/migrations/versions/0373_add_notifications_view.py @@ -15,8 +15,7 @@ down_revision = "0364_drop_old_column" def upgrade(): - op.execute( - """ + op.execute(""" CREATE VIEW notifications_all_time_view AS ( SELECT @@ -72,8 +71,7 @@ def upgrade(): document_download_count FROM notification_history ) - """ - ) + """) def downgrade(): diff --git a/migrations/versions/0385_remove postage_.py b/migrations/versions/0385_remove postage_.py index 058665960..195cd06bc 100644 --- a/migrations/versions/0385_remove postage_.py +++ b/migrations/versions/0385_remove postage_.py @@ -34,8 +34,7 @@ def upgrade(): # 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( - """ + op.execute(""" CREATE VIEW notifications_all_time_view AS ( SELECT @@ -89,8 +88,7 @@ def upgrade(): document_download_count FROM notification_history ) - """ - ) + """) op.drop_column("notification_history", "postage") op.drop_column("notifications", "postage") @@ -141,8 +139,7 @@ def downgrade(): ) op.execute("DROP VIEW notifications_all_time_view;") - op.execute( - """ + op.execute(""" CREATE VIEW notifications_all_time_view AS ( SELECT @@ -198,6 +195,5 @@ def downgrade(): document_download_count FROM notification_history ) - """ - ) + """) # ### end Alembic commands ### diff --git a/migrations/versions/0387_remove_letter_perms_.py b/migrations/versions/0387_remove_letter_perms_.py index 731754715..f4c259740 100644 --- a/migrations/versions/0387_remove_letter_perms_.py +++ b/migrations/versions/0387_remove_letter_perms_.py @@ -22,8 +22,7 @@ def upgrade(): def downgrade(): # this is the inverse of migration 0317 - op.execute( - """ + op.execute(""" INSERT INTO service_permissions (service_id, permission, created_at) SELECT @@ -39,8 +38,7 @@ def downgrade(): service_id = services.id and permission = 'upload_letters' ) - """ - ) + """) # ### end Alembic commands ### diff --git a/migrations/versions/0410_enums_for_everything.py b/migrations/versions/0410_enums_for_everything.py index b523e92df..c34821dc8 100644 --- a/migrations/versions/0410_enums_for_everything.py +++ b/migrations/versions/0410_enums_for_everything.py @@ -151,8 +151,7 @@ def view_handler() -> Iterator[None]: yield - op.execute( - """ + op.execute(""" CREATE VIEW notifications_all_time_view AS ( SELECT @@ -206,8 +205,7 @@ def view_handler() -> Iterator[None]: document_download_count FROM notification_history ) - """ - ) + """) def upgrade(): @@ -470,8 +468,7 @@ def upgrade(): postgresql_using=enum_using("notification_type", NotificationType), ) # Clobbering bad data here. These are values we don't use any more, and anything with them is unnecessary. - op.execute( - """ + op.execute(""" delete from service_permissions where @@ -482,8 +479,7 @@ def upgrade(): 'international_letters', 'broadcast' ); - """ - ) + """) op.alter_column( "service_permissions", "permission", diff --git a/migrations/versions/0418_user_state_enum.py b/migrations/versions/0418_user_state_enum.py index 3340c4d77..215840a05 100644 --- a/migrations/versions/0418_user_state_enum.py +++ b/migrations/versions/0418_user_state_enum.py @@ -63,8 +63,7 @@ def view_handler() -> Iterator[None]: yield - op.execute( - """ + op.execute(""" CREATE VIEW notifications_all_time_view AS ( SELECT @@ -118,8 +117,7 @@ def view_handler() -> Iterator[None]: document_download_count FROM notification_history ) - """ - ) + """) def upgrade(): diff --git a/notifications_utils/clients/redis/redis_client.py b/notifications_utils/clients/redis/redis_client.py index 5ec97ac09..f410a092b 100644 --- a/notifications_utils/clients/redis/redis_client.py +++ b/notifications_utils/clients/redis/redis_client.py @@ -52,16 +52,14 @@ class RedisClient: # delete keys matching a pattern supplied as a parameter. Does so in batches of 5000 to prevent unpack from # exceeding lua's stack limit, and also to prevent errors if no keys match the pattern. # Inspired by https://gist.github.com/ddre54/0a4751676272e0da8186 - self.scripts["delete-keys-by-pattern"] = self.redis_store.register_script( - """ + self.scripts["delete-keys-by-pattern"] = self.redis_store.register_script(""" local keys = redis.call('keys', ARGV[1]) local deleted = 0 for i=1, #keys, 5000 do deleted = deleted + redis.call('del', unpack(keys, i, math.min(i + 4999, #keys))) end return deleted - """ - ) + """) def delete_by_pattern(self, pattern, raise_exception=False): r""" diff --git a/tests/notifications_utils/test_formatters.py b/tests/notifications_utils/test_formatters.py index 7c66d7bc0..69c568c06 100644 --- a/tests/notifications_utils/test_formatters.py +++ b/tests/notifications_utils/test_formatters.py @@ -395,20 +395,16 @@ def test_strip_and_remove_obscure_whitespace_only_removes_normal_whitespace_from def test_remove_smart_quotes_from_email_addresses(): assert ( - remove_smart_quotes_from_email_addresses( - """ + remove_smart_quotes_from_email_addresses(""" line one’s quote first.o’last@example.com is someone’s email address line ‘three’ - """ - ) - == ( - """ + """) + == (""" line one’s quote first.o'last@example.com is someone’s email address line ‘three’ - """ - ) + """) ) diff --git a/tests/notifications_utils/test_recipient_csv.py b/tests/notifications_utils/test_recipient_csv.py index 7d47c2d3f..2d11b9445 100644 --- a/tests/notifications_utils/test_recipient_csv.py +++ b/tests/notifications_utils/test_recipient_csv.py @@ -1014,9 +1014,7 @@ def test_multiple_sms_recipient_columns_with_missing_data(column_name): """ names, phone number, {} "Joanna and Steve", 07900 900111 - """.format( - column_name - ), + """.format(column_name), template=_sample_template("sms"), allow_international_sms=True, )