-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathmigrate.ts
More file actions
46 lines (42 loc) · 930 Bytes
/
migrate.ts
File metadata and controls
46 lines (42 loc) · 930 Bytes
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
import { Sequelize } from 'sequelize-typescript';
import Umzug = require('umzug');
const sequelize = new Sequelize({
dialect: 'postgres',
host: 'YOUR_HOST',
port: 5432,
username: 'YOUR_USERNAME',
password: 'YOUR_PASSWORD',
database: 'YOUR_DB_NAME'
});
const umzug = new Umzug({
storage: 'sequelize',
storageOptions: { sequelize },
logging: false,
migrations: {
params: [
sequelize,
sequelize.constructor,
],
path: './src/migrations',
pattern: /\.ts$/,
},
});
const task = (process.argv[2] || '').trim();
switch (task) {
case 'up':
umzug.up()
.then((result) => {
console.log('Migrations up went successful!', result);
process.exit(0);
});
break;
case 'down':
umzug.down()
.then((result) => {
console.log('Migrations down went successful!', result);
process.exit(0);
});
break;
default:
break;
};