-
Notifications
You must be signed in to change notification settings - Fork 225
/
index.js
64 lines (53 loc) · 1.41 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict'
/*!
* migrate
* Copyright(c) 2011 TJ Holowaychuk <[email protected]>
* MIT Licensed
*/
/**
* Module dependencies.
*/
const MigrationSet = require('./lib/set')
const FileStore = require('./lib/file-store')
const loadMigrationsIntoSet = require('./lib/load-migrations')
/**
* Expose the migrate function.
*/
exports = module.exports = migrate
function migrate (title, up, down) {
// migration
if (typeof title === 'string' && up && down) {
migrate.set.addMigration(title, up, down)
// specify migration file
} else if (typeof title === 'string') {
migrate.set = exports.load(title)
// no migration path
} else if (!migrate.set) {
throw new Error('must invoke migrate(path) before running migrations')
// run migrations
} else {
return migrate.set
}
}
/**
* Expose MigrationSet
*/
exports.MigrationSet = MigrationSet
exports.load = function (options, fn) {
const opts = options || {}
// Create default store
const store = (typeof opts.stateStore === 'string') ? new FileStore(opts.stateStore) : opts.stateStore
// Create migration set
const set = new MigrationSet(store)
loadMigrationsIntoSet({
set,
store,
migrations: opts.migrations,
migrationsDirectory: opts.migrationsDirectory,
filterFunction: opts.filterFunction,
sortFunction: opts.sortFunction,
ignoreMissing: opts.ignoreMissing
}, function (err) {
fn(err, set)
})
}