skip migrations if the user has disabled logging

This commit is contained in:
Reto Brunner 2022-12-31 13:53:29 +01:00
parent d67277d996
commit dfed1dd757

View file

@ -29,23 +29,40 @@ async function runMigrations(user: string) {
throw new Error(`invalid user ${user}`);
}
return migrateUser(user);
return migrateUser(manager, user);
}
for (const name of users) {
await migrateUser(name);
await migrateUser(manager, name);
// if any migration fails we blow up,
// chances are the rest won't complete either
}
}
// runs sqlite migrations for a user, which must exist
async function migrateUser(user: string) {
async function migrateUser(manager: ClientManager, user: string) {
log.info("handling user", user);
if (!isUserLogEnabled(manager, user)) {
log.info("logging disabled for user", user, ". Skipping");
return;
}
const sqlite = new SqliteMessageStorage(user);
await sqlite.enable(); // enable runs migrations
await sqlite.close();
log.info("user", user, "migrated successfully");
}
function isUserLogEnabled(manager: ClientManager, user: string): boolean {
const conf = manager.readUserConfig(user);
if (!conf) {
log.error("Could not open user configuration of", user);
return false;
}
return conf.log;
}
export default program;