fix: recreate ai_provider_type instead of ADD VALUE#25895
Merged
Conversation
… ADD VALUE Coder runs all migrations in a single transaction (pgTxnDriver). Postgres forbids using an enum value added by ALTER TYPE ... ADD VALUE within the same transaction that added it. Migration 000499 widened ai_provider_type with ADD VALUE, and 000504 casts existing chat_providers rows to that enum in the same transaction. On deployments with a legacy provider using one of the new values (for example openai-compat), the batch failed with "unsafe use of new value" and the server could not start. Recreate the type (create a new enum, alter the column, drop and rename) instead of using ADD VALUE. A freshly created enum's values are usable immediately in the same transaction, so the cast in 000504 succeeds. The resulting schema is identical, so make gen produces no dump.sql diff. Add a regression test that seeds an openai-compat provider and applies 000499 through 000504 in a single transaction, reproducing the production path that the per-step Stepper used by the other tests cannot surface. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
ibetitsmike
approved these changes
Jun 1, 2026
ibetitsmike
reviewed
Jun 1, 2026
Signed-off-by: Danny Kopping <danny@coder.com>
ai_provider_type instead of ADD VALUE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Coder runs all migrations in a single transaction (
pgTxnDriver). Postgres forbids using an enum value added byALTER TYPE ... ADD VALUEwithin the same transaction that added it. Migration000499widenedai_provider_typewithADD VALUE, and000504casts existingchat_providersrows to that enum in the same transaction. On deployments with a legacy provider using one of the new values (for exampleopenai-compat), the batch failed withunsafe use of new valueand the server could not start.Recreate the type (create a new enum, alter the column, drop and rename) instead of using
ADD VALUE, matching the existing precedent in000144_user_status_dormant. A freshly created enum's values are usable immediately in the same transaction, so the cast in000504succeeds. The resulting schema is identical, somake genproduces nodump.sqldiff and databases that already applied these migrations see no drift.Added a regression test that seeds an
openai-compatprovider and applies000499through000504in a single transaction, reproducing the production path. The per-stepStepperused by the other migration tests commits each migration separately and cannot surface this class of bug.🤖 Generated with Claude Code