forked from openstad/openstad-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrate.js
executable file
·52 lines (49 loc) · 1.13 KB
/
migrate.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
var Umzug = require('umzug');
var db = require('./src/db');
var umzug = new Umzug({
storage: 'sequelize',
storageOptions : {
sequelize : db.sequelize,
modelName : 'Migrations',
tableName : 'migrations'
},
migrations : {
path : 'migrations',
pattern : /^\d+[\w_-]+\.js$/
}
});
umzug.executed()
.then(function( migrations ) {
return !migrations.length ?
logAllMigrations() :
performMigrations();
})
.catch(function( e ) {
console.log(e);
})
.finally(function() {
process.exit();
});
function logAllMigrations() {
console.log('New installation, marking all migrations as done...');
return umzug.pending()
.then(function( migrations ) {
return Promise.all(migrations.map(logMigration));
});
}
function logMigration( migration ) {
console.log(migration.file);
return umzug.storage.logMigration(migration.file);
}
function performMigrations() {
return umzug.up()
.then(function( migrations ) {
if( !migrations.length ) {
console.log('No new migrations');
} else {
console.log('Executed migrations:');
var fileNames = migrations.map(m => m.file);
console.log(fileNames.join('\n'));
}
});
}