Merge pull request #6931 from drinchev/umzug

Added umzug v1.7.0 definitions
This commit is contained in:
Horiuchi_H
2015-12-01 15:25:58 +09:00
2 changed files with 322 additions and 0 deletions
+134
View File
@@ -0,0 +1,134 @@
/// <reference path="./umzug.d.ts" />
/// <reference path="../sequelize/sequelize.d.ts" />
/// <reference path="../node/node.d.ts" />
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<any, any>( '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)
}
});
+188
View File
@@ -0,0 +1,188 @@
// Type definitions for Umzug v1.7.0
// Project: https://github.com/sequelize/umzug
// Definitions by: Ivan Drinchev <https://github.com/drinchev/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../bluebird/bluebird.d.ts" />
/// <reference path="../sequelize/sequelize.d.ts" />
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<any>;
/** 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?: <T>( 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<any, any>;
/**
* 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<string>;
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<string>;
}
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<Array<string>>;
/**
* You can get a list of pending/not yet executed migrations like this:
*/
pending() : Promise<Array<string>>;
/**
* You can get a list of already executed migrations like this:
*/
executed() : Promise<Array<string>>;
/**
* The up method can be used to execute all pending migrations.
*/
up(migration?: string) : Promise<string>;
up(migrations?: Array<string>) : Promise<Array<string>>;
up(options?: UpDownToOptions | UpDownMigrationsOptions ) : Promise<Array<string>>;
/**
* The down method can be used to revert the last executed migration.
*/
down(migration?: string) : Promise<string>;
down(migrations?: Array<string>) : Promise<Array<string>>;
down(options?: UpDownToOptions | UpDownMigrationsOptions ) : Promise<Array<string>>;
}
var umzug : typeof Umzug;
export = umzug;
}