mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-07 06:18:03 +03:00
feat(migrations): apply unapplied migrations on init
This commit is contained in:
@@ -57,6 +57,28 @@ export async function FindUnappliedMigrations() {
|
||||
return notApplied;
|
||||
}
|
||||
|
||||
export async function ApplyUnappliedMigrations() {
|
||||
const unapplied = await FindUnappliedMigrations();
|
||||
|
||||
if (unapplied.length === 0) {
|
||||
logger.verbose(`Found no migrations to apply. Not bothering.`);
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info(
|
||||
`Found ${
|
||||
unapplied.length
|
||||
} migration(s) that have not been applied yet. These are '${unapplied.join("', '")}'.`,
|
||||
{ unapplied }
|
||||
);
|
||||
|
||||
for (const migrationID of unapplied) {
|
||||
// These things need to apply in lockstep.
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await ApplyMigration(migrationID);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a migration. Will **EXIT TACHI** if a migration fails to apply, as this implies
|
||||
* database level inconsistencies which could cause severe problems.
|
||||
|
||||
@@ -13,6 +13,7 @@ import { LoadDefaultClients } from "lib/builtin-clients/builtin-clients";
|
||||
import { VERSION_PRETTY } from "lib/constants/version";
|
||||
import { HandleSIGTERMGracefully } from "lib/handlers/sigterm";
|
||||
import CreateLogCtx from "lib/logger/logger";
|
||||
import { ApplyUnappliedMigrations } from "lib/migration/migrations";
|
||||
import { Environment, ServerConfig, TachiConfig } from "lib/setup/config";
|
||||
import path from "path";
|
||||
import server from "server/server";
|
||||
@@ -32,6 +33,8 @@ async function RunOnInit() {
|
||||
await InitSequenceDocs();
|
||||
await SetIndexesIfNoneSet();
|
||||
|
||||
await ApplyUnappliedMigrations();
|
||||
|
||||
await db["folder-chart-lookup"].findOne().then((r) => {
|
||||
// If there are no folder chart lookups, initialise them.
|
||||
if (!r) {
|
||||
|
||||
Reference in New Issue
Block a user