mirror of
https://github.com/R0m1k3/Menu.git
synced 2026-10-16 19:56:20 +02:00
feat: replace Prisma CLI sync with raw SQL initialization and update Dockerfile dependencies
This commit is contained in:
1 parent
2fd431b907
commit
1de5448e55
4 files changed
+63
-36
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import Database from 'better-sqlite3';
|
||||
import path from 'path';
|
||||
|
||||
/**
|
||||
* Initializes the SQLite database schema using raw SQL.
|
||||
* This bypasses Prisma CLI entirely, avoiding CLI environment issues in Docker.
|
||||
* Safe to run multiple times (CREATE TABLE IF NOT EXISTS).
|
||||
*/
|
||||
export function initializeDatabase(): void {
|
||||
const dbUrl = process.env.DATABASE_URL || 'file:/app/prisma/dev.db';
|
||||
const filePath = dbUrl.replace(/^file:/, '');
|
||||
const resolvedPath = path.isAbsolute(filePath)
|
||||
? filePath
|
||||
: path.join(process.cwd(), filePath);
|
||||
|
||||
console.log(`[DB Init] Ensuring schema at: ${resolvedPath}`);
|
||||
|
||||
try {
|
||||
const db = new Database(resolvedPath);
|
||||
|
||||
// Create Config table
|
||||
db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS "Config" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"value" TEXT NOT NULL
|
||||
);
|
||||
`);
|
||||
|
||||
// Create Button table
|
||||
db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS "Button" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"name" TEXT NOT NULL,
|
||||
"url" TEXT NOT NULL,
|
||||
"order" INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
`);
|
||||
|
||||
db.close();
|
||||
console.log('[DB Init] Schema ready.');
|
||||
} catch (err) {
|
||||
console.error('[DB Init Error] Failed to initialize schema:', err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user