This commit is contained in:
seb
2026-10-29 16:27:02 +01:00
parent 005b48ff66
commit 676a40d4fe
6 changed files with 50 additions and 16 deletions

View File

@@ -10,6 +10,7 @@ const schemaLog = createLogger('schema');
let provider;
let store;
let connecting;
let schemaVersion;
const STORE_NAMESPACES = [
'companyuser',
@@ -149,6 +150,7 @@ export async function getStore() {
provider = createProvider();
try {
await provider.initialize((msg) => schemaLog.info(msg));
schemaVersion = await provider.getSchemaVersion();
} catch (err) {
schemaLog.error('Database schema initialization failed:', err);
throw err;
@@ -168,6 +170,19 @@ export async function getProvider() {
return provider;
}
/**
* Returns the current database schema version.
* @returns {Promise<number>}
*/
export async function getSchemaVersion() {
if (schemaVersion != null) {
return schemaVersion;
}
const prov = await getProvider();
schemaVersion = await prov.getSchemaVersion();
return schemaVersion;
}
export async function ensureConnection() {
await getStore();
}
@@ -177,6 +192,7 @@ export async function closeStore() {
await provider.close();
provider = undefined;
store = undefined;
schemaVersion = undefined;
}
}