A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.
feat(cli): add fix-username command to make all usernames lowercase (#2366)
Meier Lukas8b7caf1d7dfe
diff --git a/packages/cli/src/commands/fix-usernames.ts b/packages/cli/src/commands/fix-usernames.tsnew file mode 100644index 000000000..f2b3b774c--- /dev/null+++ b/packages/cli/src/commands/fix-usernames.ts@@ -0,0 +1,36 @@+import { command } from "@drizzle-team/brocli";++import { db, eq } from "@homarr/db";+import { users } from "@homarr/db/schema";++export const fixUsernames = command({+ name: "fix-usernames",+ desc: "Changes all credentials usernames to lowercase",+ // eslint-disable-next-line no-restricted-syntax+ handler: async () => {+ if (!process.env.AUTH_PROVIDERS?.toLowerCase().includes("credentials")) {+ console.error("Credentials provider is not enabled");+ return;+ }++ const credentialUsers = await db.query.users.findMany({+ where: eq(users.provider, "credentials"),+ });++ for (const user of credentialUsers) {+ if (!user.name) continue;+ if (user.name !== user.name.toLowerCase()) continue;++ await db+ .update(users)+ .set({+ name: user.name.toLowerCase(),+ })+ .where(eq(users.id, user.id));++ console.log(`Changed username from ${user.name} to ${user.name.toLowerCase()}`);+ }++ console.log("All usernames have been fixed");+ },+});diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.tsindex e84f7d202..8b56f9c5c 100644--- a/packages/cli/src/index.ts+++ b/packages/cli/src/index.ts@@ -1,8 +1,9 @@import { run } from "@drizzle-team/brocli";+import { fixUsernames } from "./commands/fix-usernames";import { resetPassword } from "./commands/reset-password";-const commands = [resetPassword];+const commands = [resetPassword, fixUsernames];void run(commands, {name: "homarr-cli",