Skip to content

fix(pg-delta): order leading enum value additions#313

Open
pjpjq wants to merge 1 commit into
supabase:mainfrom
pjpjq:codex/fix-leading-enum-values
Open

fix(pg-delta): order leading enum value additions#313
pjpjq wants to merge 1 commit into
supabase:mainfrom
pjpjq:codex/fix-leading-enum-values

Conversation

@pjpjq

@pjpjq pjpjq commented Jun 26, 2026

Copy link
Copy Markdown

Summary

Fixes #304.

  • schedule pending enum label additions until an adjacent label already exists in the simulated working enum
  • emit leading inserted runs from right to left, e.g. b BEFORE c then a BEFORE b
  • keep existing middle/edge addition behavior covered with regression controls

RED evidence

Before the fix:

  • enum.diff produced a BEFORE b before b existed for source ('c') -> target ('a','b','c')
  • the new PG17 integration regression failed with 22023: "b" is not an existing enum label

Validation

  • bun run --cwd packages/pg-delta test src/core/objects/type/enum/enum.diff.test.ts
  • PGDELTA_SKIP_DUMMY_SECLABEL_BUILD=1 PGDELTA_TEST_POSTGRES_VERSIONS=17 TESTCONTAINERS_RYUK_DISABLED=true bun run --cwd packages/pg-delta test --retry=0 --test-name-pattern "add multiple leading enum values before the first existing value" tests/integration/type-operations.test.ts
  • PGDELTA_SKIP_DUMMY_SECLABEL_BUILD=1 PGDELTA_TEST_POSTGRES_VERSIONS=17 TESTCONTAINERS_RYUK_DISABLED=true bun run --cwd packages/pg-delta test --retry=0 tests/integration/type-operations.test.ts
  • bun run format-and-lint
  • bun run check-types
  • bun run knip

Note: I also attempted PGDELTA_SKIP_DUMMY_SECLABEL_BUILD=1 PGDELTA_TEST_POSTGRES_VERSIONS=17 TESTCONTAINERS_RYUK_DISABLED=true bun run test:pg-delta; it hit unrelated local Testcontainers/Postgres connection timeouts in non-enum integration files, so I stopped it after confirming the targeted enum coverage and project checks above.

@changeset-bot

changeset-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a06f8da

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@supabase/pg-delta Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

RED: the new enum.diff unit test produced ADD 'a' BEFORE 'b' before b existed, and the new PG17 integration test failed with 22023: "b" is not an existing enum label.\n\nGREEN: the planner now only emits enum ADD VALUE statements whose BEFORE/AFTER anchors are already present in the simulated working label list.
@pjpjq
pjpjq force-pushed the codex/fix-leading-enum-values branch from 1a65f76 to a06f8da Compare July 23, 2026 10:27
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.

pg-delta: multiple leading enum values generate ADD VALUE before a non-existent label

1 participant