-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmigrate.ts
46 lines (42 loc) · 1.5 KB
/
migrate.ts
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 { Umzug, SequelizeStorage, type MigrationParams } from 'umzug';
import { Sequelize } from 'sequelize';
import log from './core/log';
const sequelize = new Sequelize(process.env['DATABASE'] ?? '', {
logging(sql, timing) {
log.info('$d7c' + sql);
}
});
(async () => {
try {
log.info('$fffMigrating:');
for (const path of ['./core/migrations/', './userdata/migrations/']) {
const migrator = new Umzug({
migrations: {
glob: [path + '*.ts', { cwd: process.cwd() }]
},
context: sequelize,
storage: new SequelizeStorage({
sequelize
}),
logger: {
debug: (message) => {},
error: (message) => {
log.info('$f00' + message);
},
warn: (message) => {
log.info('$fa0' + message);
},
info: (message) => {}
//info: (message) => { log.info("$5bf" + message.event + " $fff" + message.name) },
}
});
log.info('$5bfRunning migrations for ' + path);
await migrator.up();
log.info('$0f0Success!');
}
process.exit(0);
} catch (e: any) {
log.error('$f00error occurred');
}
})();
export type Migration = (params: MigrationParams<Sequelize>, context: Sequelize) => Promise<unknown>;