UNPKG

@mikro-orm/migrations

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.

30 lines (29 loc) 1.48 kB
import { type AnyEntity, type Configuration, type EntityData, type RawQueryFragment, type Transaction } from '@mikro-orm/core'; import type { AbstractSqlDriver, EntityManager, NativeQueryBuilder } from '@mikro-orm/sql'; /** A migration query: raw SQL string, a native query builder instance, or a `raw()` SQL fragment. */ export type Query = string | NativeQueryBuilder | RawQueryFragment; /** Base class for SQL database migrations. Extend this class and implement `up()` (and optionally `down()`). */ export declare abstract class Migration { #private; protected readonly driver: AbstractSqlDriver; protected readonly config: Configuration; protected ctx?: Transaction; constructor(driver: AbstractSqlDriver, config: Configuration); abstract up(): Promise<void> | void; down(): Promise<void> | void; isTransactional(): boolean; addSql(sql: Query): void; reset(): void; setTransactionContext(ctx: Transaction): void; /** * Executes a raw SQL query. Accepts a string SQL, `raw()` SQL fragment, or a native query builder instance. * The `params` parameter is respected only if you use string SQL in the first parameter. */ execute(sql: Query, params?: unknown[]): Promise<EntityData<AnyEntity>[]>; /** * Creates a cached `EntityManager` instance for this migration, which will respect * the current transaction context. */ getEntityManager(): EntityManager; getQueries(): Query[]; }