From 0cf0251b353eed2dc733804e51d094334138dd1a Mon Sep 17 00:00:00 2001 From: Ivan Drinchev Date: Tue, 24 Nov 2015 17:22:57 +0200 Subject: [PATCH] Added umzug v1.7.0 definitions --- umzug/umzug-tests.ts | 134 ++++++++++++++++++++++++++++++ umzug/umzug.d.ts | 188 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 322 insertions(+) create mode 100644 umzug/umzug-tests.ts create mode 100644 umzug/umzug.d.ts diff --git a/umzug/umzug-tests.ts b/umzug/umzug-tests.ts new file mode 100644 index 000000000..95d7521fd --- /dev/null +++ b/umzug/umzug-tests.ts @@ -0,0 +1,134 @@ +/// +/// +/// + +import Umzug = require("umzug"); +import Sequelize = require("sequelize"); + + +var umzug = new Umzug({}); + +umzug.up().then(function (result) { + // do something with the result +}); + +umzug.execute({ + migrations: ['some-id', 'some-other-id'], + method: 'up' +}).then(function (migrations) { + // "migrations" will be an Array of all executed/reverted migrations. +}); + +umzug.pending().then(function (migrations) { + // "migrations" will be an Array with the names of + // pending migrations. +}); + +umzug.executed().then(function (migrations) { + // "migrations" will be an Array of already executed migrations. +}); + +umzug.up().then(function (migrations) { + // "migrations" will be an Array with the names of the + // executed migrations. +}); + +umzug.up({ to: '20141101203500-task' }).then(function (migrations) {}); + +umzug.up({ migrations: ['20141101203500-task', '20141101203501-task-2'] }); + +umzug.up('20141101203500-task'); // Runs just the passed migration +umzug.up(['20141101203500-task', '20141101203501-task-2']); + +umzug.down().then(function (migration) { + // "migration" will the name of the reverted 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']); + +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: function (fun : Function) { return fun; } + } +}); + +var AnotherUmzug = new Umzug({ + // The storage. + // Possible values: 'json', 'sequelize', an object + storage: 'json', + storageOptions: { + path: process.cwd() + '/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) + } + +}); diff --git a/umzug/umzug.d.ts b/umzug/umzug.d.ts new file mode 100644 index 000000000..2e2b20a7c --- /dev/null +++ b/umzug/umzug.d.ts @@ -0,0 +1,188 @@ +// Type definitions for Umzug v1.7.0 +// Project: https://github.com/sequelize/umzug +// Definitions by: Ivan Drinchev +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +/// + +declare module "umzug" { + + import Sequelize = require("sequelize"); + + interface MigrationOptions { + + /* + * The params that gets passed to the migrations. + * Might be an array or a synchronous function which returns an array. + */ + params?: Array; + + /** The path to the migrations directory. */ + path?: string; + + /** The pattern that determines whether or not a file is a migration. */ + pattern?: RegExp; + + /** + * A function that receives and returns the to be executed function. + * This can be used to modify the function. + */ + wrap?: ( fn : T ) => T; + + } + + interface JSONStorageOptions { + + /** + * The path to the json storage. + * Defaults to process.cwd() + '/umzug.json'; + */ + path?: string; + + } + + interface SequelizeStorageOptions { + + /** + * The configured instance of Sequelize. + * Optional if `model` is passed. + */ + sequelize?: Sequelize.Sequelize; + + /** + * The to be used Sequelize model. + * Must have column name matching `columnName` option + * Optional of `sequelize` is passed. + */ + model?: Sequelize.Model; + + /** + * The name of the to be used model. + * Defaults to 'SequelizeMeta' + */ + modelName?: string; + + /** + * The name of table to create if `model` option is not supplied + * Defaults to `modelName` + */ + tableName?: string; + + /** + * The name of table column holding migration name. + * Defaults to 'name'. + */ + columnName: string; + + /** + * The type of the column holding migration name. + * Defaults to `Sequelize.STRING` + */ + columnType: Sequelize.DataTypeAbstract; + + } + + interface ExecuteOptions { + migrations?: Array; + method?: string; + } + + interface UmzugOptions { + + /** + * The storage. + * Possible values: 'json', 'sequelize', an object + */ + storage?: string; + + /** + * The options for the storage. + */ + storageOptions?: JSONStorageOptions | SequelizeStorageOptions | Object; + + /** + * The logging function. + * A function that gets executed everytime migrations start and have ended. + */ + logging? : boolean | Function; + + /** + * The name of the positive method in migrations. + */ + upName? : string; + + /** + * The name of the negative method in migrations. + */ + downName? : string; + + /** + * Options for defined migration + */ + migrations? : MigrationOptions; + + } + + interface UpDownToOptions { + + /** + * It is also possible to pass the name of a migration in order to + * just run the migrations from the current state to the passed + * migration name. + */ + to: string; + + } + + interface UpDownMigrationsOptions { + + /** + * Running specific migrations while ignoring the right order, can be + * done like this: + */ + migrations: Array; + + } + + class Umzug { + + constructor(options?: UmzugOptions); + + /** + * The execute method is a general purpose function that runs for + * every specified migrations the respective function. + */ + execute(options? : ExecuteOptions) : Promise>; + + /** + * You can get a list of pending/not yet executed migrations like this: + */ + pending() : Promise>; + + /** + * You can get a list of already executed migrations like this: + */ + executed() : Promise>; + + /** + * The up method can be used to execute all pending migrations. + */ + up(migration?: string) : Promise; + up(migrations?: Array) : Promise>; + up(options?: UpDownToOptions | UpDownMigrationsOptions ) : Promise>; + + /** + * The down method can be used to revert the last executed migration. + */ + down(migration?: string) : Promise; + down(migrations?: Array) : Promise>; + down(options?: UpDownToOptions | UpDownMigrationsOptions ) : Promise>; + + } + + var umzug : typeof Umzug; + + export = umzug; + +}