feat: add conditional creation of skills marketplace and gateway installed skills tables with index checks
This commit is contained in:
committed by
Abhimanyu Saharan
parent
e7b5df0bce
commit
88565f4d69
@@ -19,7 +19,19 @@ branch_labels = None
|
|||||||
depends_on = None
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def _has_table(table_name: str) -> bool:
|
||||||
|
return sa.inspect(op.get_bind()).has_table(table_name)
|
||||||
|
|
||||||
|
|
||||||
|
def _has_index(table_name: str, index_name: str) -> bool:
|
||||||
|
if not _has_table(table_name):
|
||||||
|
return False
|
||||||
|
indexes = sa.inspect(op.get_bind()).get_indexes(table_name)
|
||||||
|
return any(index["name"] == index_name for index in indexes)
|
||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
|
if not _has_table("marketplace_skills"):
|
||||||
op.create_table(
|
op.create_table(
|
||||||
"marketplace_skills",
|
"marketplace_skills",
|
||||||
sa.Column("id", sa.Uuid(), nullable=False),
|
sa.Column("id", sa.Uuid(), nullable=False),
|
||||||
@@ -40,12 +52,17 @@ def upgrade() -> None:
|
|||||||
name="uq_marketplace_skills_org_source_url",
|
name="uq_marketplace_skills_org_source_url",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
marketplace_org_idx = op.f("ix_marketplace_skills_organization_id")
|
||||||
|
if not _has_index("marketplace_skills", marketplace_org_idx):
|
||||||
op.create_index(
|
op.create_index(
|
||||||
op.f("ix_marketplace_skills_organization_id"),
|
marketplace_org_idx,
|
||||||
"marketplace_skills",
|
"marketplace_skills",
|
||||||
["organization_id"],
|
["organization_id"],
|
||||||
unique=False,
|
unique=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not _has_table("gateway_installed_skills"):
|
||||||
op.create_table(
|
op.create_table(
|
||||||
"gateway_installed_skills",
|
"gateway_installed_skills",
|
||||||
sa.Column("id", sa.Uuid(), nullable=False),
|
sa.Column("id", sa.Uuid(), nullable=False),
|
||||||
@@ -68,14 +85,20 @@ def upgrade() -> None:
|
|||||||
name="uq_gateway_installed_skills_gateway_id_skill_id",
|
name="uq_gateway_installed_skills_gateway_id_skill_id",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
gateway_id_idx = op.f("ix_gateway_installed_skills_gateway_id")
|
||||||
|
if not _has_index("gateway_installed_skills", gateway_id_idx):
|
||||||
op.create_index(
|
op.create_index(
|
||||||
op.f("ix_gateway_installed_skills_gateway_id"),
|
gateway_id_idx,
|
||||||
"gateway_installed_skills",
|
"gateway_installed_skills",
|
||||||
["gateway_id"],
|
["gateway_id"],
|
||||||
unique=False,
|
unique=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
gateway_skill_idx = op.f("ix_gateway_installed_skills_skill_id")
|
||||||
|
if not _has_index("gateway_installed_skills", gateway_skill_idx):
|
||||||
op.create_index(
|
op.create_index(
|
||||||
op.f("ix_gateway_installed_skills_skill_id"),
|
gateway_skill_idx,
|
||||||
"gateway_installed_skills",
|
"gateway_installed_skills",
|
||||||
["skill_id"],
|
["skill_id"],
|
||||||
unique=False,
|
unique=False,
|
||||||
@@ -83,17 +106,29 @@ def upgrade() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
def downgrade() -> None:
|
||||||
|
gateway_skill_idx = op.f("ix_gateway_installed_skills_skill_id")
|
||||||
|
if _has_index("gateway_installed_skills", gateway_skill_idx):
|
||||||
op.drop_index(
|
op.drop_index(
|
||||||
op.f("ix_gateway_installed_skills_skill_id"),
|
gateway_skill_idx,
|
||||||
table_name="gateway_installed_skills",
|
table_name="gateway_installed_skills",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
gateway_id_idx = op.f("ix_gateway_installed_skills_gateway_id")
|
||||||
|
if _has_index("gateway_installed_skills", gateway_id_idx):
|
||||||
op.drop_index(
|
op.drop_index(
|
||||||
op.f("ix_gateway_installed_skills_gateway_id"),
|
gateway_id_idx,
|
||||||
table_name="gateway_installed_skills",
|
table_name="gateway_installed_skills",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if _has_table("gateway_installed_skills"):
|
||||||
op.drop_table("gateway_installed_skills")
|
op.drop_table("gateway_installed_skills")
|
||||||
|
|
||||||
|
marketplace_org_idx = op.f("ix_marketplace_skills_organization_id")
|
||||||
|
if _has_index("marketplace_skills", marketplace_org_idx):
|
||||||
op.drop_index(
|
op.drop_index(
|
||||||
op.f("ix_marketplace_skills_organization_id"),
|
marketplace_org_idx,
|
||||||
table_name="marketplace_skills",
|
table_name="marketplace_skills",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if _has_table("marketplace_skills"):
|
||||||
op.drop_table("marketplace_skills")
|
op.drop_table("marketplace_skills")
|
||||||
|
|||||||
Reference in New Issue
Block a user