unoffical wafrn mirror
wafrn.net
atproto
social-network
activitypub
1import { Sequelize } from "sequelize";
2import { Umzug, SequelizeStorage } from "umzug";
3import process from "process";
4import { realpathSync } from "fs";
5import { pathToFileURL } from "url";
6import { completeEnvironment } from "./utils/backendOptions.js";
7import { wait } from "./utils/wait.js";
8
9function wasCalledAsScript() {
10 const realPath = realpathSync(process.argv[1]);
11 const realPathAsUrl = pathToFileURL(realPath).href;
12 return import.meta.url === realPathAsUrl;
13}
14
15await wait(5000);
16
17const sequelize = new Sequelize(completeEnvironment.databaseConnectionString);
18
19const umzug = new Umzug({
20 migrations: { glob: "migrations/*.ts" },
21 context: sequelize.getQueryInterface(),
22 storage: new SequelizeStorage({ sequelize }),
23 logger: console,
24});
25
26// export the type helper exposed by umzug, which will have the `context` argument typed correctly
27export type Migration = typeof umzug._types.migration;
28
29if (wasCalledAsScript()) {
30 if (process.argv[2] == "init-container") {
31 await umzug.up();
32 console.log("Migrations run successfully");
33 process.exit(0);
34 } else {
35 await umzug.runAsCLI();
36 }
37}