Files
Momento/memento-note/lib/prisma.ts
Antigravity 5821e2c96f
Some checks failed
CI / Lint, Unit Tests & Build (push) Failing after 1m8s
CI / Deploy production (on server) (push) Has been skipped
fix(audit): sécurité + perf + DB — 40 problèmes adressés
SÉCURITÉ (CRITIQUE):
- link-preview: auth() obligatoire + filtre IP privées (SSRF fix)
- metrics: !metricsToken → 401 au lieu d'etre ouvert si token absent
- contextual-ai-chat: DOMPurify.sanitize() sur dangerouslySetInnerHTML (XSS fix)

PERFORMANCE:
- graph/route.ts: take:500 + orderBy updatedAt desc (pas de full table scan)
- syncAllEmbeddings: batch parallèle Promise.allSettled × 5 (pas séquentiel)
- 80 console.log supprimés du code production

BASE DE DONNÉES:
- Note: index contentUpdatedAt + isPublic ajoutés au schema
- DocumentChunk: commentaire index vectoriel HNSW (à exécuter manuellement)
2026-07-05 08:51:21 +00:00

36 lines
1.0 KiB
TypeScript

import { PrismaClient } from '@prisma/client'
const prismaClientSingleton = () => {
return new PrismaClient({
datasources: {
db: {
url: process.env.DATABASE_URL || 'postgresql://memento:memento@localhost:5432/memento',
},
},
})
}
/** Dev hot-reload can keep an old PrismaClient missing newly generated models. */
function needsFreshPrismaClient(client: PrismaClient | undefined): boolean {
if (!client) return true
return typeof (client as PrismaClient & { flashcard?: unknown }).flashcard === 'undefined'
}
declare const globalThis: {
prismaGlobal: ReturnType<typeof prismaClientSingleton>;
} & typeof global;
let prisma = globalThis.prismaGlobal ?? prismaClientSingleton()
if (process.env.NODE_ENV !== 'production') {
if (needsFreshPrismaClient(globalThis.prismaGlobal)) {
prisma = prismaClientSingleton()
}
globalThis.prismaGlobal = prisma
const models = Object.keys(prisma).filter(k => !k.startsWith('_') && !k.startsWith('$'))
}
export { prisma }
export default prisma