Files
notifications-api/migrations/versions/0377_add_inbound_sms_number.py

102 lines
3.1 KiB
Python
Raw Normal View History

2022-10-03 09:05:34 -07:00
"""empty message
Revision ID: 0377_add_inbound_sms_number
Revises: 0376_add_provider_response
Create Date: 2022-09-30 11:04:15.888017
"""
2024-04-01 15:12:33 -07:00
2022-10-03 09:05:34 -07:00
import uuid
from alembic import op
from flask import current_app
2023-07-14 14:59:23 -07:00
from sqlalchemy import text
2022-10-03 09:05:34 -07:00
2023-08-29 14:54:30 -07:00
revision = "0377_add_inbound_sms_number"
down_revision = "0376_add_provider_response"
2022-10-03 09:05:34 -07:00
2023-08-29 14:54:30 -07:00
INBOUND_NUMBER_ID = "9b5bc009-b847-4b1f-8a54-f3b5f95cff18"
INBOUND_NUMBER = current_app.config["NOTIFY_INTERNATIONAL_SMS_SENDER"].strip("+")
DEFAULT_SERVICE_ID = current_app.config["NOTIFY_SERVICE_ID"]
2022-10-03 09:05:34 -07:00
2022-10-03 09:05:34 -07:00
def upgrade():
2023-07-14 14:59:23 -07:00
conn = op.get_bind()
2022-10-04 17:42:04 -07:00
# delete the previous inbound_number with mmg as provider
# table_name = 'inbound_numbers'
# select_by_col = 'number'
# select_by_val = INBOUND_NUMBER
2023-08-29 14:54:30 -07:00
input_params = {"inbound_number": INBOUND_NUMBER}
conn.execute(
text("delete from inbound_numbers where number =:inbound_number"), input_params
)
2023-03-01 13:46:08 -05:00
2023-07-14 14:59:23 -07:00
input_params = {
"inbound_number_id": INBOUND_NUMBER_ID,
"inbound_number": INBOUND_NUMBER,
2023-08-29 14:54:30 -07:00
"default_service_id": DEFAULT_SERVICE_ID,
2023-07-14 14:59:23 -07:00
}
2022-10-03 20:07:42 -07:00
# add the inbound number for the default service to inbound_numbers
2023-08-29 14:54:30 -07:00
conn.execute(
text(
"insert into inbound_numbers "
"(id, number, provider, service_id, active, created_at) "
"VALUES (:inbound_number_id, :inbound_number, 'sns', :default_service_id, 'true', now())"
),
input_params,
)
2023-03-01 13:46:08 -05:00
2023-08-29 14:54:30 -07:00
input_params = {"inbound_number": INBOUND_NUMBER}
2022-10-03 20:07:42 -07:00
# add the inbound number for the default service to service_sms_senders
2023-08-29 14:54:30 -07:00
conn.execute(
text(
"update service_sms_senders set sms_sender=:inbound_number "
"where id = '286d6176-adbe-7ea7-ba26-b7606ee5e2a4'"
),
input_params,
)
2023-03-01 13:46:08 -05:00
2022-10-03 20:07:42 -07:00
# add the inbound number for the default service to inbound_numbers
2023-08-29 14:54:30 -07:00
input_params = {"default_service_id": DEFAULT_SERVICE_ID}
conn.execute(
text(
"insert into service_permissions (service_id, permission, created_at) "
"VALUES(:default_service_id, 'inbound_sms', now())"
),
input_params,
)
2022-10-03 20:07:42 -07:00
# pass
2022-10-03 09:05:34 -07:00
def downgrade():
2023-07-14 14:59:23 -07:00
conn = op.get_bind()
2023-08-29 14:54:30 -07:00
input_params = {"inbound_number_id": INBOUND_NUMBER_ID}
conn.execute(
text(
"delete from service_sms_senders where inbound_number_id = :inbound_number_id"
),
input_params,
)
input_params = {"inbound_number": INBOUND_NUMBER}
conn.execute(
text("delete from inbound_numbers where number = :inbound_number"), input_params
)
input_params = {"default_service_id": DEFAULT_SERVICE_ID}
conn.execute(
text(
"delete from service_permissions "
"where service_id = :default_service_id and permission = 'inbound_sms'"
),
input_params,
)
input_params = {"inbound_number": INBOUND_NUMBER}
conn.execute(
text(
"insert into inbound_numbers (id, number, provider, service_id, active, created_at) "
"VALUES('d7aea27f-340b-4428-9b20-4470dd978bda', :inbound_number, 'mmg', 'null', 'false', 'now()')"
),
input_params,
)
2022-10-03 20:07:42 -07:00
# pass