Skip to content

Commit

Permalink
fix: update data connectors migrations (#443)
Browse files Browse the repository at this point in the history
Fixes two issues with the migrations for data connectors:
1.  The migrations cannot be rolled back after creating a data connector. This was caused by leftover entries in the `entity_slugs` table.
2. The entity slug constraint was not created. The change was not picked up by Alembic; it seems Alembic can only handle `CheckConstraint` creation together with table creation, but not new constraints on an existing table, updates to them, or removing them from a table.
  • Loading branch information
leafty authored Oct 7, 2024
1 parent f3a5f98 commit d8c7b05
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ def upgrade() -> None:
referent_schema="storage",
ondelete="CASCADE",
)
op.create_check_constraint(
"either_project_id_or_data_connector_id_is_set",
"entity_slugs",
"CAST (project_id IS NOT NULL AS int) + CAST (data_connector_id IS NOT NULL AS int) BETWEEN 0 AND 1",
schema="common",
)
op.create_table(
"data_connector_secrets",
sa.Column("user_id", sa.String(length=36), nullable=False),
Expand Down Expand Up @@ -135,6 +141,8 @@ def downgrade() -> None:
schema="storage",
)
op.drop_table("data_connector_secrets", schema="storage")
op.drop_constraint("either_project_id_or_data_connector_id_is_set", "entity_slugs", schema="common", type_="check")
op.execute("DELETE FROM common.entity_slugs WHERE entity_slugs.data_connector_id IS NOT NULL")
op.drop_constraint("entity_slugs_data_connector_id_fk", "entity_slugs", schema="common", type_="foreignkey")
op.drop_index(op.f("ix_common_entity_slugs_data_connector_id"), table_name="entity_slugs", schema="common")
op.alter_column("entity_slugs", "project_id", existing_type=sa.String(length=26), nullable=False, schema="common")
Expand Down

0 comments on commit d8c7b05

Please sign in to comment.