From 00b63ca5c73f90620b41e4174b35b6a82f296db0 Mon Sep 17 00:00:00 2001 From: Pea Tyczynska Date: Wed, 9 Feb 2022 14:30:25 +0000 Subject: [PATCH] Migration adding cancelled_by_api_key_id to broadcast_message table. Also add created_by_api_key_id column that will supersede api_key_id_column. We do migration and code in separate PRs to make it easier to downgrade if anything goes wrong. --- .../versions/0363_cancelled_by_api_key.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 migrations/versions/0363_cancelled_by_api_key.py diff --git a/migrations/versions/0363_cancelled_by_api_key.py b/migrations/versions/0363_cancelled_by_api_key.py new file mode 100644 index 000000000..20856a287 --- /dev/null +++ b/migrations/versions/0363_cancelled_by_api_key.py @@ -0,0 +1,45 @@ +""" +Revision ID: 0363_cancelled_by_api_key +Revises: 0362_broadcast_msg_event +Create Date: 2022-02-09 14:05:27.750234 +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +revision = '0363_cancelled_by_api_key' +down_revision = '0362_broadcast_msg_event' + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('broadcast_message', sa.Column('created_by_api_key_id', postgresql.UUID(as_uuid=True), nullable=True)) + op.add_column( + 'broadcast_message', sa.Column('cancelled_by_api_key_id', postgresql.UUID(as_uuid=True), nullable=True) + ) + op.drop_constraint('broadcast_message_api_key_id_fkey', 'broadcast_message', type_='foreignkey') + op.create_foreign_key( + 'broadcast_message_created_by_api_key_id_fkey', + 'broadcast_message', + 'api_keys', + ['created_by_api_key_id'], + ['id'] + ) + op.create_foreign_key( + 'broadcast_message_cancelled_by_api_key_id_fkey', + 'broadcast_message', + 'api_keys', + ['cancelled_by_api_key_id'], + ['id'] + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint('broadcast_message_created_by_api_key_id_fkey', 'broadcast_message', type_='foreignkey') + op.drop_constraint('broadcast_message_cancelled_by_api_key_id_fkey', 'broadcast_message', type_='foreignkey') + op.create_foreign_key('broadcast_message_api_key_id_fkey', 'broadcast_message', 'api_keys', ['api_key_id'], ['id']) + op.drop_column('broadcast_message', 'cancelled_by_api_key_id') + op.drop_column('broadcast_message', 'created_by_api_key_id') + # ### end Alembic commands ###