Skip to content

Commit 910d274

Browse files
authored
feat(drizzle): include collection and global slugs in validation errors (#15147)
Unique constraint `ValidationError`s now include `data.collection` or `data.global` for better error context. **Changes:** - Added optional `collectionSlug` and `globalSlug` parameters to `upsertRow` - Passed slugs through to `handleUpsertError` → `ValidationError` - Updated all callers: `create`, `updateOne`, `updateMany`, `updateJobs`, `createGlobal`, `updateGlobal`, `createVersion`, `updateVersion`, `createGlobalVersion`, `updateGlobalVersion`, `fetchAndResave` - Updated test to verify `error.data.collection` is populated
1 parent c103667 commit 910d274

File tree

15 files changed

+39
-4
lines changed

15 files changed

+39
-4
lines changed

packages/drizzle/src/create.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const create: Create = async function create(
1919

2020
const result = await upsertRow({
2121
adapter: this,
22+
collectionSlug,
2223
data,
2324
db,
2425
fields: collection.flattenedFields,

packages/drizzle/src/createGlobal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export async function createGlobal<T extends Record<string, unknown>>(
2424
data,
2525
db,
2626
fields: globalConfig.flattenedFields,
27+
globalSlug: slug,
2728
ignoreResult: returning === false,
2829
operation: 'create',
2930
req,

packages/drizzle/src/createGlobalVersion.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export async function createGlobalVersion<T extends JsonObject = JsonObject>(
4444
},
4545
db,
4646
fields: buildVersionGlobalFields(this.payload.config, global, true),
47+
globalSlug,
4748
ignoreResult: returning === false ? 'idOnly' : false,
4849
operation: 'create',
4950
req,

packages/drizzle/src/createVersion.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export async function createVersion<T extends JsonObject = JsonObject>(
5656

5757
const result = await upsertRow<TypeWithVersion<T>>({
5858
adapter: this,
59+
collectionSlug,
5960
data,
6061
db,
6162
fields: buildVersionCollectionFields(this.payload.config, collection, true),

packages/drizzle/src/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export const fetchAndResave = async ({
6666
await upsertRow({
6767
id: doc.id,
6868
adapter,
69+
collectionSlug,
6970
data: doc,
7071
db,
7172
fields,
@@ -115,6 +116,7 @@ export const fetchAndResave = async ({
115116
await upsertRow({
116117
id: doc.id,
117118
adapter,
119+
collectionSlug,
118120
data: doc,
119121
db,
120122
fields,
@@ -174,6 +176,7 @@ export const fetchAndResave = async ({
174176
data: doc,
175177
db,
176178
fields,
179+
globalSlug,
177180
ignoreResult: true,
178181
operation: 'update',
179182
req,
@@ -214,6 +217,7 @@ export const fetchAndResave = async ({
214217
data: doc,
215218
db,
216219
fields,
220+
globalSlug,
217221
ignoreResult: true,
218222
operation: 'update',
219223
req,

packages/drizzle/src/updateGlobal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export async function updateGlobal<T extends Record<string, unknown>>(
2323
data,
2424
db,
2525
fields: globalConfig.flattenedFields,
26+
globalSlug: slug,
2627
ignoreResult: returning === false,
2728
req,
2829
select,

packages/drizzle/src/updateGlobalVersion.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export async function updateGlobalVersion<T extends JsonObject = JsonObject>(
5454
data: versionData,
5555
db,
5656
fields,
57+
globalSlug: global,
5758
ignoreResult: returning === false,
5859
operation: 'update',
5960
req,

packages/drizzle/src/updateJobs.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const updateJobs: UpdateJobs = async function updateMany(
3838
const result = await upsertRow({
3939
id,
4040
adapter: this,
41+
collectionSlug: 'payload-jobs',
4142
data,
4243
db,
4344
fields: collection.flattenedFields,
@@ -81,6 +82,7 @@ export const updateJobs: UpdateJobs = async function updateMany(
8182
const result = await upsertRow({
8283
id: job.id,
8384
adapter: this,
85+
collectionSlug: 'payload-jobs',
8486
data: updateData,
8587
db,
8688
fields: collection.flattenedFields,

packages/drizzle/src/updateMany.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export const updateMany: UpdateMany = async function updateMany(
8989
const result = await upsertRow({
9090
id: idToUpdate,
9191
adapter: this,
92+
collectionSlug,
9293
data,
9394
db,
9495
fields: collection.flattenedFields,

packages/drizzle/src/updateOne.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export const updateOne: UpdateOne = async function updateOne(
7878
const result = await upsertRow({
7979
id: idToUpdate,
8080
adapter: this,
81+
collectionSlug,
8182
data,
8283
db,
8384
fields: collection.flattenedFields,

0 commit comments

Comments
 (0)