ordinality
Version:
Universal migrations tools
51 lines (50 loc) • 1.65 kB
TypeScript
import type { Migration, MigrationContext } from './Migration';
import type { MigrationStorage } from './storage/MigrationStorage';
export type Range<K extends string> = {
/**
* Name of migration or its index
*/
to: K | number;
} | {
/**
* Number of next migrations to select related to current
*/
step: number;
};
export declare const findMigrationIndexByRange: <T extends string = string>({ range, items, currentIndex, direction, }: {
range: Range<T>;
items: string[];
currentIndex: number;
direction: 'backward' | 'forward';
}) => number | null;
export declare class MigrationRunner<Context = void, Meta extends Record<any, any> | void = void> {
protected readonly config: {
migrations: Migration<Context, Meta>[];
storage: MigrationStorage<MigrationContext<Context, Meta>>;
} & (void extends Context ? {
context?: Context;
} : {
context: Context;
});
constructor(config: {
migrations: Migration<Context, Meta>[];
storage: MigrationStorage<MigrationContext<Context, Meta>>;
} & (void extends Context ? {
context?: Context;
} : {
context: Context;
}));
private getState;
executed(): Promise<string[]>;
pending(): Promise<string[]>;
/**
* Executes migrations and returns list with ids of applied migrations
*/
up(range?: Range<string>): Promise<string[]>;
/**
* Roll back migrations and returns list with ids of reverted migrations
*
* Throw error in case migration cannot be reverted
*/
down(range?: Range<string>): Promise<string[]>;
}