refactor(db): finish Drizzle migration for remaining actions and services

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
SimoandCursor committed 2026-08-01 13:27:59 +02:00
1 parent 22234fe102
commit 65b2fbee6a
19 files changed
+422 -342

No files matched your search

+12 -7
View File
@@ -1,7 +1,8 @@
import "server-only";
import { count, eq, sql } from "drizzle-orm";
import { env } from "@/env";
import { prisma } from "@/lib/prisma";
import { db, User } from "@/lib/db";
import { redis } from "@/lib/redis";
import { rcon } from "@/lib/services/rcon";
@@ -19,11 +20,11 @@ export type OpsHealth = {
* Semantics match `/api/health` for Redis (null when not configured).
*/
export async function fetchOpsHealth(): Promise<OpsHealth> {
const [db, redisOk, emulatorOk, onlineUsers] = await Promise.all([
const [dbProbe, redisOk, emulatorOk, onlineUsers] = await Promise.all([
(async () => {
try {
const start = Date.now();
await prisma.$queryRaw`SELECT 1`;
await db.execute(sql`SELECT 1`);
return { dbOk: true, dbLatencyMs: Date.now() - start };
} catch {
return { dbOk: false, dbLatencyMs: 0 };
@@ -40,12 +41,16 @@ export async function fetchOpsHealth(): Promise<OpsHealth> {
}
})(),
rcon.send("ping", null).catch(() => false),
prisma.user.count({ where: { online: "1" } }).catch(() => 0),
db
.select({ total: count() })
.from(User)
.where(eq(User.online, "1"))
.then((rows) => rows[0]?.total ?? 0)
.catch(() => 0),
]);
return {
dbOk: db.dbOk,
dbLatencyMs: db.dbLatencyMs,
dbOk: dbProbe.dbOk,
dbLatencyMs: dbProbe.dbLatencyMs,
redisOk,
emulatorOk: Boolean(emulatorOk),
onlineUsers,