chore: Add flag to prevent automatic migration running on startup
This commit is contained in:
@@ -10,10 +10,11 @@ export function getArg(name: string, shortName?: string) {
|
||||
.slice(2)
|
||||
.filter(
|
||||
(arg) =>
|
||||
arg === `--${name}` ||
|
||||
arg.startsWith(`--${name}=`) ||
|
||||
(shortName && arg.startsWith(`-${shortName}=`))
|
||||
)
|
||||
.map((arg) => arg.split("=")[1])
|
||||
.map((arg) => arg.split("=")[1] ?? "true")
|
||||
.map((arg) => arg.trim())
|
||||
.join(",");
|
||||
|
||||
|
||||
@@ -5,13 +5,23 @@ import Logger from "@server/logging/Logger";
|
||||
import AuthenticationProvider from "@server/models/AuthenticationProvider";
|
||||
import Team from "@server/models/Team";
|
||||
import { migrations } from "@server/storage/database";
|
||||
import { getArg } from "./args";
|
||||
|
||||
export async function checkPendingMigrations() {
|
||||
try {
|
||||
const pending = await migrations.pending();
|
||||
if (!isEmpty(pending)) {
|
||||
Logger.info("database", "Running migrations…");
|
||||
await migrations.up();
|
||||
if (getArg("no-migrate")) {
|
||||
Logger.warn(
|
||||
chalk.red(
|
||||
`Database migrations are pending and were not ran because --no-migrate flag was passed.\nRun the migrations with "yarn db:migrate".`
|
||||
)
|
||||
);
|
||||
process.exit(1);
|
||||
} else {
|
||||
Logger.info("database", "Running migrations…");
|
||||
await migrations.up();
|
||||
}
|
||||
}
|
||||
await checkDataMigrations();
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user