add broadcast_event table

It's clear that we need a way to track updates to a broadcast message.
It's also clear that we'll need some kind of audit log that captures
exactly what was sent out in a message.

This commit adds a new database table, `broadcast_event`, which maps 1:1
with CAP XML sent to the CBCs. We'll create one of these just before
sending out.

The main driver for this was that cancel and update messages need to
contain a list of references of all previous messages that they're
amending. This is of format `{sender},{identifier},{sent_timestamp}`,
and the identifier itself needs to be unique for each message.
This commit is contained in:
Leo Hemsted
2020-07-24 12:46:28 +01:00
parent 5dc8b43242
commit 36ae5fadf6
4 changed files with 136 additions and 1 deletions

View File

@@ -1,5 +1,5 @@
from app import db
from app.models import BroadcastMessage
from app.models import BroadcastMessage, BroadcastEvent
from app.dao.dao_utils import transactional
@@ -28,3 +28,16 @@ def dao_get_broadcast_messages_for_service(service_id):
return BroadcastMessage.query.filter(
BroadcastMessage.service_id == service_id
).order_by(BroadcastMessage.created_at)
def dao_get_earlier_events_for_broadcast_event(broadcast_event_id):
"""
This is used to build up the references list.
"""
this_event = BroadcastEvent.query.get(broadcast_event_id)
return BroadcastEvent.query.filter(
BroadcastEvent.broadcast_message_id == this_event.id,
BroadcastEvent.sent_at < this_event.sent_at
).order_by(
BroadcastEvent.sent_at.asc()
)