Skip to content

Commit 0128eed

Browse files
r1tsuuDanRibbens
andauthored
fix(drizzle)!: make radio and select column names to snake_case (#8439)
Fixes #8402 and #8027 Before DB column names were camelCase: ![image](https://github.com/user-attachments/assets/d2965bcf-290a-4f86-9bf4-dfe7e8613934) After this change, they are snake_case: ![Screenshot 2024-10-04 114226](https://github.com/user-attachments/assets/bbc8c20b-6745-4dd3-b0c8-56263a4e37b1) #### Breaking SQLite / Postgres ⚠️ If you had any select (not `hasMany: true`) or radio fields with the name in camelCase, for example: ```ts { name: 'selectReadOnly', type: 'select', admin: { readOnly: true, }, options: [ { label: 'Value One', value: 'one', }, { label: 'Value Two', value: 'two', }, ], }, ``` This previously was mapped to the db column name `"selectReadOnly"`. Now it's `select_read_only`. Generate a new migration to rename your columns. ```sh pnpm payload migrate:create ``` Then select "rename column" for targeted columns and Drizzle will handle the migration. --------- Co-authored-by: Dan Ribbens <dan.ribbens@gmail.com>
1 parent 414030e commit 0128eed

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

packages/db-sqlite/src/schema/traverseFields.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,12 @@ export const traverseFields = ({
329329
}),
330330
)
331331
} else {
332-
targetTable[fieldName] = withDefault(text(fieldName, { enum: options }), field)
332+
targetTable[fieldName] = withDefault(
333+
text(columnName, {
334+
enum: options,
335+
}),
336+
field,
337+
)
333338
}
334339
break
335340
}

packages/drizzle/src/postgres/schema/traverseFields.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ export const traverseFields = ({
349349
}),
350350
)
351351
} else {
352-
targetTable[fieldName] = withDefault(adapter.enums[enumName](fieldName), field)
352+
targetTable[fieldName] = withDefault(adapter.enums[enumName](columnName), field)
353353
}
354354
break
355355
}

0 commit comments

Comments
 (0)