Allow broadcast messages to be created with API key

When we have a public API there will be no human creating the broadcast
message. Instead it will be created by an API integration, authenticated
by a key (just like for emails or texts).

This updates the database to:
- add a new foreign key from BroadcastMessages to API keys
- add a `reference` column

It doesn’t change the model yet, because the model is used by previous
migrations, so would cause them to fail when run before the new columns
exist. We can make this change in later pull requests.
This commit is contained in:
Chris Hill-Scott
2021-01-13 11:21:42 +00:00
parent 8d86d70739
commit fe420448e1
2 changed files with 35 additions and 1 deletions

View File

@@ -0,0 +1,26 @@
"""
Revision ID: 0337_broadcast_msg_api
Revises: 0336_broadcast_msg_content_2
Create Date: 2020-12-04 15:06:22.544803
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
revision = '0337_broadcast_msg_api'
down_revision = '0336_broadcast_msg_content_2'
def upgrade():
op.alter_column('broadcast_message', 'created_by_id', nullable=True)
op.add_column('broadcast_message', sa.Column('api_key_id', postgresql.UUID(), nullable=True))
op.create_foreign_key(None, 'broadcast_message', 'api_keys', ['api_key_id'], ['id'])
op.add_column('broadcast_message', sa.Column('reference', sa.String(length=255), nullable=True))
def downgrade():
op.alter_column('broadcast_message', 'created_by_id', nullable=False)
op.drop_column('broadcast_message', 'api_key_id')
op.add_column('broadcast_message', 'reference')