2021-02-17 09:52:04 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
Revision ID: 0346_notify_number_sms_sender
|
|
|
|
|
Revises: 0345_move_broadcast_provider
|
|
|
|
|
Create Date: 2021-02-17 10:40:10.181087
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
import uuid
|
|
|
|
|
|
|
|
|
|
from alembic import op
|
|
|
|
|
from flask import current_app
|
2023-07-14 14:59:23 -07:00
|
|
|
from sqlalchemy import text
|
2021-02-17 09:52:04 +00:00
|
|
|
|
|
|
|
|
revision = '0346_notify_number_sms_sender'
|
|
|
|
|
down_revision = '0345_move_broadcast_provider'
|
|
|
|
|
|
|
|
|
|
SMS_SENDER_ID = 'd24b830b-57b4-4f14-bd80-02f46f8d54de'
|
|
|
|
|
NOTIFY_SERVICE_ID = current_app.config['NOTIFY_SERVICE_ID']
|
2023-03-01 13:46:08 -05:00
|
|
|
INBOUND_NUMBER = current_app.config['NOTIFY_INTERNATIONAL_SMS_SENDER'].strip('+')
|
2021-02-17 09:52:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def upgrade():
|
2023-07-14 14:59:23 -07:00
|
|
|
conn = op.get_bind()
|
|
|
|
|
input_params = {
|
|
|
|
|
"sms_sender_id": SMS_SENDER_ID,
|
|
|
|
|
"inbound_number": INBOUND_NUMBER,
|
|
|
|
|
"notify_service_id": NOTIFY_SERVICE_ID
|
|
|
|
|
}
|
|
|
|
|
conn.execute(text("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())"), input_params)
|
|
|
|
|
|
2021-02-17 09:52:04 +00:00
|
|
|
|
|
|
|
|
inbound_number_id = uuid.uuid4()
|
2023-07-14 14:59:23 -07:00
|
|
|
input_params = {
|
|
|
|
|
"inbound_number_id": inbound_number_id,
|
|
|
|
|
"inbound_number": INBOUND_NUMBER,
|
|
|
|
|
}
|
2021-02-17 09:52:04 +00:00
|
|
|
# by adding a row in inbound_number we ensure the number isn't added to the table and assigned to a service.
|
2023-07-14 14:59:23 -07:00
|
|
|
conn.execute(text("INSERT INTO INBOUND_NUMBERS (id, number, provider, active, created_at) VALUES(:inbound_number_id, "
|
|
|
|
|
":inbound_number, 'mmg', false, now())"), input_params)
|
2021-02-17 09:52:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def downgrade():
|
2023-07-14 14:59:23 -07:00
|
|
|
conn = op.get_bind()
|
|
|
|
|
input_params = {
|
|
|
|
|
"sms_sender_id": SMS_SENDER_ID
|
|
|
|
|
}
|
|
|
|
|
conn.execute(text("delete from service_sms_senders where id = :sms_sender_id"), input_params)
|
|
|
|
|
input_params = {
|
|
|
|
|
"inbound_number": INBOUND_NUMBER
|
|
|
|
|
}
|
|
|
|
|
conn.execute(text("delete from inbound_numbers where number = :inbound_number"), input_params)
|