Update sms sender numbers in db

This commit is contained in:
Ryan Ahearn
2023-03-01 13:46:08 -05:00
parent 28f8649444
commit dd0c7ebd56
4 changed files with 38 additions and 7 deletions

View File

@@ -166,7 +166,7 @@ class Config(object):
MOU_SIGNER_RECEIPT_TEMPLATE_ID = '4fd2e43c-309b-4e50-8fb8-1955852d9d71' MOU_SIGNER_RECEIPT_TEMPLATE_ID = '4fd2e43c-309b-4e50-8fb8-1955852d9d71'
MOU_SIGNED_ON_BEHALF_SIGNER_RECEIPT_TEMPLATE_ID = 'c20206d5-bf03-4002-9a90-37d5032d9e84' MOU_SIGNED_ON_BEHALF_SIGNER_RECEIPT_TEMPLATE_ID = 'c20206d5-bf03-4002-9a90-37d5032d9e84'
MOU_SIGNED_ON_BEHALF_ON_BEHALF_RECEIPT_TEMPLATE_ID = '522b6657-5ca5-4368-a294-6b527703bd0b' MOU_SIGNED_ON_BEHALF_ON_BEHALF_RECEIPT_TEMPLATE_ID = '522b6657-5ca5-4368-a294-6b527703bd0b'
NOTIFY_INTERNATIONAL_SMS_SENDER = '18446120782' NOTIFY_INTERNATIONAL_SMS_SENDER = getenv('AWS_US_TOLL_FREE_NUMBER')
LETTERS_VOLUME_EMAIL_TEMPLATE_ID = '11fad854-fd38-4a7c-bd17-805fb13dfc12' LETTERS_VOLUME_EMAIL_TEMPLATE_ID = '11fad854-fd38-4a7c-bd17-805fb13dfc12'
NHS_EMAIL_BRANDING_ID = 'a7dc4e56-660b-4db7-8cff-12c37b12b5ea' NHS_EMAIL_BRANDING_ID = 'a7dc4e56-660b-4db7-8cff-12c37b12b5ea'
# we only need real email in Live environment (production) # we only need real email in Live environment (production)

View File

@@ -15,12 +15,12 @@ down_revision = '0345_move_broadcast_provider'
SMS_SENDER_ID = 'd24b830b-57b4-4f14-bd80-02f46f8d54de' SMS_SENDER_ID = 'd24b830b-57b4-4f14-bd80-02f46f8d54de'
NOTIFY_SERVICE_ID = current_app.config['NOTIFY_SERVICE_ID'] NOTIFY_SERVICE_ID = current_app.config['NOTIFY_SERVICE_ID']
INBOUND_NUMBER = current_app.config['NOTIFY_INTERNATIONAL_SMS_SENDER'] INBOUND_NUMBER = current_app.config['NOTIFY_INTERNATIONAL_SMS_SENDER'].strip('+')
def upgrade(): def upgrade():
sql = f"""INSERT INTO service_sms_senders (id, sms_sender, service_id, is_default, created_at) sql = f"""INSERT INTO service_sms_senders (id, sms_sender, service_id, is_default, created_at)
VALUES ('{SMS_SENDER_ID}', '{INBOUND_NUMBER}', '{NOTIFY_SERVICE_ID}',false, now())""" VALUES ('{SMS_SENDER_ID}', '{INBOUND_NUMBER}', '{NOTIFY_SERVICE_ID}',false, now())"""
op.execute(sql) op.execute(sql)

View File

@@ -15,7 +15,7 @@ revision = '0377_add_inbound_sms_number'
down_revision = '0376_add_provider_response' down_revision = '0376_add_provider_response'
INBOUND_NUMBER_ID = '9b5bc009-b847-4b1f-8a54-f3b5f95cff18' INBOUND_NUMBER_ID = '9b5bc009-b847-4b1f-8a54-f3b5f95cff18'
INBOUND_NUMBER = current_app.config['NOTIFY_INTERNATIONAL_SMS_SENDER'] INBOUND_NUMBER = current_app.config['NOTIFY_INTERNATIONAL_SMS_SENDER'].strip('+')
DEFAULT_SERVICE_ID = current_app.config['NOTIFY_SERVICE_ID'] DEFAULT_SERVICE_ID = current_app.config['NOTIFY_SERVICE_ID']
def upgrade(): def upgrade():
@@ -26,20 +26,20 @@ def upgrade():
select_by_col = 'number' select_by_col = 'number'
select_by_val = INBOUND_NUMBER select_by_val = INBOUND_NUMBER
op.execute(f"delete from {table_name} where {select_by_col} = '{select_by_val}'") op.execute(f"delete from {table_name} where {select_by_col} = '{select_by_val}'")
# add the inbound number for the default service to inbound_numbers # add the inbound number for the default service to inbound_numbers
table_name = 'inbound_numbers' table_name = 'inbound_numbers'
provider = 'sns' provider = 'sns'
active = 'true' active = 'true'
op.execute(f"insert into {table_name} (id, number, provider, service_id, active, created_at) VALUES('{INBOUND_NUMBER_ID}', '{INBOUND_NUMBER}', '{provider}','{DEFAULT_SERVICE_ID}', '{active}', 'now()')") op.execute(f"insert into {table_name} (id, number, provider, service_id, active, created_at) VALUES('{INBOUND_NUMBER_ID}', '{INBOUND_NUMBER}', '{provider}','{DEFAULT_SERVICE_ID}', '{active}', 'now()')")
# add the inbound number for the default service to service_sms_senders # add the inbound number for the default service to service_sms_senders
table_name = 'service_sms_senders' table_name = 'service_sms_senders'
sms_sender = INBOUND_NUMBER sms_sender = INBOUND_NUMBER
select_by_col = 'id' select_by_col = 'id'
select_by_val = '286d6176-adbe-7ea7-ba26-b7606ee5e2a4' select_by_val = '286d6176-adbe-7ea7-ba26-b7606ee5e2a4'
op.execute(f"update {table_name} set {'sms_sender'}='{sms_sender}' where {select_by_col} = '{select_by_val}'") op.execute(f"update {table_name} set {'sms_sender'}='{sms_sender}' where {select_by_col} = '{select_by_val}'")
# add the inbound number for the default service to inbound_numbers # add the inbound number for the default service to inbound_numbers
table_name = 'service_permissions' table_name = 'service_permissions'
permission = 'inbound_sms' permission = 'inbound_sms'

View File

@@ -0,0 +1,31 @@
"""
Revision ID: 0391_update_sms_numbers
Revises: 0390_drop_dvla_provider.py
Create Date: 2023-03-01 12:36:38.226954
"""
from alembic import op
from flask import current_app
import sqlalchemy as sa
revision = '0391_update_sms_numbers'
down_revision = '0390_drop_dvla_provider.py'
OLD_SMS_NUMBER = "18446120782"
NEW_SMS_NUMBER = current_app.config['NOTIFY_INTERNATIONAL_SMS_SENDER'].strip('+')
def upgrade():
op.alter_column("service_sms_senders", "sms_sender", type_=sa.types.String(length=255))
op.alter_column("inbound_numbers", "number", type_=sa.types.String(length=255))
op.execute(f"UPDATE service_sms_senders SET sms_sender = '+{NEW_SMS_NUMBER}' WHERE sms_sender IN ('{OLD_SMS_NUMBER}', '{NEW_SMS_NUMBER}')")
op.execute(f"UPDATE inbound_numbers SET number = '+{NEW_SMS_NUMBER}' WHERE number IN ('{OLD_SMS_NUMBER}', '{NEW_SMS_NUMBER}')")
def downgrade():
op.execute(f"UPDATE service_sms_senders SET sms_sender = '{OLD_SMS_NUMBER}' WHERE sms_sender = '+{NEW_SMS_NUMBER}'")
op.execute(f"UPDATE inbound_numbers SET number = '{OLD_SMS_NUMBER}' WHERE number = '+{NEW_SMS_NUMBER}'")
op.alter_column("service_sms_senders", "sms_sender", type_=sa.types.String(length=11))
op.alter_column("inbound_numbers", "number", type_=sa.types.String(length=11))