diff --git a/types/umzug/index.d.ts b/types/umzug/index.d.ts index 9f2602f361..931434aea3 100644 --- a/types/umzug/index.d.ts +++ b/types/umzug/index.d.ts @@ -202,9 +202,9 @@ declare namespace umzug { down(migrations?: string[]): Promise; down(options?: DownToOptions | UpDownMigrationsOptions): Promise; - on(eventName: 'migrating' | 'reverting' | 'migrated' | 'reverted', cb?: (name: string, migration: string) => void): this; - addListener(eventName: 'migrating' | 'reverting' | 'migrated' | 'reverted', cb?: (name: string, migration: string) => void): this; - removeListener(eventName: 'migrating' | 'reverting' | 'migrated' | 'reverted', cb?: (name: string, migration: string) => void): this; + on(eventName: 'migrating' | 'reverting' | 'migrated' | 'reverted', cb?: (name: string, migration: Migration) => void): this; + addListener(eventName: 'migrating' | 'reverting' | 'migrated' | 'reverted', cb?: (name: string, migration: Migration) => void): this; + removeListener(eventName: 'migrating' | 'reverting' | 'migrated' | 'reverted', cb?: (name: string, migration: Migration) => void): this; } diff --git a/types/umzug/umzug-tests.ts b/types/umzug/umzug-tests.ts index b5def394e9..fad7b11427 100644 --- a/types/umzug/umzug-tests.ts +++ b/types/umzug/umzug-tests.ts @@ -1,133 +1,123 @@ -import * as Umzug from "umzug"; -import * as Sequelize from "sequelize"; +import * as Umzug from 'umzug'; +import * as Sequelize from 'sequelize'; -var someVar:Umzug.Umzug; -var umzug = new Umzug({}); +let someVar: Umzug.Umzug; +const umzug = new Umzug({}); someVar = umzug; -umzug.up().then(function (result) { - // do something with the result -}); +umzug.up().then((migrations: Umzug.Migration[]) => null); umzug.execute({ migrations: ['some-id', 'some-other-id'], method: 'up' -}).then(function (migrations) { - // "migrations" will be an Array of all executed/reverted migrations. +}).then((migrations: Umzug.Migration[]) => null); + +umzug.pending().then((migrations: Umzug.Migration[]) => null); + +umzug.executed().then((migrations: Umzug.Migration[]) => null); + +umzug.up().then((migrations: Umzug.Migration[]) => null); + +umzug.up({ to: '20141101203500-task' }).then((migrations: Umzug.Migration[]) => null); + +umzug.up({ migrations: ['20141101203500-task', '20141101203501-task-2'] }).then((migrations: Umzug.Migration[]) => null); + +umzug.up('20141101203500-task').then((migrations: Umzug.Migration[]) => null); // Runs just the passed migration +umzug.up(['20141101203500-task', '20141101203501-task-2']).then((migrations: Umzug.Migration[]) => null); + +umzug.down().then((migrations: Umzug.Migration[]) => null); + +umzug.down({ to: '20141031080000-task' }).then((migrations: Umzug.Migration[]) => null); + +umzug.down({ migrations: ['20141101203500-task', '20141101203501-task-2'] }).then((migrations: Umzug.Migration[]) => null); + +umzug.down('20141101203500-task').then((migrations: Umzug.Migration[]) => null); +umzug.down(['20141101203500-task', '20141101203501-task-2']).then((migrations: Umzug.Migration[]) => null); + +umzug.down({ to: 0 }).then((migrations: Umzug.Migration[]) => null); + +umzug.on('migrating', (name: string, migration: Umzug.Migration) => null); +umzug.on('migrated', (name: string, migration: Umzug.Migration) => null); +umzug.on('reverting', (name: string, migration: Umzug.Migration) => null); +umzug.on('reverted', (name: string, migration: Umzug.Migration) => null); + + +new Umzug({ + // The storage. + // Possible values: 'json', 'sequelize', an object + storage: 'json', + + // The options for the storage. + // Check the available storages for further details. + storageOptions: {}, + + // The logging function. + // A function that gets executed every time migrations start and have ended. + logging: false, + + // The name of the positive method in migrations. + upName: 'up', + + // The name of the negative method in migrations. + downName: 'down', + + migrations: { + // The params that gets passed to the migrations. + // Might be an array or a synchronous function which returns an array. + params: [], + + // The path to the migrations directory. + path: 'migrations', + + // The pattern that determines whether or not a file is a migration. + pattern: /^\d+[\w-]+\.js$/, + + // A function that receives and returns the to be executed function. + // This can be used to modify the function. + wrap: (fun: T) => fun, + }, }); -umzug.pending().then(function (migrations) { - // "migrations" will be an Array with the names of - // pending migrations. +new Umzug({ + // The storage. + // Possible values: 'json', 'sequelize', an object + storage: 'json', + storageOptions: { + path: '/db/sequelize-meta.json', + }, }); -umzug.executed().then(function (migrations) { - // "migrations" will be an Array of already executed migrations. -}); +const sequelize = new Sequelize(''); -umzug.up().then(function (migrations) { - // "migrations" will be an Array with the names of the - // executed migrations. -}); +new Umzug({ + // The storage. + // Possible values: 'json', 'sequelize', an object + storage: 'sequelize', + storageOptions: { + // The configured instance of Sequelize. + // Optional if `model` is passed. + sequelize: sequelize, -umzug.up({ to: '20141101203500-task' }).then(function (migrations) {}); + // The to be used Sequelize model. + // Must have column name matching `columnName` option + // Optional of `sequelize` is passed. + model: sequelize.define('model', {}), -umzug.up({ migrations: ['20141101203500-task', '20141101203501-task-2'] }); + // The name of the to be used model. + // Defaults to 'SequelizeMeta' + modelName: 'Schema', -umzug.up('20141101203500-task'); // Runs just the passed migration -umzug.up(['20141101203500-task', '20141101203501-task-2']); + // The name of table to create if `model` option is not supplied + // Defaults to `modelName` + tableName: 'Schema', -umzug.down().then(function (migration) { - // "migration" will the name of the reverted migration. -}); + // The name of table column holding migration name. + // Defaults to 'name'. + columnName: 'migration', -umzug.down({ to: '20141031080000-task' }).then(function (migrations) { - // "migrations" will be an Array with the names of all reverted migrations. -}); - -umzug.down({ migrations: ['20141101203500-task', '20141101203501-task-2'] }); - -umzug.down('20141101203500-task'); // Runs just the passed migration -umzug.down(['20141101203500-task', '20141101203501-task-2']); - -umzug.down({to: 0}); // Reverts every migration. - -var AnotherUmzug = new Umzug({ - // The storage. - // Possible values: 'json', 'sequelize', an object - storage: 'json', - - // The options for the storage. - // Check the available storages for further details. - storageOptions: {}, - - // The logging function. - // A function that gets executed everytime migrations start and have ended. - logging: false, - - // The name of the positive method in migrations. - upName: 'up', - - // The name of the negative method in migrations. - downName: 'down', - - migrations: { - // The params that gets passed to the migrations. - // Might be an array or a synchronous function which returns an array. - params: [], - - // The path to the migrations directory. - path: 'migrations', - - // The pattern that determines whether or not a file is a migration. - pattern: /^\d+[\w-]+\.js$/, - - // A function that receives and returns the to be executed function. - // This can be used to modify the function. - wrap: (fun: T) => fun, - } -}); - -var AnotherUmzug = new Umzug({ - // The storage. - // Possible values: 'json', 'sequelize', an object - storage: 'json', - storageOptions: { - path: '/db/sequelize-meta.json' - } -}); - -var sequelize = new Sequelize(''); - -var AnotherUmzug = new Umzug({ - // The storage. - // Possible values: 'json', 'sequelize', an object - storage: 'sequelize', - storageOptions: { - // The configured instance of Sequelize. - // Optional if `model` is passed. - sequelize: sequelize, - - // The to be used Sequelize model. - // Must have column name matching `columnName` option - // Optional of `sequelize` is passed. - model: sequelize.define( 'model', {} ), - - // The name of the to be used model. - // Defaults to 'SequelizeMeta' - modelName: 'Schema', - - // The name of table to create if `model` option is not supplied - // Defaults to `modelName` - tableName: 'Schema', - - // The name of table column holding migration name. - // Defaults to 'name'. - columnName: 'migration', - - // The type of the column holding migration name. - // Defaults to `Sequelize.STRING` - columnType: Sequelize.STRING(100) - } + // The type of the column holding migration name. + // Defaults to `Sequelize.STRING` + columnType: Sequelize.STRING(100), + }, });