UNPKG

ts-migrate-mongoose

Version:

A migration framework for Mongoose, built with TypeScript.

82 lines (78 loc) 2.58 kB
import { ConnectOptions, Connection, Model, HydratedDocument } from 'mongoose'; interface MigrationFile { filename: string; createdAt: Date; existsInDatabase: boolean; } interface Migration { name: string; filename: string; state: 'down' | 'up'; createdAt: Date; updatedAt: Date; } interface ConfigOptionsDefault { default?: ConfigOptions; } interface MigrationFunctions { up?: (connection: Connection) => Promise<void>; down?: (connection: Connection) => Promise<void>; } interface MigrationFunctionsDefault { default?: MigrationFunctions; } interface CommonOptions { connectOptions?: ConnectOptions; migrationsPath?: string; templatePath?: string; collection?: string; autosync?: boolean; } interface ConfigOptions extends CommonOptions { uri?: string; configPath?: string; mode?: string; } interface MigratorOptions extends CommonOptions { uri: string; cli?: boolean; } declare enum Env { MIGRATE_CONFIG_PATH = "MIGRATE_CONFIG_PATH", MIGRATE_MONGO_COLLECTION = "MIGRATE_MONGO_COLLECTION", MIGRATE_MIGRATIONS_PATH = "MIGRATE_MIGRATIONS_PATH", MIGRATE_AUTOSYNC = "MIGRATE_AUTOSYNC", MIGRATE_CLI = "MIGRATE_CLI", MIGRATE_MODE = "MIGRATE_MODE", MIGRATE_MONGO_URI = "MIGRATE_MONGO_URI", MIGRATE_TEMPLATE_PATH = "MIGRATE_TEMPLATE_PATH" } declare class Migrator { readonly migrationModel: Model<Migration>; readonly connection: Connection; private readonly uri?; private readonly template; private readonly migrationsPath; private readonly collection; private readonly autosync; private readonly cli; private constructor(); static connect(options: MigratorOptions): Promise<Migrator>; close(): Promise<void>; list(): Promise<HydratedDocument<Migration>[]>; create(migrationName: string): Promise<HydratedDocument<Migration>>; run(direction: 'up' | 'down', migrationName?: string, single?: boolean): Promise<HydratedDocument<Migration>[]>; sync(): Promise<HydratedDocument<Migration>[]>; prune(): Promise<HydratedDocument<Migration>[]>; private noPendingMigrations; private log; private logMigrationStatus; private getTemplate; private ensureMigrationsPath; private connected; private syncMigrations; private getMigrations; private choseMigrations; private runMigrations; } export { type ConfigOptions, type ConfigOptionsDefault, Env, type Migration, type MigrationFile, type MigrationFunctions, type MigrationFunctionsDefault, Migrator, type MigratorOptions };