mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-27 17:53:42 -04:00
Compare commits
46 Commits
1-26-26
...
03f28ca25a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03f28ca25a | ||
|
|
99f325f5fd | ||
|
|
24294972c5 | ||
|
|
ff2e8a1c17 | ||
|
|
d6c216c157 | ||
|
|
8420d602a2 | ||
|
|
9250b19fbf | ||
|
|
b90e103d03 | ||
|
|
dbebb24690 | ||
|
|
e4c61ca897 | ||
|
|
8b45b72e03 | ||
|
|
5803215c9a | ||
|
|
adede6f78b | ||
|
|
f51eb6c157 | ||
|
|
914efac7e6 | ||
|
|
05849703b8 | ||
|
|
e8ca918db0 | ||
|
|
77976a9b06 | ||
|
|
7ad499eb97 | ||
|
|
a99685a6a0 | ||
|
|
4896e72306 | ||
|
|
09bc850e6b | ||
|
|
27b37c7a5e | ||
|
|
48beb45add | ||
|
|
049f52d9dc | ||
|
|
05a5e33dc3 | ||
|
|
fc5e356cad | ||
|
|
de73d515ac | ||
|
|
f9322ecfa2 | ||
|
|
e516878565 | ||
|
|
afe927728a | ||
|
|
e557f236f9 | ||
|
|
7ff7263717 | ||
|
|
b2bd1d52b2 | ||
|
|
38bce0a994 | ||
|
|
f6e77c2546 | ||
|
|
2972678def | ||
|
|
e625661796 | ||
|
|
68f7bc3547 | ||
|
|
24ca958f30 | ||
|
|
746a891bc0 | ||
|
|
231d851969 | ||
|
|
3741b4cccf | ||
|
|
b88b75f20a | ||
|
|
04d8e8fc48 | ||
|
|
0c10e1cdde |
@@ -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)}"
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 ###
|
||||
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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'")
|
||||
|
||||
|
||||
@@ -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'
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
@@ -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
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
|
||||
@@ -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')
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
@@ -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"]
|
||||
)
|
||||
|
||||
@@ -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')"
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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})
|
||||
|
||||
|
||||
|
||||
@@ -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 ###
|
||||
|
||||
|
||||
|
||||
@@ -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 ###
|
||||
|
||||
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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 ###
|
||||
|
||||
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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 ###
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
;
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
|
||||
@@ -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'
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
@@ -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())},
|
||||
)
|
||||
|
||||
@@ -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 ###
|
||||
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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
|
||||
)
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
@@ -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)
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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 ###
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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 ###
|
||||
|
||||
@@ -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 ###
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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"""
|
||||
|
||||
754
poetry.lock
generated
754
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -9,12 +9,12 @@ readme = "README.md"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.13.2"
|
||||
alembic = "==1.18.1"
|
||||
alembic = "==1.18.4"
|
||||
amqp = "==5.3.1"
|
||||
beautifulsoup4 = "==4.14.3"
|
||||
boto3 = "^1.38.27"
|
||||
botocore = "^1.38.27"
|
||||
cachetools = "==6.2.4"
|
||||
cachetools = "==7.0.1"
|
||||
celery = {version = "==5.6.2", extras = ["redis"]}
|
||||
certifi = ">=2022.12.7"
|
||||
cffi = "==2.0.0"
|
||||
@@ -31,13 +31,13 @@ flask-bcrypt = "==1.0.1"
|
||||
flask-migrate = "==4.1.0"
|
||||
flask-redis = "==0.4.0"
|
||||
flask-sqlalchemy = "^3.1.1"
|
||||
gunicorn = {version = "==24.1.1", extras = ["gevent"]}
|
||||
gunicorn = {version = "==25.1.0", extras = ["gevent"]}
|
||||
iso8601 = "==2.1.0"
|
||||
jsonschema = {version = "==4.26.0", extras = ["format"]}
|
||||
lxml = "==6.0.2"
|
||||
marshmallow = "^4.2.1"
|
||||
marshmallow = "^4.2.2"
|
||||
marshmallow-sqlalchemy = "^1.4.2"
|
||||
newrelic = "^11.3.0"
|
||||
newrelic = "^11.5.0"
|
||||
packaging = "==26.0"
|
||||
poetry-dotenv-plugin = "==0.2.0"
|
||||
psycopg2-binary = "==2.9.11"
|
||||
@@ -45,20 +45,20 @@ pyjwt = "==2.10.1"
|
||||
python-dotenv = "==1.2.1"
|
||||
sqlalchemy = "==2.0.46"
|
||||
werkzeug = "^3.1.5"
|
||||
faker = "^40.1.0"
|
||||
faker = "^40.5.1"
|
||||
async-timeout = "^5.0.1"
|
||||
bleach = "^6.3.0"
|
||||
geojson = "^3.2.0"
|
||||
numpy = "^2.4.1"
|
||||
numpy = "^2.4.2"
|
||||
ordered-set = "^4.1.0"
|
||||
phonenumbers = "^9.0.22"
|
||||
phonenumbers = "^9.0.24"
|
||||
python-json-logger = "^4.0.0"
|
||||
regex = "^2026.1.15"
|
||||
regex = "^2026.2.19"
|
||||
shapely = "^2.1.2"
|
||||
smartypants = "^2.0.1"
|
||||
mistune = "^3.2.0"
|
||||
blinker = "^1.9.0"
|
||||
cryptography = "^46.0.3"
|
||||
cryptography = "^46.0.5"
|
||||
idna = "^3.11"
|
||||
jmespath = "^1.1.0"
|
||||
markupsafe = "^3.0.3"
|
||||
@@ -73,7 +73,7 @@ itsdangerous = "^2.2.0"
|
||||
jinja2 = "^3.1.6"
|
||||
redis = "^6.4.0"
|
||||
requests = "^2.32.5"
|
||||
virtualenv = "^20.36.1"
|
||||
virtualenv = "^21.0.0"
|
||||
marshmallow-enum = "^1.5.1"
|
||||
awscli = "^1.40.36"
|
||||
typing-extensions = "^4.15.0"
|
||||
@@ -94,21 +94,21 @@ exceptiongroup = "==1.3.1"
|
||||
flake8 = "^7.3.0"
|
||||
flake8-bugbear = "^25.11.29"
|
||||
freezegun = "^1.5.5"
|
||||
hypothesis = "^6.151.2"
|
||||
hypothesis = "^6.151.9"
|
||||
honcho = "*"
|
||||
isort = "^7.0.0"
|
||||
isort = "^8.0.0"
|
||||
jinja2-cli = {version = "==1.0.0", extras = ["yaml"]}
|
||||
moto = "==5.1.20"
|
||||
moto = "==5.1.21"
|
||||
pip-audit = "*"
|
||||
pre-commit = "^4.5.1"
|
||||
pytest = "^9.0.2"
|
||||
pytest-env = "^1.2.0"
|
||||
pytest-env = "^1.5.0"
|
||||
pytest-mock = "^3.15.1"
|
||||
pytest-cov = "^7.0.0"
|
||||
pytest-xdist = "^3.8.0"
|
||||
radon = "^6.0.1"
|
||||
requests-mock = "^1.11.0"
|
||||
setuptools = "^80.9.0"
|
||||
setuptools = "^82.0.0"
|
||||
sqlalchemy-utils = "^0.41.2"
|
||||
vulture = "^2.10"
|
||||
detect-secrets = "^1.5.0"
|
||||
|
||||
@@ -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’
|
||||
"""
|
||||
)
|
||||
""")
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user