Skip to content

Postgres column name for select fields are not snake_case #8027

@willviles

Description

@willviles

Link to reproduction

No response

Environment Info

Binaries:
  Node: 18.20.2
  npm: 10.5.0
  Yarn: N/A
  pnpm: 9.1.0
Relevant Packages:
  payload: 3.0.0-beta.97
  next: 15.0.0-canary.104
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.5.0: Wed May  1 20:13:18 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6030
  Available memory (MB): 36864
  Available CPU cores: 12

Describe the Bug

Postgres column names for select fields are not converted to snake case, unlike all other fields.

For example, an input field with the name fooBar will result in a pg column name of foo_bar.
However, a select field named fooBar will create a column called fooBar.

The offending logic may be here, where the fieldName argument should instead be columnName:

targetTable[fieldName] = withDefault(adapter.enums[enumName](fieldName), field)

Reproduction Steps

  1. Configure the Postgres db adapter
  2. Create a collection (e.g. Foo)
  3. Create an input field with a camelCase name (e.g. fooInput)
  4. Create a select field with a camelCase name (e.g. fooSelect)
  5. Run payload migrate:create
  6. Open the migration output file.

Expected output:

CREATE TABLE IF NOT EXISTS "foos" (
  "foo_input" varchar,
  "foo_select" "enum_foos_foo_select",
);

Actual output:

CREATE TABLE IF NOT EXISTS "foos" (
  "foo_input" varchar,
  "fooSelect" "enum_foos_foo_select",
);

Adapters and Plugins

db-postgres

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions