web / lib/jobs/utils/bulk-event-insert
lib/jobs/utils/bulk-event-insert
Bulk INSERT utility for event creation during imports.
Uses Drizzle’s typed table API (payload-generated-schema) to insert
events directly into PostgreSQL, bypassing Payload hooks for throughput.
Also populates the _events_v versions table to keep Payload’s
draft/publish system consistent.
Only used by the import pipeline where hooks are redundant (quota and access fields are handled at the job level).
Interfaces
BulkEventData
Shape of a single event to be bulk-inserted.
Maps 1:1 to the output of createEventData plus the denormalized access fields that the import job pre-computes once.
Properties
dataset
dataset:
number
ingestJob?
optionalingestJob?:number
originalData
originalData:
Record<string,unknown>
uniqueId
uniqueId:
string
eventTimestamp
eventTimestamp:
string
location?
optionallocation?:object
latitude
latitude:
number
longitude
longitude:
number
locationName?
optionallocationName?:string|null
coordinateSource
coordinateSource:
object
type
type:
string
confidence?
optionalconfidence?:number
normalizedAddress?
optionalnormalizedAddress?:string
validationStatus
validationStatus:
string
transformations?
optionaltransformations?:unknown
schemaVersionNumber?
optionalschemaVersionNumber?:number
contentHash?
optionalcontentHash?:string
datasetIsPublic?
optionaldatasetIsPublic?:boolean
catalogOwnerId?
optionalcatalogOwnerId?:number
Functions
bulkInsertEvents()
bulkInsertEvents(
payload,allEvents):Promise<number>
Bulk-insert events into the events and _events_v tables,
bypassing Payload hooks.
Splits the input into batches of BATCH_SIZE rows and executes
typed Drizzle INSERT statements. This is orders of magnitude faster
than calling payload.create() per row.
Parameters
payload
BasePayload
allEvents
Returns
Promise<number>
The total number of inserted rows.