UNPKG

@mikro-orm/core

Version:

TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.

126 lines (125 loc) 4.64 kB
import type { Constructor, IMigrationGenerator, IMigrationRunner, IMigrator, IMigratorStorage, MaybePromise, Migration, MigrationInfo, MigrationResult, MigrationRow, MigratorEvent } from '../typings.js'; import type { Transaction } from '../connections/Connection.js'; import type { Configuration, MigrationsOptions } from './Configuration.js'; import type { EntityManagerType, IDatabaseDriver } from '../drivers/IDatabaseDriver.js'; interface RunnableMigration { name: string; path?: string; up: (afterRun?: (tx?: Transaction) => Promise<void>) => MaybePromise<void>; down: (afterRun?: (tx?: Transaction) => Promise<void>) => MaybePromise<void>; } type MigrateOptions = { from?: string | number; to?: string | number; migrations?: string[]; transaction?: Transaction; schema?: string; }; export declare abstract class AbstractMigrator<D extends IDatabaseDriver> implements IMigrator { #private; protected readonly em: D[typeof EntityManagerType]; protected runner: IMigrationRunner; protected storage: IMigratorStorage; protected generator: IMigrationGenerator; protected readonly driver: D; protected readonly config: Configuration; protected readonly options: MigrationsOptions; protected absolutePath: string; protected initialized: boolean; constructor(em: D[typeof EntityManagerType]); protected abstract createRunner(): IMigrationRunner; protected abstract createStorage(): IMigratorStorage; protected abstract getDefaultGenerator(): IMigrationGenerator; abstract create(path?: string, blank?: boolean, initial?: boolean, name?: string): Promise<{ fileName: string; code: string; diff: { up: string[]; down: string[]; }; }>; abstract checkSchema(): Promise<boolean>; abstract createInitial(path?: string, name?: string, blank?: boolean): Promise<{ fileName: string; code: string; diff: { up: string[]; down: string[]; }; }>; /** * @inheritDoc */ on(eventName: MigratorEvent, listener: (event: MigrationInfo) => MaybePromise<void>): this; /** * @inheritDoc */ off(eventName: MigratorEvent, listener: (event: MigrationInfo) => MaybePromise<void>): this; /** * @inheritDoc */ getExecuted(options?: { schema?: string; }): Promise<MigrationRow[]>; /** * @inheritDoc */ getPending(options?: { schema?: string; }): Promise<MigrationInfo[]>; /** * @inheritDoc */ up(options?: string | string[] | MigrateOptions): Promise<MigrationInfo[]>; /** * @inheritDoc */ down(options?: string | string[] | Omit<MigrateOptions, 'from'>): Promise<MigrationInfo[]>; /** * @inheritDoc */ rollup(migrations?: string[]): Promise<MigrationResult>; /** * Extracts the body of a method from migration source code using brace counting. * Returns the raw lines between the opening and closing braces, or empty string if not found. * @internal */ private extractMethodBody; abstract getStorage(): IMigratorStorage; /** * @inheritDoc */ logMigration(name: string): Promise<void>; /** * @inheritDoc */ unlogMigration(name: string): Promise<void>; protected init(): Promise<void>; protected initPaths(): Promise<void>; protected initServices(): void; protected resolve(params: { name: string; path: string; }): RunnableMigration; protected initialize(MigrationClass: Constructor<Migration>, name: string): RunnableMigration; /** * Checks if `src` folder exists, it so, tries to adjust the migrations and seeders paths automatically to use it. * If there is a `dist` or `build` folder, it will be used for the JS variant (`path` option), while the `src` folder will be * used for the TS variant (`pathTs` option). * * If the default folder exists (e.g. `/migrations`), the config will respect that, so this auto-detection should not * break existing projects, only help with the new ones. */ private detectSourceFolder; private registerDefaultListeners; private emit; protected discoverMigrations(): Promise<RunnableMigration[]>; private executeMigrations; private filterUp; private filterDown; private getMigrationFilename; private prefix; protected runMigrations(method: 'up' | 'down', options?: string | string[] | MigrateOptions): Promise<MigrationInfo[]>; private runInTransaction; } export {};