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

Method runMigrations

packages/migrations/src/Migrator.ts:198–235  ·  view source on GitHub ↗
(
    method: 'up' | 'down',
    options?: string | string[] | MigrateOptions,
  )

Source from the content-addressed store, hash-verified

196 }
197
198 protected override async runMigrations(
199 method: 'up' | 'down',
200 options?: string | string[] | MigrateOptions,
201 ): Promise<MigrationInfo[]> {
202 const result = await super.runMigrations(method, options);
203
204 if (result.length > 0 && this.options.snapshot) {
205 const ctx = Utils.isObject<MigrateOptions>(options) ? options.transaction : undefined;
206 const schema = await DatabaseSchema.create(
207 this.em.getConnection(),
208 this.em.getPlatform(),
209 this.config,
210 undefined,
211 undefined,
212 undefined,
213 undefined,
214 undefined,
215 ctx,
216 );
217
218 // keep the snapshot authored by `migration:create` when the migrated DB still matches it
219 // semantically — rewriting it from introspection only churns cosmetic serialization noise
220 // (expression casing/reformatting, native-enum mapped type, index method, ...) into the diff
221 const existing = await this.getSchemaFromSnapshot();
222
223 if (existing && !this.snapshotDiffers(existing, schema)) {
224 return result;
225 }
226
227 try {
228 await this.storeCurrentSchema(schema);
229 } catch {
230 // Silently ignore for read-only filesystems (production).
231 }
232 }
233
234 return result;
235 }
236
237 /** Whether the introspected schema differs from the snapshot in any way the comparator turns into SQL. */
238 private snapshotDiffers(snapshot: DatabaseSchema, schema: DatabaseSchema): boolean {

Callers 2

upFunction · 0.80
downFunction · 0.80

Calls 7

getSchemaFromSnapshotMethod · 0.95
snapshotDiffersMethod · 0.95
storeCurrentSchemaMethod · 0.95
isObjectMethod · 0.80
createMethod · 0.65
getConnectionMethod · 0.65
getPlatformMethod · 0.65

Tested by

no test coverage detected