add broadcast provider message table to DB

we need to track the state of sending to different provider separately
(and trigger them off separately, refer to references separately, etc)
This commit is contained in:
Leo Hemsted
2020-10-26 16:04:39 +00:00
parent 3aa602bd6b
commit 2e665de46d
2 changed files with 95 additions and 1 deletions

View File

@@ -2195,6 +2195,10 @@ class BroadcastStatusType(db.Model):
class BroadcastMessage(db.Model):
"""
This is for creating a message, viewing it in notify, adding areas, approvals, drafts, etc. Notify logic before
hitting send.
"""
__tablename__ = 'broadcast_message'
__table_args__ = (
db.ForeignKeyConstraint(
@@ -2299,7 +2303,8 @@ class BroadcastEventMessageType:
class BroadcastEvent(db.Model):
"""
This table represents a single CAP XML blob that we sent to the mobile network providers.
This table represents an instruction that we will send to the broadcast providers. It directly correlates with an
instruction from the admin - to broadcast a message, to cancel an existing message, or to update an existing one.
We should be able to create the complete CAP message without joining from this to any other tables, eg
template, service, or broadcast_message.
@@ -2398,3 +2403,43 @@ class BroadcastEvent(db.Model):
'transmitted_finishes_at': self.transmitted_finishes_at.strftime(DATETIME_FORMAT),
}
class BroadcastProvider:
EE = 'ee'
VODAFONE = 'vodafone'
THREE = 'three'
O2 = 'o2'
PROVIDERS = [EE, VODAFONE, THREE, O2]
class BroadcastProviderMessageStatus:
TECHNICAL_FAILURE = 'technical-failure' # Couldnt send (cbc proxy 5xx/4xx)
SENDING = 'sending' # Sent to cbc, awaiting response
ACK = 'returned-ack' # Received ack response
ERR = 'returned-error' # Received error response
STATES = [TECHNICAL_FAILURE, SENDING, ACK, ERR]
class BroadcastProviderMessage(db.Model):
"""
A row in this table represents the XML blob sent to a single provider.
"""
__tablename__ = 'broadcast_provider_message'
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
broadcast_event_id = db.Column(UUID(as_uuid=True), db.ForeignKey('broadcast_event.id'))
broadcast_event = db.relationship('BroadcastEvent')
# 'ee', 'three', 'vodafone', etc
provider = db.Column(db.String)
status = db.Column(db.String)
created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow)
updated_at = db.Column(db.DateTime, nullable=True, onupdate=datetime.datetime.utcnow)
UniqueConstraint(broadcast_event_id, provider)

View File

@@ -0,0 +1,49 @@
"""
Revision ID: 0332_broadcast_provider_msg
Revises: 0331_add_broadcast_org
Create Date: 2020-10-26 16:28:11.917468
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
revision = '0332_broadcast_provider_msg'
down_revision = '0331_add_broadcast_org'
STATUSES = [
'technical-failure',
'sending',
'returned-ack',
'returned-error',
]
def upgrade():
broadcast_provider_message_status_type = op.create_table(
'broadcast_provider_message_status_type',
sa.Column('name', sa.String(), nullable=False),
sa.PrimaryKeyConstraint('name')
)
op.bulk_insert(broadcast_provider_message_status_type, [{'name': status} for status in STATUSES])
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
'broadcast_provider_message',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('broadcast_event_id', postgresql.UUID(as_uuid=True), nullable=True),
sa.Column('provider', sa.String(), nullable=True),
sa.Column('status', sa.String(), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(['broadcast_event_id'], ['broadcast_event.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('broadcast_event_id', 'provider')
)
def downgrade():
op.drop_table('broadcast_provider_message')
op.drop_table('broadcast_provider_message_status_type')