mirror of
https://github.com/thelounge/thelounge.git
synced 2024-05-17 05:36:36 +02:00
skip migrations if the user has disabled logging
This commit is contained in:
parent
d67277d996
commit
dfed1dd757
|
@ -29,23 +29,40 @@ async function runMigrations(user: string) {
|
||||||
throw new Error(`invalid user ${user}`);
|
throw new Error(`invalid user ${user}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return migrateUser(user);
|
return migrateUser(manager, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const name of users) {
|
for (const name of users) {
|
||||||
await migrateUser(name);
|
await migrateUser(manager, name);
|
||||||
// if any migration fails we blow up,
|
// if any migration fails we blow up,
|
||||||
// chances are the rest won't complete either
|
// chances are the rest won't complete either
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// runs sqlite migrations for a user, which must exist
|
// 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);
|
log.info("handling user", user);
|
||||||
|
|
||||||
|
if (!isUserLogEnabled(manager, user)) {
|
||||||
|
log.info("logging disabled for user", user, ". Skipping");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const sqlite = new SqliteMessageStorage(user);
|
const sqlite = new SqliteMessageStorage(user);
|
||||||
await sqlite.enable(); // enable runs migrations
|
await sqlite.enable(); // enable runs migrations
|
||||||
await sqlite.close();
|
await sqlite.close();
|
||||||
log.info("user", user, "migrated successfully");
|
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;
|
export default program;
|
||||||
|
|
Loading…
Reference in a new issue