mirror of
https://github.com/R0m1k3/Menu.git
synced 2026-10-17 12:16:20 +02:00
feat: implement Prisma SQLite adapter, upgrade to Node 22, and improve container initialization and permissions
This commit is contained in:
1 parent
3f15c228f8
commit
9d4b1dabae
4 files changed
+52
-18
No files matched your search
@@ -4,10 +4,31 @@ import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3';
|
||||
const globalForPrisma = global as unknown as { prisma: PrismaClient };
|
||||
|
||||
const createPrismaClient = () => {
|
||||
const dbUrl = process.env.DATABASE_URL || 'file:./dev.db';
|
||||
const adapter = new PrismaBetterSqlite3({ url: dbUrl });
|
||||
|
||||
return new PrismaClient({ adapter });
|
||||
try {
|
||||
const dbUrl = process.env.DATABASE_URL || 'file:/app/prisma/dev.db';
|
||||
const filePath = dbUrl.replace('file:', '');
|
||||
|
||||
console.log(`[DB Init] Attempting to connect to SQLite at: ${filePath}`);
|
||||
|
||||
// Check if the URL is valid
|
||||
if (!filePath) {
|
||||
throw new Error("DATABASE_URL must be provided and contain a valid path.");
|
||||
}
|
||||
|
||||
const adapter = new PrismaBetterSqlite3({ url: dbUrl });
|
||||
|
||||
const client = new PrismaClient({
|
||||
adapter,
|
||||
log: ['error', 'warn']
|
||||
});
|
||||
|
||||
console.log(`[DB Init] Prisma Client initialized successfully with adapter.`);
|
||||
return client;
|
||||
} catch (error) {
|
||||
console.error(`[DB Init Error] Critical failure during database initialization:`, error);
|
||||
// Rethrow to let Next.js handle the server component error
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const prisma = globalForPrisma.prisma || createPrismaClient();
|
||||
|
||||
Reference in new issue
Block a user