Skip to content

fix(migrations): stop 7bf4eac76958 renaming link constraints to a sha…#988

Open
manshusainishab wants to merge 2 commits into
OWASP:mainfrom
manshusainishab:fix-migration-uq-pair
Open

fix(migrations): stop 7bf4eac76958 renaming link constraints to a sha…#988
manshusainishab wants to merge 2 commits into
OWASP:mainfrom
manshusainishab:fix-migration-uq-pair

Conversation

@manshusainishab

Copy link
Copy Markdown
Contributor

Problem

A from-scratch flask db upgrade on PostgreSQL fails:

psycopg2.errors.DuplicateTable: relation "uq_pair" already exists
[SQL: ALTER TABLE cre_node_links ADD CONSTRAINT uq_pair UNIQUE (cre, node)]

Migration 7bf4eac76958 renames the unique constraints on both cre_links
(uq_cre_link_pair) and cre_node_links (uq_cre_node_link_pair) to the same
name uq_pair. On Postgres a UNIQUE constraint creates a schema-global index,
so the second uq_pair collides with the first — breaking any from-empty
migration on Postgres. (It slips by on SQLite, where batch_alter_table
rebuilds the table.)

Fix

Remove those two renames from 7bf4eac76958 (upgrade + downgrade). The preceding
migration 0d267ae11945 already creates the table-specific constraints, and the
SQLAlchemy models keep those names (uq_cre_link_pair / uq_cre_node_link_pair),
so we preserve them instead of collapsing both to uq_pair. The migration's
actual purpose (adding node.section_id and updating uq_node) is unchanged.

Validation

Full flask db upgrade from an empty PostgreSQL database now completes the entire
chain to head c7d8e9f0a1b2.

Note: completing the run also requires CRE_EMBED_EXPECTED_DIM to be set for the
pgvector migration (c7d8e9f0a1b2) on an empty DB — a separate, pre-existing
requirement of that migration, unrelated to this fix.

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 8b122055-8148-418e-8a96-4df5146c641b

📥 Commits

Reviewing files that changed from the base of the PR and between 2d1aa47 and e9a6b9f.

📒 Files selected for processing (1)
  • migrations/versions/7bf4eac76958_add_rule_id_column.py

Summary by CodeRabbit

  • Bug Fixes
    • Updated database migration behavior to prevent unique-constraint naming conflicts in PostgreSQL.
    • Preserved existing uniqueness protections for link records while applying related schema updates safely.

Walkthrough

Changes

Migration constraint changes

Layer / File(s) Summary
Remove link constraint renames
migrations/versions/7bf4eac76958_add_rule_id_column.py
Upgrade and downgrade no longer rename unique constraints on cre_links and cre_node_links; remaining node constraint and section_id behaviors are unchanged.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: northdpole

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: it stops migration 7bf4eac76958 from renaming link constraints to a shared name.
Description check ✅ Passed The description accurately explains the PostgreSQL migration failure and the fix to preserve table-specific constraint names.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@manshusainishab

Copy link
Copy Markdown
Contributor Author

@northdpole here is the PR with the fix as discussed I need a review and merge so I can take a fresh pull to continue with my next PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant