update: the api backs up before migrating; scripts/update.sh for compose installs
Docker only, never bare metal (owner, 2026-10-21). A new version with pending migrations backs up first (database, voicemail, sounds, MOH) and stops if it can't (SKIP_BACKUP_BEFORE_MIGRATE to override). update.sh: checks, changelog, backup (node dist/backup-cli.js), log compaction, build while the old version runs, restart, self-check, and rollback with restore. Container logs capped in compose. Admin guide: Updating, for compose and Portainer.
This commit is contained in:
1 parent
8d5475cfbf
commit
54e1e201a1
9 files changed
+376
-6
No files matched your search
@@ -1,5 +1,8 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { sql } from 'drizzle-orm';
|
||||
import { drizzle } from 'drizzle-orm/node-postgres';
|
||||
import { migrate } from 'drizzle-orm/node-postgres/migrator';
|
||||
import pg from 'pg';
|
||||
@@ -19,3 +22,21 @@ export type Db = ReturnType<typeof createDb>['db'];
|
||||
export async function runMigrations(db: Db): Promise<void> {
|
||||
await migrate(db, { migrationsFolder: MIGRATIONS_DIR });
|
||||
}
|
||||
|
||||
/**
|
||||
* This image has migrations the database hasn't run yet. False for an empty database (a fresh
|
||||
* install: nothing to lose). Reads drizzle's own bookkeeping, `drizzle.__drizzle_migrations`.
|
||||
*/
|
||||
export async function migrationsPending(db: Db, folder = MIGRATIONS_DIR): Promise<boolean> {
|
||||
const journal = JSON.parse(await readFile(join(folder, 'meta', '_journal.json'), 'utf8')) as {
|
||||
entries: unknown[];
|
||||
};
|
||||
const t = await db.execute<{ t: string | null }>(
|
||||
sql`select to_regclass('drizzle.__drizzle_migrations')::text as t`,
|
||||
);
|
||||
if (!t.rows[0]?.t) return false;
|
||||
const r = await db.execute<{ n: number }>(
|
||||
sql`select count(*)::int as n from drizzle.__drizzle_migrations`,
|
||||
);
|
||||
return r.rows[0]!.n < journal.entries.length;
|
||||
}
|
||||
Reference in new issue
Block a user