u
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user