Parameters
- pool: Pool
Optionaloptions: {
eventStore?: boolean;
lockTimeout?: Duration;
projections?: readonly Pick<
Readonly<
{
"~types"?: { event: Event; state: unknown };
eventTypes: readonly string[];
isSingleStream: boolean;
kind: "document";
mode: ProjectionMode;
name: string;
canHandle(event: { type: string }): boolean;
evolve(state: unknown, event: RecordedEvent<E>): unknown;
getDocumentId(event: RecordedEvent<E>): string;
initialState(): unknown;
},
>,
"name"
| "isSingleStream",
>[];
}
-
OptionaleventStore?: boolean
-
OptionallockTimeout?: Duration
-
Optionalprojections?: readonly Pick<
Readonly<
{
"~types"?: { event: Event; state: unknown };
eventTypes: readonly string[];
isSingleStream: boolean;
kind: "document";
mode: ProjectionMode;
name: string;
canHandle(event: { type: string }): boolean;
evolve(state: unknown, event: RecordedEvent<E>): unknown;
getDocumentId(event: RecordedEvent<E>): string;
initialState(): unknown;
},
>,
"name"
| "isSingleStream",
>[]
Returns Promise<number[]>
The versions of the outbox that this call applied
Creates or updates the Hermes tables:
hermes_outbox,hermes_outbox_partitionandhermes_migrations, which keeps the versions that were applied.Many instances of the application can run it at the same time: they wait for each other on a named lock (
GET_LOCK) of the database, and every migration runs once. A statement waits for the lock of a table at most 5 seconds (lock_wait_timeout), because the waiting statement stops the queries of the application on that table, and then tries again a moment later, up to about a minute. The migrations are safe to run again, so a statement can be repeated. The connection gets its ownlock_wait_timeoutback afterwards.createOutboxConsumerruns it onstart(). Call it yourself when you turn that off (migrate: false), e.g. in a deployment pipeline with a user that can change the schema.With
eventStore, it also creates the tables of the event store (hermes_streams,hermes_events,hermes_subscriptions,hermes_dead_letters), whose versions are kept apart inhermes_event_store_migrations. The event store is opt-in, so an application that uses only the outbox does not get its tables. Withprojections, it also creates the missing tables of those projections (see projectionTable); it never changes existing ones.