Skip to content

fix: recreate ai_provider_type instead of ADD VALUE#25895

Merged
dannykopping merged 2 commits into
mainfrom
dk/migration-fix
Jun 1, 2026
Merged

fix: recreate ai_provider_type instead of ADD VALUE#25895
dannykopping merged 2 commits into
mainfrom
dk/migration-fix

Conversation

@dannykopping
Copy link
Copy Markdown
Contributor

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, matching the existing precedent in 000144_user_status_dormant. 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 and databases that already applied these migrations see no drift.

Added a regression test that seeds an openai-compat provider and applies 000499 through 000504 in a single transaction, reproducing the production path. The per-step Stepper used by the other migration tests commits each migration separately and cannot surface this class of bug.

🤖 Generated with Claude Code

… 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>
Signed-off-by: Danny Kopping <danny@coder.com>
@dannykopping dannykopping changed the title fix(coderd/database/migrations): recreate ai_provider_type instead of ADD VALUE fix: recreate ai_provider_type instead of ADD VALUE Jun 1, 2026
@dannykopping dannykopping marked this pull request as ready for review June 1, 2026 13:19
@dannykopping dannykopping enabled auto-merge (squash) June 1, 2026 13:19
@dannykopping dannykopping merged commit 85f56e4 into main Jun 1, 2026
45 of 46 checks passed
@dannykopping dannykopping deleted the dk/migration-fix branch June 1, 2026 13:30
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants