Skip to content

fix(drizzle): generate the locale enum with its actual db name - #17737

Open
EugenieF wants to merge 1 commit into
payloadcms:mainfrom
EugenieF:fix/locale-enum-db-name
Open

fix(drizzle): generate the locale enum with its actual db name#17737
EugenieF wants to merge 1 commit into
payloadcms:mainfrom
EugenieF:fix/locale-enum-db-name

Conversation

@EugenieF

Copy link
Copy Markdown

Fixes #17736.

What

generate:db-schema declared the locale enum as pgEnum('enum__locales', …), but the adapter creates that type in Postgres as _localesenum__locales is only the key in the adapter's enums map:

https://github.com/payloadcms/payload/blob/main/packages/drizzle/src/postgres/init.ts#L22-L27

So every _locale column in a generated schema referenced a type that does not exist in the database. Under push: false the generated file is never executed, so nothing surfaced it.

How

addEnum() already assumed name === db name, and that holds for its only other caller — columnToCodeConverter passes column.enumName, which is a real type name. Rather than change that contract, this adds an optional dbName defaulting to name, so only the locale call site behaves differently.

The exported const keeps the name enum__locales, because columnToCodeConverter.ts#L17 emits enum__locales(…) as the column builder. Only the first argument to pgEnum changes.

Fixture

test/relationships/payload-generated-schema.ts is the one committed fixture that contained the old name; it is updated here. The other two generated-schema fixtures under test/ are not localized and contain no locale enum.

That one-line fixture change is exactly what regenerating produces — the emitted string is deterministic — but I could not run the repo's test suite locally to confirm, so CI is the real check on that file.

Verifying

Before this change, in any localized Postgres project:

SELECT DISTINCT udt_name FROM information_schema.columns
WHERE table_schema = 'public' AND column_name = '_locale';
-- _locales

SELECT typname FROM pg_type WHERE typname = 'enum__locales';
-- 0 rows

while the generated schema declared enum__locales.

generate:db-schema declared the locale enum as pgEnum('enum__locales', ...),
but postgres/init.ts creates that type as '_locales' — 'enum__locales' is only
the key in the adapter's enums map. Every _locale column in the generated
schema therefore referenced a type that does not exist in the database.

addEnum() already assumed name === db name, which holds for its only other
caller (columnToCodeConverter passes column.enumName, a real type name), so
this adds an optional dbName argument rather than changing that contract.

The exported const keeps the name enum__locales, since columnToCodeConverter
emits enum__locales(...) as the column builder.

Updates test/relationships/payload-generated-schema.ts, the one committed
fixture that contained the old name.
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.

generate:db-schema declares the locale enum as enum__locales, but the adapter creates _locales

1 participant