From e9a6b9fe42bc0143ec06564a6b61c2dce0ce501e Mon Sep 17 00:00:00 2001 From: manshusainishab Date: Mon, 20 Jul 2026 16:03:23 +0530 Subject: [PATCH] fix(migrations): stop 7bf4eac76958 renaming link constraints to a shared uq_pair --- .../7bf4eac76958_add_rule_id_column.py | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/migrations/versions/7bf4eac76958_add_rule_id_column.py b/migrations/versions/7bf4eac76958_add_rule_id_column.py index 9a12ccd49..f97545028 100644 --- a/migrations/versions/7bf4eac76958_add_rule_id_column.py +++ b/migrations/versions/7bf4eac76958_add_rule_id_column.py @@ -19,14 +19,14 @@ def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table("cre_links", schema=None) as batch_op: - batch_op.drop_constraint("uq_cre_link_pair", type_="unique") - batch_op.create_unique_constraint("uq_pair", ["group", "cre"]) - - with op.batch_alter_table("cre_node_links", schema=None) as batch_op: - batch_op.drop_constraint("uq_cre_node_link_pair", type_="unique") - batch_op.create_unique_constraint("uq_pair", ["cre", "node"]) - + # NOTE: the original auto-generated diff also renamed the unique constraints + # on cre_links (uq_cre_link_pair) and cre_node_links (uq_cre_node_link_pair) + # to a shared name "uq_pair". On PostgreSQL a UNIQUE constraint creates a + # schema-global index, so two "uq_pair" indexes on two tables collide + # ("relation uq_pair already exists") and break a from-empty + # `flask db upgrade`. Those renames are removed: the preceding migration + # (0d267ae11945) already creates the table-specific constraints and the + # models keep those names, so we preserve them here. with op.batch_alter_table("node", schema=None) as batch_op: batch_op.add_column(sa.Column("section_id", sa.String(), nullable=True)) batch_op.drop_constraint("uq_node", type_="unique") @@ -56,12 +56,4 @@ def downgrade(): ) batch_op.drop_column("section_id") - with op.batch_alter_table("cre_node_links", schema=None) as batch_op: - batch_op.drop_constraint("uq_pair", type_="unique") - batch_op.create_unique_constraint("uq_cre_node_link_pair", ["cre", "node"]) - - with op.batch_alter_table("cre_links", schema=None) as batch_op: - batch_op.drop_constraint("uq_pair", type_="unique") - batch_op.create_unique_constraint("uq_cre_link_pair", ["group", "cre"]) - # ### end Alembic commands ###