misc: properly handled multi-container setups

This commit is contained in:
Sheen Capadngan
2025-10-28 05:52:58 +08:00
parent b9c824559c
commit 8214e07abd
4 changed files with 54 additions and 18 deletions
+8 -1
View File
@@ -12,6 +12,7 @@ type TArgs = {
auditLogDb?: Knex;
applicationDb: Knex;
logger: Logger;
onMigrationLockAcquired?: () => void;
};
const isProduction = process.env.NODE_ENV === "production";
@@ -30,7 +31,7 @@ const migrationStatusCheckErrorHandler = (err: Error) => {
throw err;
};
export const runMigrations = async ({ applicationDb, auditLogDb, logger }: TArgs) => {
export const runMigrations = async ({ applicationDb, auditLogDb, logger, onMigrationLockAcquired }: TArgs) => {
try {
// akhilmhdh(Feb 10 2025): 2 years from now remove this
if (isProduction) {
@@ -85,6 +86,12 @@ export const runMigrations = async ({ applicationDb, auditLogDb, logger }: TArgs
await applicationDb.transaction(async (tx) => {
await tx.raw("SELECT pg_advisory_xact_lock(?)", [PgSqlLock.BootUpMigration]);
// Signal that this container is running migrations
if (onMigrationLockAcquired) {
onMigrationLockAcquired();
}
logger.info("Running application migrations.");
const didPreviousInstanceRunMigration = !(await applicationDb.migrate