add service broadcast provider restriction table

some services only send to one provider. This is a platform admin
setting to allow us to test integrations and providers manually without
affecting other broadcasts from different services.

one-to-one - a service can either send to all as normal, or send to only
one provider.
This commit is contained in:
Leo Hemsted
2020-12-01 17:24:08 +00:00
parent 3bf936b782
commit 1a083134fa
2 changed files with 47 additions and 0 deletions

View File

@@ -2472,3 +2472,22 @@ class BroadcastProviderMessage(db.Model):
updated_at = db.Column(db.DateTime, nullable=True, onupdate=datetime.datetime.utcnow) updated_at = db.Column(db.DateTime, nullable=True, onupdate=datetime.datetime.utcnow)
UniqueConstraint(broadcast_event_id, provider) UniqueConstraint(broadcast_event_id, provider)
class ServiceBroadcastProviderRestriction(db.Model):
"""
Most services don't send broadcasts. Of those that do, most send to all broadcast providers.
However, some services don't send to all providers. These services are test services that we or the providers
themselves use.
This table links those services. There should only be one row per service in this table, and this is enforced by
the service_id being a primary key.
"""
__tablename__ = "service_broadcast_provider_restriction"
service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), primary_key=True, nullable=False)
service = db.relationship(Service, backref=db.backref("allowed_broadcast_provider", uselist=False))
provider = db.Column(db.String, nullable=False)
created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow)

View File

@@ -0,0 +1,28 @@
"""
Revision ID: 0333_service_broadcast_provider
Revises: 0332_broadcast_provider_msg
Create Date: 2020-12-01 17:03:18.209780
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
revision = '0333_service_broadcast_provider'
down_revision = '0332_broadcast_provider_msg'
def upgrade():
op.create_table(
'service_broadcast_provider_restriction',
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('provider', sa.String(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
sa.PrimaryKeyConstraint('service_id')
)
def downgrade():
op.drop_table('service_broadcast_provider_restriction')