-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request 'Merge in upstream fixes' (#1) from upstream-fixes…
…-202312 into master Reviewed-on: https://git.supernets.org/supernets/hardlounge/pulls/1
- Loading branch information
Showing
8 changed files
with
395 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import log from "../log"; | ||
import { Command } from "commander"; | ||
import ClientManager from "../clientManager"; | ||
import Utils from "./utils"; | ||
import SqliteMessageStorage from "../plugins/messageStorage/sqlite"; | ||
|
||
const program = new Command("storage").description( | ||
"various utilities related to the message storage" | ||
); | ||
|
||
program | ||
.command("migrate") | ||
.argument("[user]", "migrate a specific user only, all if not provided") | ||
.description("Migrate message storage where needed") | ||
.on("--help", Utils.extraHelp) | ||
.action(function (user) { | ||
runMigrations(user).catch((err) => { | ||
log.error(err.toString()); | ||
process.exit(1); | ||
}); | ||
}); | ||
|
||
async function runMigrations(user: string) { | ||
const manager = new ClientManager(); | ||
const users = manager.getUsers(); | ||
|
||
if (user) { | ||
if (!users.includes(user)) { | ||
throw new Error(`invalid user ${user}`); | ||
} | ||
|
||
return migrateUser(manager, user); | ||
} | ||
|
||
for (const name of users) { | ||
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(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; |
Oops, something went wrong.