fix: make profile migration idempotent
This commit is contained in:
@@ -12,7 +12,9 @@ depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
inspector = sa.inspect(op.get_bind())
|
||||
if "scenario_test_pack_profiles" not in inspector.get_table_names():
|
||||
op.create_table(
|
||||
"scenario_test_pack_profiles",
|
||||
sa.Column("profile_handle_id", sa.String(36), primary_key=True),
|
||||
sa.Column("owner_principal", sa.String(128), nullable=False),
|
||||
@@ -28,10 +30,16 @@ def upgrade() -> None:
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(), nullable=False),
|
||||
)
|
||||
op.create_index("ix_scenario_test_pack_profiles_owner_principal", "scenario_test_pack_profiles", ["owner_principal"])
|
||||
op.create_index("ix_scenario_test_pack_profiles_dashboard_id", "scenario_test_pack_profiles", ["dashboard_id"])
|
||||
op.create_index("ix_scenario_test_pack_profiles_profile_digest", "scenario_test_pack_profiles", ["profile_digest"])
|
||||
op.create_table(
|
||||
existing_indexes = {item["name"] for item in inspector.get_indexes("scenario_test_pack_profiles")}
|
||||
for name, column in (
|
||||
("ix_scenario_test_pack_profiles_owner_principal", "owner_principal"),
|
||||
("ix_scenario_test_pack_profiles_dashboard_id", "dashboard_id"),
|
||||
("ix_scenario_test_pack_profiles_profile_digest", "profile_digest"),
|
||||
):
|
||||
if name not in existing_indexes:
|
||||
op.create_index(name, "scenario_test_pack_profiles", [column])
|
||||
if "scenario_test_pack_profile_receipts" not in inspector.get_table_names():
|
||||
op.create_table(
|
||||
"scenario_test_pack_profile_receipts",
|
||||
sa.Column("receipt_id", sa.String(36), primary_key=True),
|
||||
sa.Column("profile_handle_id", sa.String(36), nullable=False),
|
||||
|
||||
Reference in New Issue
Block a user