refactor(db): migrate app pages and APIs from Prisma facade to Drizzle (2)
Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
7c39aef5d9
commit
2cd0863cb8
40 files changed
+1069
-726
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import os from "node:os";
|
||||
import { count, desc, inArray } from "drizzle-orm";
|
||||
import { Terminal } from "lucide-react";
|
||||
import { redirect } from "next/navigation";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
@@ -11,9 +12,9 @@ import {
|
||||
} from "@/components/admin/dashboard";
|
||||
import { fetchOpsHealth } from "@/lib/admin/ops-health";
|
||||
import { fetchOpsOnlineUsers } from "@/lib/admin/ops-online-users";
|
||||
import { db, EmulatorErrors, StaffActivities, User } from "@/lib/db";
|
||||
import { formatDate } from "@/lib/format-date";
|
||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { siteSettings } from "@/lib/services/site-settings";
|
||||
import { CommandocentrumControls } from "./commandocentrum-controls";
|
||||
|
||||
@@ -46,22 +47,29 @@ export default async function CommandoCentrum() {
|
||||
|
||||
const t = await getTranslations("pages.admin.commandocentrum");
|
||||
|
||||
const [totalUsers, errors, health, maintenance, activity, onlineRoster] =
|
||||
const [totalUsersRows, errors, health, maintenance, activity, onlineRoster] =
|
||||
await Promise.all([
|
||||
prisma.user.count().catch(() => -1),
|
||||
prisma.emulatorErrors
|
||||
.findMany({ orderBy: { timestamp: "desc" }, take: 50 })
|
||||
db
|
||||
.select({ total: count() })
|
||||
.from(User)
|
||||
.catch(() => [{ total: -1 }]),
|
||||
db
|
||||
.select()
|
||||
.from(EmulatorErrors)
|
||||
.orderBy(desc(EmulatorErrors.timestamp))
|
||||
.limit(50)
|
||||
.catch(() => []),
|
||||
fetchOpsHealth(),
|
||||
siteSettings.getBool("maintenance_enabled", false),
|
||||
prisma.staffActivities
|
||||
.findMany({ orderBy: { createdAt: "desc" }, take: 12 })
|
||||
.catch(
|
||||
() =>
|
||||
[] as Awaited<ReturnType<typeof prisma.staffActivities.findMany>>,
|
||||
),
|
||||
db
|
||||
.select()
|
||||
.from(StaffActivities)
|
||||
.orderBy(desc(StaffActivities.createdAt))
|
||||
.limit(12)
|
||||
.catch(() => [] as (typeof StaffActivities.$inferSelect)[]),
|
||||
fetchOpsOnlineUsers(40),
|
||||
]);
|
||||
const totalUsers = Number(totalUsersRows[0]?.total ?? -1);
|
||||
|
||||
const dbOk = health.dbOk;
|
||||
const redisOk = health.redisOk;
|
||||
@@ -74,11 +82,10 @@ export default async function CommandoCentrum() {
|
||||
).filter((n) => n > 0);
|
||||
let nameById = new Map<number, string>();
|
||||
if (staffIds.length) {
|
||||
const users = await prisma.user
|
||||
.findMany({
|
||||
where: { id: { in: staffIds } },
|
||||
select: { id: true, username: true },
|
||||
})
|
||||
const users = await db
|
||||
.select({ id: User.id, username: User.username })
|
||||
.from(User)
|
||||
.where(inArray(User.id, staffIds))
|
||||
.catch(() => []);
|
||||
nameById = new Map(users.map((u) => [u.id, u.username]));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user