chore(db): remove Prisma facade and drop prisma:generate from CI
Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
ca72966a37
commit
422567272c
17 files changed
+182
-1430
No files matched your search
+26
-8
@@ -1,3 +1,4 @@
|
||||
import { eq, sql } from "drizzle-orm";
|
||||
import { unstable_cache } from "next/cache";
|
||||
import { cache } from "react";
|
||||
import { logAuthorizationEvent } from "./admin/authorization-events";
|
||||
@@ -5,8 +6,8 @@ import { isDynamicSuperAdmin } from "./admin/authorization-policy";
|
||||
import { resolveAuthorizationState } from "./admin/rank-authority";
|
||||
import { auth } from "./auth";
|
||||
import { sessionUserId } from "./auth/session-user";
|
||||
import { db, User } from "./db";
|
||||
import { redirectSafe } from "./foundation/security";
|
||||
import { prisma } from "./prisma";
|
||||
|
||||
// Re-export PERMS from the standalone file (safe for client components)
|
||||
export { PERMS } from "./permission-slugs";
|
||||
@@ -32,7 +33,7 @@ function createEmptySet(): PermissionSet {
|
||||
*/
|
||||
const getCachedPermissionSlugs = unstable_cache(
|
||||
async (userId: number, rank: number): Promise<string[]> => {
|
||||
const rows = await prisma.$queryRaw<{ slug: string }[]>`
|
||||
const [result] = await db.execute<{ slug: string }>(sql`
|
||||
SELECT DISTINCT p.slug
|
||||
FROM acl_model_permissions mp
|
||||
JOIN acl_permissions p ON p.id = mp.permission_id
|
||||
@@ -46,7 +47,8 @@ const getCachedPermissionSlugs = unstable_cache(
|
||||
FROM acl_roles ar
|
||||
WHERE ar.slug = ${`rank_${rank}`}
|
||||
)
|
||||
`;
|
||||
`);
|
||||
const rows = result as unknown as { slug: string }[];
|
||||
return rows.map((r) => r.slug);
|
||||
},
|
||||
["user-permissions"],
|
||||
@@ -100,14 +102,27 @@ export const loadUserPermissions = cache(async function loadUserPermissions(
|
||||
|
||||
const getCurrentAuthorizationState = cache(async (userId: number) =>
|
||||
resolveAuthorizationState(userId, {
|
||||
user: prisma.user,
|
||||
user: {
|
||||
findUnique: async ({ where }) => {
|
||||
const [row] = await db
|
||||
.select({
|
||||
id: User.id,
|
||||
username: User.username,
|
||||
rank: User.rank,
|
||||
})
|
||||
.from(User)
|
||||
.where(eq(User.id, where.id))
|
||||
.limit(1);
|
||||
return row ?? null;
|
||||
},
|
||||
},
|
||||
highestRank: async () => {
|
||||
// Prefer the highest rank actually held by a user. Unused high IDs in
|
||||
// permission_ranks (common on Habbo DBs) would otherwise lock the real
|
||||
// owner out of super-admin / permissions management.
|
||||
const rows = await prisma.$queryRaw<
|
||||
{ highest_rank: number | bigint | null }[]
|
||||
>`
|
||||
const [result] = await db.execute<{
|
||||
highest_rank: number | bigint | null;
|
||||
}>(sql`
|
||||
SELECT COALESCE(
|
||||
(
|
||||
SELECT MAX(u.\`rank\`)
|
||||
@@ -116,7 +131,10 @@ const getCurrentAuthorizationState = cache(async (userId: number) =>
|
||||
),
|
||||
(SELECT MAX(id) FROM permission_ranks)
|
||||
) AS highest_rank
|
||||
`;
|
||||
`);
|
||||
const rows = result as unknown as {
|
||||
highest_rank: number | bigint | null;
|
||||
}[];
|
||||
return rows[0]?.highest_rank == null
|
||||
? null
|
||||
: Number(rows[0].highest_rank);
|
||||
|
||||
Reference in new issue
Block a user