|
|
|
@ -1,5 +1,5 @@ |
|
|
|
const { DocumentTypes } = require("../db/constants") |
|
|
|
const { getGlobalDB } = require("../tenancy") |
|
|
|
const { getGlobalDB, getTenantId } = require("../tenancy") |
|
|
|
|
|
|
|
exports.MIGRATION_DBS = { |
|
|
|
GLOBAL_DB: "GLOBAL_DB", |
|
|
|
@ -29,6 +29,7 @@ exports.getMigrationsDoc = async db => { |
|
|
|
} |
|
|
|
|
|
|
|
exports.migrateIfRequired = async (migrationDb, migrationName, migrateFn) => { |
|
|
|
const tenantId = getTenantId() |
|
|
|
try { |
|
|
|
let db |
|
|
|
if (migrationDb === exports.MIGRATION_DBS.GLOBAL_DB) { |
|
|
|
@ -49,15 +50,18 @@ exports.migrateIfRequired = async (migrationDb, migrationName, migrateFn) => { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
console.log(`Performing migration: ${migrationName}`) |
|
|
|
console.log(`[Tenant: ${tenantId}] Performing migration: ${migrationName}`) |
|
|
|
await migrateFn() |
|
|
|
console.log(`Migration complete: ${migrationName}`) |
|
|
|
console.log(`[Tenant: ${tenantId}] Migration complete: ${migrationName}`) |
|
|
|
|
|
|
|
// mark as complete
|
|
|
|
doc[migrationName] = Date.now() |
|
|
|
await db.put(doc) |
|
|
|
} catch (err) { |
|
|
|
console.error(`Error performing migration: ${migrationName}: `, err) |
|
|
|
console.error( |
|
|
|
`[Tenant: ${tenantId}] Error performing migration: ${migrationName}: `, |
|
|
|
err |
|
|
|
) |
|
|
|
throw err |
|
|
|
} |
|
|
|
} |
|
|
|
|