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

Function generate

packages/migrations-mongodb/src/MigrationGenerator.ts:20–33  ·  view source on GitHub ↗

* @inheritDoc

(diff: { up: string[]; down: string[] }, path?: string, name?: string)

Source from the content-addressed store, hash-verified

18 * @inheritDoc
19 */
20 async generate(diff: { up: string[]; down: string[] }, path?: string, name?: string): Promise<[string, string]> {
21 const { fs } = await import('@mikro-orm/core/fs-utils');
22 /* v8 ignore next */
23 const defaultPath = this.options.emit === 'ts' && this.options.pathTs ? this.options.pathTs : this.options.path!;
24 path = fs.normalizePath(this.driver.config.get('baseDir'), path ?? defaultPath);
25 fs.ensureDir(path);
26 const timestamp = new Date().toISOString().replace(/[-T:]|\.\d{3}z$/gi, '');
27 const className = this.namingStrategy.classToMigrationName(timestamp, name);
28 const fileName = `${this.options.fileName!(timestamp, name)}.${this.options.emit}`;
29 const ret = await this.generateMigrationFile(className, diff);
30 await fs.writeFile(path + '/' + fileName, ret, { flush: true });
31
32 return [ret, fileName];
33 }
34
35 /** @inheritDoc */
36 /* v8 ignore next */

Callers

nothing calls this directly

Calls 6

normalizePathMethod · 0.80
ensureDirMethod · 0.80
classToMigrationNameMethod · 0.80
writeFileMethod · 0.80
getMethod · 0.65
generateMigrationFileMethod · 0.65

Tested by

no test coverage detected