freshen up files

This commit is contained in:
stvnrlly
2023-11-17 09:47:32 -05:00
parent 379140c740
commit 63952e35a9
29 changed files with 72 additions and 68 deletions

View File

@@ -62,12 +62,12 @@ def upgrade():
template_history_insert = """INSERT INTO templates_history (id, name, template_type, created_at,
content, archived, service_id,
subject, created_by_id, version)
VALUES (:template_id, :template_name, :template_type, :time_now,
VALUES (:template_id, :template_name, :template_type, :time_now,
:content, False, :service_id, :subject, :user_id, 1)
"""
template_insert = """INSERT INTO templates (id, name, template_type, created_at,
content, archived, service_id, subject, created_by_id, version)
VALUES (:template_id, :template_name, :template_type, :time_now,
VALUES (:template_id, :template_name, :template_type, :time_now,
:content, False, :service_id, :subject, :user_id, 1)
"""
email_verification_content = """Hi ((name)),\n\nTo complete your registration for GOV.UK Notify please click the link below\n\n((url))"""

View File

@@ -41,8 +41,8 @@ def upgrade():
conn.execute(
"""
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
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')
"""
)
@@ -50,8 +50,8 @@ def upgrade():
conn.execute(
"""
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
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')
"""
)
@@ -59,7 +59,7 @@ def upgrade():
conn.execute(
"""
INSERT INTO service_permissions (service_id, permission, created_at)
SELECT id, 'letter', '2017-05-26 17:30:00.000000' FROM services
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')
"""
@@ -67,8 +67,8 @@ def upgrade():
conn.execute(
"""
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
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')
"""
)

View File

@@ -37,10 +37,10 @@ def upgrade():
"time_now": datetime.utcnow(),
}
insert_row_if_not_exist = """
INSERT INTO annual_billing
(id, service_id, financial_year_start, free_sms_fragment_limit, created_at, updated_at)
SELECT uuid_in(md5(random()::text)::cstring), id, :current_year, :default_limit, :time_now, :time_now
FROM services WHERE id NOT IN
INSERT INTO annual_billing
(id, service_id, financial_year_start, free_sms_fragment_limit, created_at, updated_at)
SELECT uuid_in(md5(random()::text)::cstring), id, :current_year, :default_limit, :time_now, :time_now
FROM services WHERE id NOT IN
(select service_id from annual_billing)
"""
conn.execute(text(insert_row_if_not_exist), input_params)

View File

@@ -25,7 +25,7 @@ def upgrade():
history_query = """
UPDATE templates_history t_history set service_letter_contact_id = (
SELECT service_letter_contact_id from templates
where service_letter_contact_id is not null
where service_letter_contact_id is not null
and id = t_history.id
and version = t_history.version
)

View File

@@ -22,13 +22,13 @@ def upgrade():
template_insert = """
INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject,
created_by_id, version, process_type, hidden)
VALUES (:template_id, :template_name, :template_type, :time_now, :content, False,
VALUES (:template_id, :template_name, :template_type, :time_now, :content, False,
:notify_service_id, :subject, :user_id, 1, :process_type, false)
"""
template_history_insert = """
INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject,
created_by_id, version, process_type, hidden)
VALUES (:template_id, :template_name, :template_type, :time_now, :content, False,
VALUES (:template_id, :template_name, :template_type, :time_now, :content, False,
:notify_service_id, :subject, :user_id, 1, :process_type, false)
"""

View File

@@ -14,8 +14,8 @@ down_revision = "0189_ft_billing_data_type"
def upgrade():
op.get_bind()
op.execute("ALTER TABLE ft_billing DROP CONSTRAINT ft_billing_pkey")
sql = """ALTER TABLE ft_billing ADD CONSTRAINT
ft_billing_pkey PRIMARY KEY
sql = """ALTER TABLE ft_billing ADD CONSTRAINT
ft_billing_pkey PRIMARY KEY
(bst_date, template_id, service_id, rate_multiplier, provider, notification_type, international, rate)"""
op.execute(sql)
@@ -23,7 +23,7 @@ def upgrade():
def downgrade():
op.get_bind()
op.execute("ALTER TABLE ft_billing DROP CONSTRAINT ft_billing_pkey")
sql = """ALTER TABLE ft_billing ADD CONSTRAINT
ft_billing_pkey PRIMARY KEY
sql = """ALTER TABLE ft_billing ADD CONSTRAINT
ft_billing_pkey PRIMARY KEY
(bst_date, template_id, service_id, rate_multiplier, provider, notification_type, international)"""
op.execute(sql)

View File

@@ -22,13 +22,13 @@ def upgrade():
template_insert = """
INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject,
created_by_id, version, process_type, hidden)
VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, :notify_service_id,
VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, :notify_service_id,
:subject, :user_id, 1, :process_type, false)
"""
template_history_insert = """
INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject,
created_by_id, version, process_type, hidden)
VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, :notify_service_id,
VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, :notify_service_id,
:subject, :user_id, 1, :process_type, false)
"""

View File

@@ -16,14 +16,14 @@ import sqlalchemy as sa
def upgrade():
op.execute(
"""UPDATE organisation SET email_branding_id = email_branding.id
"""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
"""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)
"""

View File

@@ -21,15 +21,15 @@ def upgrade():
template_insert = """
INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject,
created_by_id, version, process_type, hidden)
VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, :notify_service_id,
VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, :notify_service_id,
:subject, :user_id, 1, :process_type, false)
"""
template_history_insert = """
INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject,
created_by_id, version, process_type, hidden)
VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, :notify_service_id,
VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, :notify_service_id,
:subject, :user_id, 1, :process_type, false)
"""
email_template_content = "\n".join(

View File

@@ -102,15 +102,15 @@ def upgrade():
insert_t = """
INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject,
created_by_id, version, process_type, hidden)
VALUES (:template_id, :template_name, :template_type, current_timestamp,
VALUES (:template_id, :template_name, :template_type, current_timestamp,
:content, False, :notify_service_id, :subject, :user_id, 1, :process_type, false)
"""
insert_th = """
INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject,
created_by_id, version, process_type, hidden)
VALUES (:template_id, :template_name, :template_type, current_timestamp,
VALUES (:template_id, :template_name, :template_type, current_timestamp,
:content, False, :notify_service_id, :subject, :user_id, 1, :process_type, false)
"""
for template in templates:

View File

@@ -34,7 +34,7 @@ def upgrade():
UPDATE services_history
SET organisation_id = :organisation_id
WHERE id = :service_id
AND version = (select max(version) from services_history sh2 where id = services_history.id);
AND version = (select max(version) from services_history sh2 where id = services_history.id);
"""
conn.execute(
text(history_sql),

View File

@@ -16,11 +16,11 @@ def upgrade():
conn = op.get_bind()
sql = """
select id, service_id, reference, updated_at
from notification_history
from notification_history
where notification_type = 'letter'
and notification_status = 'returned-letter'"""
insert_sql = """
insert into returned_letters(id, reported_at, service_id, notification_id, created_at, updated_at)
insert into returned_letters(id, reported_at, service_id, notification_id, created_at, updated_at)
values(uuid_in(md5(random()::text)::cstring), :updated_at, :service_id, :id, now(), null)
"""

View File

@@ -28,13 +28,13 @@ def upgrade():
# PLEASE NOTE: that if you create index on production you need to add concurrently to the create statement,
# however we are unable to do that inside a transaction like this upgrade method
ix_notifications_service_id_composite = """
CREATE INDEX ix_notifications_service_id_composite
CREATE INDEX ix_notifications_service_id_composite
on notifications (service_id, notification_type, notification_status, created_at)
"""
op.execute(ix_notifications_service_id_composite)
ix_notifications_notification_type_composite = """
CREATE INDEX ix_notifications_notification_type_composite
CREATE INDEX ix_notifications_notification_type_composite
on notifications (notification_type, notification_status, created_at)
"""
op.execute(ix_notifications_notification_type_composite)

View File

@@ -21,13 +21,13 @@ def upgrade():
op.execute("DROP INDEX IF EXISTS ix_notification_history_service_id_created_at")
index = """
CREATE INDEX IF NOT EXISTS ix_notification_history_service_id_composite
CREATE INDEX IF NOT EXISTS ix_notification_history_service_id_composite
on notification_history(service_id, key_type, notification_type, created_at)
"""
op.execute(index)
composite_index = """
CREATE INDEX IF NOT EXISTS ix_notifications_notification_type_composite
CREATE INDEX IF NOT EXISTS ix_notifications_notification_type_composite
on notifications(notification_type, notification_status, created_at)
"""
op.execute(composite_index)
@@ -43,19 +43,19 @@ def downgrade():
if environment not in ["live", "production"]:
op.execute(
"""
CREATE INDEX IF NOT EXISTS ix_notifications_service_id_created_at
CREATE INDEX IF NOT EXISTS ix_notifications_service_id_created_at
ON notifications(service_id, date(created_at))
"""
)
op.execute(
"""
CREATE INDEX IF NOT EXISTS ix_notification_history_created_at
CREATE INDEX IF NOT EXISTS ix_notification_history_created_at
on notification_history(created_at)
"""
)
op.execute(
"""
CREATE INDEX IF NOT EXISTS ix_notification_history_service_id_created_at
CREATE INDEX IF NOT EXISTS ix_notification_history_service_id_created_at
on notification_history(created_at)
"""
)
@@ -75,13 +75,13 @@ def downgrade():
)
op.execute(
"""
CREATE INDEX IF NOT EXISTS ix_notification_history_notification_status
CREATE INDEX IF NOT EXISTS ix_notification_history_notification_status
on notification_history (notification_status)
"""
)
op.execute(
"""
CREATE INDEX IF NOT EXISTS ix_notification_history_notification_type
CREATE INDEX IF NOT EXISTS ix_notification_history_notification_type
on notification_history (notification_type)
"""
)

View File

@@ -23,15 +23,15 @@ def upgrade():
template_insert = """
INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject,
created_by_id, version, process_type, hidden)
VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, :notify_service_id,
VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, :notify_service_id,
:subject, :user_id, 1, :process_type, false)
"""
template_history_insert = """
INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject,
created_by_id, version, process_type, hidden)
VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, :notify_service_id,
VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, :notify_service_id,
:subject, :user_id, 1, :process_type, false)
"""
email_template_content = "\n".join(

View File

@@ -17,7 +17,7 @@ environment = os.environ["NOTIFY_ENVIRONMENT"]
def upgrade():
index = """
CREATE UNIQUE INDEX CONCURRENTLY uix_service_id_financial_year_start
CREATE UNIQUE INDEX CONCURRENTLY uix_service_id_financial_year_start
ON annual_billing (service_id, financial_year_start)
"""
constraint = """

View File

@@ -26,7 +26,7 @@ def upgrade():
op.execute("UPDATE services_history SET organisation_type = 'federal';")
# remove uk values
service_delete = """DELETE FROM organisation_types WHERE name IN
service_delete = """DELETE FROM organisation_types WHERE name IN
('central','local','nhs','nhs_central','nhs_local','emergency_service','school_or_college','nhs_gp')
"""
op.execute(service_delete)
@@ -36,7 +36,7 @@ def upgrade():
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
service_insert = """INSERT INTO organisation_types VALUES
service_insert = """INSERT INTO organisation_types VALUES
('central','','250000')
('local','f','25000')
('nhs','','25000')