Skip to content

hotfix: reset model_config sequence before seeding in migration 063#883

Merged
vprashrex merged 1 commit into
mainfrom
hotfix/migration-063-sequence-reset
May 25, 2026
Merged

hotfix: reset model_config sequence before seeding in migration 063#883
vprashrex merged 1 commit into
mainfrom
hotfix/migration-063-sequence-reset

Conversation

@vprashrex
Copy link
Copy Markdown
Collaborator

@vprashrex vprashrex commented May 25, 2026

Target issue is #884

Summary

Fixes #884. Migration 063 failed on staging because the model_config id sequence was behind the actual max id in the DB. Auto-generated ids during the INSERT collided with existing rows, causing UniqueViolation on model_config_pkey. Fix resets the sequence to max(id) before seeding so new rows get non-conflicting ids.

Checklist

Before submitting a pull request, please ensure that you mark these task.

  • Ran fastapi run --reload app/main.py or docker compose up in the repository root and test.
  • If you've fixed a bug or added code that is tested and has test cases.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 25, 2026

📝 Walkthrough

Walkthrough

Migration 063 is fixed to prevent duplicate key violations by adding a sequence synchronization step. After creating model-config indexes, the migration resets the global.model_config.id sequence to the current maximum ID, ensuring subsequent inserts use non-colliding auto-generated IDs.

Changes

Migration 063: Sequence Synchronization

Layer / File(s) Summary
Sequence reset after index creation
backend/app/alembic/versions/063_seed_stt_tts_model_configs.py
After creating the GIN index on output_modalities, the upgrade adds op.execute() to reset the id sequence to MAX(id) via setval(pg_get_serial_sequence(...), MAX(id)), preventing primary key conflicts during the subsequent model_config insert.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A sequence once lost in the database night,
Found its way back to the ID light,
With setval and MAX, the fix is done,
No more collisions—migration won! 🌟

🚥 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 clearly summarizes the main change: resetting the model_config sequence before seeding in migration 063, which directly addresses the key issue.
Linked Issues check ✅ Passed The changes implement the fix described in issue #884 by adding a setval() call to reset the sequence to max(id) before INSERT, directly resolving the primary key conflict.
Out of Scope Changes check ✅ Passed All changes are focused on the sequence reset fix for migration 063; no unrelated modifications are present outside the stated objective.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hotfix/migration-063-sequence-reset

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 and usage tips.

@vprashrex vprashrex requested a review from AkhileshNegi May 25, 2026 02:46
@vprashrex vprashrex self-assigned this May 25, 2026
@vprashrex vprashrex added the bug Something isn't working label May 25, 2026
@vprashrex vprashrex linked an issue May 25, 2026 that may be closed by this pull request
@sentry
Copy link
Copy Markdown

sentry Bot commented May 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Ayush8923 Ayush8923 removed this from Kaapi-dev May 25, 2026
@vprashrex vprashrex removed the request for review from AkhileshNegi May 25, 2026 10:06
@vprashrex vprashrex merged commit 597dfc9 into main May 25, 2026
3 checks passed
@vprashrex vprashrex deleted the hotfix/migration-063-sequence-reset branch May 25, 2026 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ready-for-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migration 063: Fix sequence reset

2 participants