MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / run

Method run

packages/migrations/src/MigrationRunner.ts:21–56  ·  view source on GitHub ↗
(
    migration: Migration,
    method: 'up' | 'down',
    afterRun?: (tx?: Transaction) => Promise<void>,
  )

Source from the content-addressed store, hash-verified

19 }
20
21 async run(
22 migration: Migration,
23 method: 'up' | 'down',
24 afterRun?: (tx?: Transaction) => Promise<void>,
25 ): Promise<void> {
26 migration.reset();
27
28 if (!this.options.transactional || !migration.isTransactional()) {
29 // Without a pinned transaction the set/reset statements may land on different pooled
30 // connections than the DDL, so refuse rather than silently running in the default schema.
31 if (this.#runSchema) {
32 throw new Error(
33 'Runtime schema (migrations.schema / migrator.up({ schema })) is only supported with transactional migrations',
34 );
35 }
36
37 const queries = await this.getQueries(migration, method);
38 await Utils.runSerial(queries, sql => this.driver.execute(sql));
39 await afterRun?.();
40 } else {
41 await this.#connection.transactional(
42 async tx => {
43 migration.setTransactionContext(tx);
44
45 try {
46 const queries = await this.getQueries(migration, method);
47 await Utils.runSerial(queries, sql => this.driver.execute(sql, undefined, 'all', tx));
48 await afterRun?.(tx);
49 } finally {
50 await this.resetSessionSchema(tx);
51 }
52 },
53 { ctx: this.#masterTransaction },
54 );
55 }
56 }
57
58 private async resetSessionSchema(ctx?: Transaction): Promise<void> {
59 if (!this.#runSchema) {

Callers

nothing calls this directly

Calls 8

getQueriesMethod · 0.95
resetSessionSchemaMethod · 0.95
runSerialMethod · 0.80
resetMethod · 0.65
isTransactionalMethod · 0.65
executeMethod · 0.65
setTransactionContextMethod · 0.65
transactionalMethod · 0.45

Tested by

no test coverage detected