This commit is contained in:
Kenneth Kehl
2023-08-29 14:54:30 -07:00
parent 19dcd7a48b
commit 1ecb747c6d
588 changed files with 34100 additions and 23589 deletions

View File

@@ -9,25 +9,29 @@ from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
revision = '0364_drop_old_column'
down_revision = '0363_cancelled_by_api_key'
revision = "0364_drop_old_column"
down_revision = "0363_cancelled_by_api_key"
def upgrade():
# move data over
op.execute("UPDATE broadcast_message SET created_by_api_key_id=api_key_id WHERE created_by_api_key_id IS NULL")
op.execute(
"UPDATE broadcast_message SET created_by_api_key_id=api_key_id WHERE created_by_api_key_id IS NULL"
)
op.create_check_constraint(
"ck_broadcast_message_created_by_not_null",
"broadcast_message",
"created_by_id is not null or created_by_api_key_id is not null"
"created_by_id is not null or created_by_api_key_id is not null",
)
op.drop_column('broadcast_message', 'api_key_id')
op.drop_column("broadcast_message", "api_key_id")
def downgrade():
op.add_column('broadcast_message', sa.Column('api_key_id', postgresql.UUID(), autoincrement=False, nullable=True))
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"
op.add_column(
"broadcast_message",
sa.Column("api_key_id", postgresql.UUID(), autoincrement=False, nullable=True),
)
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")