Hermes MySQL
    Preparing search index...

    Function migrate

    • Creates or updates the Hermes tables: hermes_outbox, hermes_outbox_partition and hermes_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 own lock_wait_timeout back afterwards.

      createOutboxConsumer runs it on start(). 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 in hermes_event_store_migrations. The event store is opt-in, so an application that uses only the outbox does not get its tables. With projections, it also creates the missing tables of those projections (see projectionTable); it never changes existing ones.

      Parameters

      • pool: Pool

        A mysql2 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

          Whether to create or update the tables of the event store too (default: false)

        • OptionallockTimeout?: Duration

          How long to wait for other instances that are migrating (default: 10 minutes)

        • 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",
          >[]

          The projections whose tables to create when they are missing (needs eventStore)

      Returns Promise<number[]>

      The versions of the outbox that this call applied