2022-02-08 16:57:46 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
Revision ID: 0364_drop_old_column
|
|
|
|
|
Revises: 0363_cancelled_by_api_key
|
|
|
|
|
Create Date: 2022-01-25 18:05:27.750234
|
|
|
|
|
|
|
|
|
|
"""
|
2024-04-01 15:12:33 -07:00
|
|
|
|
2022-02-08 16:57:46 +00:00
|
|
|
import sqlalchemy as sa
|
2023-12-08 21:43:52 -05:00
|
|
|
from alembic import op
|
2022-02-08 16:57:46 +00:00
|
|
|
from sqlalchemy.dialects import postgresql
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
revision = "0364_drop_old_column"
|
|
|
|
|
down_revision = "0363_cancelled_by_api_key"
|
2022-02-08 16:57:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def upgrade():
|
|
|
|
|
# move data over
|
2023-08-29 14:54:30 -07:00
|
|
|
op.execute(
|
|
|
|
|
"UPDATE broadcast_message SET created_by_api_key_id=api_key_id WHERE created_by_api_key_id IS NULL"
|
|
|
|
|
)
|
2022-02-08 16:57:46 +00:00
|
|
|
op.create_check_constraint(
|
|
|
|
|
"ck_broadcast_message_created_by_not_null",
|
|
|
|
|
"broadcast_message",
|
2023-08-29 14:54:30 -07:00
|
|
|
"created_by_id is not null or created_by_api_key_id is not null",
|
2022-02-08 16:57:46 +00:00
|
|
|
)
|
2023-08-29 14:54:30 -07:00
|
|
|
op.drop_column("broadcast_message", "api_key_id")
|
2022-02-08 16:57:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def downgrade():
|
2023-08-29 14:54:30 -07:00
|
|
|
op.add_column(
|
|
|
|
|
"broadcast_message",
|
|
|
|
|
sa.Column("api_key_id", postgresql.UUID(), autoincrement=False, nullable=True),
|
2022-02-08 16:57:46 +00:00
|
|
|
)
|
2023-08-29 14:54:30 -07:00
|
|
|
op.execute(
|
|
|
|
|
"UPDATE broadcast_message SET api_key_id=created_by_api_key_id"
|
|
|
|
|
) # move data over
|
|
|
|
|
op.drop_constraint("ck_broadcast_message_created_by_not_null", "broadcast_message")
|