/** * Adapter determines where executed migration names will be stored and what will be * passed to `migrate` and `rollback` function as a parameter. */ export interface Adapter
{ /** * Returns the client that is passed as a parameter to `migrate()` and `rollback()`. */ connect(): Promise
;
/**
* Releases the resources (if any) allocated by the adapter internally.
*/
disconnect(): Promise extends MigratorParams {
/**
* Adapter constructor is invoked only when the property `adapter` of `MigratorParams`
* is a string that is the path leading to the adapter module itself.
*/
adapter: string;
/**
* Any other additional parameters that are required by the adapter.
* The adapter should check their presense and validity by himself.
*/
[additionalParams: string]: unknown;
}
/**
* Creates an instance of `Adapter` passing the config object (that will also
* contain properties from `.eastrc` if not overriden in code).
*/
export type AdapterConstructor = new (params: AdapterConstructorParams ) => Adapter ;
export interface MigratorParams {
/**
* Path to migration executable scripts dir.
*
* Default: `"./migrations"`
*/
dir: string;
/**
* Path to the adapter to require or the `AdpaterConstructor` itself.
*
* Default: path to the builtin adapter that stores executed migration names
* at file `.migrations` in dir which is located at `dir` and passes `null`
* to `migrate()/rollback()`
*/
adapter: string | AdapterConstructor ;
/**
* File extension of migrations at `dir` (without the leading dot, e.g. `"js"`, `"ts"`)
*
* Default: `"js"`
*/
migrationExtension: string;
/**
* Dir with migration source files (for transpiled languages e.g. ts)
*
* Default: the same as `dir`
*/
sourceDir: string;
/**
* File extension of migrations at `sourceDir` (without the leading dot, e.g. `"js"`, `"ts"`)
*
* Default: the same as `migrationExtension`
*/
sourceMigrationExtension: string;
/**
* Execution timeout in milliseconds.
*
* Default: one week (unreal)
*/
timeout: number;
/**
* Database url. This is not used by `east` itself, it is just passed to the
* adapter and only the adapter determines what to do with it. By convention,
* adapters * should use `url` for passing the target database cluster domain
* endpoint.
*
* Default: `null`
*/
url: null | string;
/**
* Numbering format for migration file names.
*
* Default: `"sequentialNumber"`
*/
migrationNumberFormat: MigrationNumberFormat;
/**
* Whether to turn on verbose mode (includes error stack trace).
*
* Default: `false`
*/
trace: boolean;
/**
* Whether to load the `config` file. Its contents will be merged with
* these parameters, though if some parameters passed here also appear
* in `config` file, the former will take precedence.
*
* Default: `true`
*/
loadConfig: boolean;
/**
* Path to the config file. This may be a `json` file or a `js` file that
* exports the config object as `module.exports`.
*
* Default: `"./.eastrc"`
*/
config: string;
/**
* Path to the template file for new migrations.
*
* Default: builtin `"js"` or `"ts"` template according to `sourceMigrationExtension`
*/
template: string;
/**
* Array of paths to plugin modules or plugin objects themselves.
* `module.exports` of the plugin module should conform to `Plugin` interface.
*
* Default: `undefined`
*/
plugins?: (string | Plugin )[];
/**
* Whether to load config, migrations, adapter and plugins using import
* expression. It allows to provide those entities like commonjs or es
* modules.
*
* Default: `false`
*/
esModules: boolean;
}
export interface Plugin {
register(params: RegisterPluginParams ): Promise {
migratorParams: MigratorParams ;
migratorHooks: Hooks ;
}
export interface OkHookParams {
migrationName: string;
/**
* Parameter value that is passed to `migrate(param: P)/rollback(param: P)`
*/
migrationParams: P;
}
export interface ErrHookParams extends OkHookParams {
error: unknown;
}
type OkHook = (params: OkHookParams ) => void;
type ErrHook = (params: ErrHookParams ) => void;
export interface Hooks {
on(event: 'beforeMigrate', listener: OkHook ): this;
on(event: 'afterMigrate', listener: OkHook ): this;
on(event: 'migrateError', listener: ErrHook ): this;
on(event: 'beforeRollback', listener: OkHook ): this;
on(event: 'afterRollback', listener: OkHook ): this;
on(event: 'rollbackError', listener: ErrHook ): this;
}
/**
* The default format for migration file names is to prepend a number to the filename
* which is incremented with every new file.
* This creates migration files such as
* - `migrations/1_doSomething.js`,
* - `migrations/2_doSomethingElse.js`.
*
* If you prefer your files to be created with a date time instead of sequential numbers,
* you can choose the `dateTime` format.
* This will create migration files with date time prefix in `YYYYMMDDhhmmss` format such as
* - `migrations/20190720172730_doSomething.js`
*/
export type MigrationNumberFormat = "sequentialNumber" | "dateTime";
/**
* Parameters for the default builtin adapter that stores the migration state in
* a file on the local filesystem.
*/
export interface FileStorageAdapterParams {
/**
* Path to the file where the migration state is stored.
*
* Default: `"${dir}/.migrations"`
*/
migrationsFile?: string;
}
export interface CreateResult {
/**
* Name of the migration that was created. Doesn't include the file
* extension. It has the following format: ` {
/**
* Configures migration process (dir, adapter, etc). Merges `params` with loaded config
* (when `loadConfig` param is truthy - `true` by default).
* This method should be called before any other methods.
*/
configure(params: Partial