mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-16 20:48:37 -04:00
add broadcast_message to database
new broadcast_message table. contains a whole bunch of timestamps, a couple of user ids for who created and who approved, some personalisation and a template id/version. areas is a jsonb field - it is expected that this will be an array, for example `["england", "wales"]` intended valid state transitions are as follows, from an initial status of draft * draft -> pending-approval, rejected * pending-approval -> broadcasting, rejected, (draft maybe) * broadcasting -> completed, cancelled rejected, completed, cancelled and technical-failure are terminating states. also copy across the enum switching code from migration 0060 (adding letter type).
This commit is contained in:
@@ -2148,3 +2148,65 @@ class ServiceContactList(db.Model):
|
||||
"created_at": created_at_in_bst.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
}
|
||||
return contact_list
|
||||
|
||||
|
||||
class BroadcastStatusType(db.Model):
|
||||
__tablename__ = 'broadcast_status_type'
|
||||
DRAFT = 'draft'
|
||||
PENDING_APPROVAL = 'pending-approval'
|
||||
REJECTED = 'rejected'
|
||||
BROADCASTING = 'broadcasting'
|
||||
COMPLETED = 'completed'
|
||||
CANCELLED = 'cancelled'
|
||||
TECHNICAL_FAILURE = 'technical-failure'
|
||||
|
||||
STATUSES = [DRAFT, PENDING_APPROVAL, REJECTED, BROADCASTING, COMPLETED, CANCELLED, TECHNICAL_FAILURE]
|
||||
|
||||
name = db.Column(db.String, primary_key=True)
|
||||
|
||||
|
||||
class BroadcastMessage(db.Model):
|
||||
__tablename__ = 'broadcast_message'
|
||||
__table_args__ = (
|
||||
db.ForeignKeyConstraint(
|
||||
['template_id', 'template_version'],
|
||||
['templates_history.id', 'templates_history.version'],
|
||||
),
|
||||
{}
|
||||
)
|
||||
|
||||
id = db.Column(UUID(as_uuid=True), primary_key=True)
|
||||
|
||||
service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'))
|
||||
service = db.relationship('Service', backref='broadcast_messages')
|
||||
|
||||
template_id = db.Column(UUID(as_uuid=True), nullable=False)
|
||||
template_version = db.Column(db.Integer, nullable=False)
|
||||
template = db.relationship('TemplateHistory', backref='broadcast_messages')
|
||||
|
||||
_personalisation = db.Column(db.String, nullable=True)
|
||||
|
||||
status = db.Column(
|
||||
db.String,
|
||||
db.ForeignKey('broadcast_status_type.name'),
|
||||
nullable=False,
|
||||
default=BroadcastStatusType.DRAFT
|
||||
)
|
||||
|
||||
# these times are related to the actual broadcast, rather than auditing purposes
|
||||
starts_at = db.Column(db.DateTime, nullable=True)
|
||||
finishes_at = db.Column(db.DateTime, nullable=True) # isn't updated if user cancels
|
||||
|
||||
# these times correspond to when
|
||||
created_at = db.Column(db.DateTime, nullable=False)
|
||||
approved_at = db.Column(db.DateTime, nullable=True)
|
||||
cancelled_at = db.Column(db.DateTime, nullable=True)
|
||||
updated_at = db.Column(db.DateTime, nullable=True, onupdate=datetime.datetime.utcnow)
|
||||
|
||||
created_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), nullable=False)
|
||||
approved_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), nullable=True)
|
||||
cancelled_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), nullable=True)
|
||||
|
||||
created_by = db.relationship('User', foreign_keys=[created_by_id])
|
||||
approved_by = db.relationship('User', foreign_keys=[approved_by_id])
|
||||
cancelled_by = db.relationship('User', foreign_keys=[cancelled_by_id])
|
||||
|
||||
Reference in New Issue
Block a user