umzug mongodb storage (#27547)

* umzug mongodb storage

* make mongodb storage connection optional
This commit is contained in:
Emmanuel Gautier
2018-07-31 15:01:44 -07:00
committed by Sheetal Nandi
parent c252eedb85
commit e20d154eb6
2 changed files with 56 additions and 5 deletions
+26 -3
View File
@@ -1,13 +1,15 @@
// Type definitions for Umzug v2.1.0
// Type definitions for Umzug v2.2.0
// Project: https://github.com/sequelize/umzug
// Definitions by: Ivan Drinchev <https://github.com/drinchev>
// Margus Lamp <https://github.com/mlamp>
// Troy McKinnon <https://github.com/trodi>
// Emmanuel Gautier <https://github.com/emmanuelgautier>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import { EventEmitter } from 'events';
import Sequelize = require("sequelize");
import MongoDB = require("mongodb");
declare namespace umzug {
@@ -116,6 +118,27 @@ declare namespace umzug {
}
interface MongoDBStorageOptions extends Storage {
/**
* The MongoDB database connection instance.
*/
connection?: MongoDB.Db;
/**
* The to be used Mongo collection cursor.
* Defaults to collection created from collectionName attribute.
*/
collection?: MongoDB.Collection;
/**
* The name of the collection used by the connection.
* Defaults to 'migrations'
*/
collectionName?: string;
}
interface ExecuteOptions {
migrations?: Array<string>;
method?: string;
@@ -125,12 +148,12 @@ declare namespace umzug {
/**
* The storage.
*/
storage?: "json" | "sequelize" | Storage;
storage?: "json" | "sequelize" | "mongodb" | Storage;
/**
* The options for the storage.
*/
storageOptions?: JSONStorageOptions | SequelizeStorageOptions | Object;
storageOptions?: JSONStorageOptions | SequelizeStorageOptions | MongoDBStorageOptions | Object;
/**
* The logging function.
+30 -2
View File
@@ -1,5 +1,6 @@
import Umzug = require('umzug');
import Sequelize = require('sequelize');
import MongoDB = require('mongodb');
let someVar: Umzug.Umzug;
const umzug = new Umzug({});
@@ -44,7 +45,7 @@ umzug.on('reverted', (name: string, migration: Umzug.Migration) => null);
new Umzug({
// The storage.
// Possible values: 'json', 'sequelize', an object
// Possible values: 'json', 'sequelize', 'mongodb' an object
storage: 'json',
// The options for the storage.
@@ -80,7 +81,7 @@ new Umzug({
new Umzug({
// The storage.
// Possible values: 'json', 'sequelize', an object
// Possible values: 'json', 'sequelize', 'mongodb' an object
storage: 'json',
storageOptions: {
path: '/db/sequelize-meta.json',
@@ -121,3 +122,30 @@ new Umzug({
},
});
const mongodb = new MongoDB.Db('database', new MongoDB.Server('host', 21017));
new Umzug({
// The storage.
// Possible values: 'json', 'sequelize', 'mongodb' an object
storage: 'mongodb',
storageOptions: {
/**
* The MongoDB database connection instance.
*/
connection: mongodb,
/**
* The to be used Mongo collection cursor.
* Defaults to collection created from collectionName attribute.
*/
collection: mongodb.collection,
/**
* The name of the collection used by the connection.
* Defaults to 'migrations'
*/
collectionName: 'migrations'
},
});