-
Notifications
You must be signed in to change notification settings - Fork 9
/
migration.js
48 lines (41 loc) · 902 Bytes
/
migration.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
const Sequelize = require("sequelize");
const Umzug = require("umzug");
module.exports = class Migration {
constructor(connectionString) {
this.connectionString = connectionString;
this.close = this.init();
}
init() {
this.sequelize = new Sequelize(this.connectionString, {
pool: {
max: 1,
min: 0,
idle: 5000
}
});
this.umzug = new Umzug({
storage: "sequelize",
storageOptions: {
sequelize: this.sequelize
},
migrations: {
params: [this.sequelize.getQueryInterface(), this.sequelize.constructor]
},
logging: function() {
console.log.apply(null, arguments);
}
});
return () => {
this.sequelize.close();
};
}
pending() {
return this.umzug.pending();
}
up() {
return this.umzug.up();
}
down() {
return this.umzug.down();
}
};