mirror of
https://github.com/R0m1k3/Menu.git
synced 2026-10-11 17:28:28 +02:00
feat: initialize Prisma schema with Config and Button models
This commit is contained in:
1 parent
ca99378348
commit
485aba96fd
10 files changed
+408
-241
No files matched your search
+11
-4
@@ -3,8 +3,7 @@ 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).
|
||||
* Safe to run multiple times — uses IF NOT EXISTS and handles migrations.
|
||||
*/
|
||||
export function initializeDatabase(): void {
|
||||
const dbUrl = process.env.DATABASE_URL || 'file:/app/prisma/dev.db';
|
||||
@@ -18,7 +17,7 @@ export function initializeDatabase(): void {
|
||||
try {
|
||||
const db = new Database(resolvedPath);
|
||||
|
||||
// Create Config table
|
||||
// Config table
|
||||
db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS "Config" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
@@ -26,7 +25,7 @@ export function initializeDatabase(): void {
|
||||
);
|
||||
`);
|
||||
|
||||
// Create Button table
|
||||
// Button table (base)
|
||||
db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS "Button" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
@@ -36,6 +35,14 @@ export function initializeDatabase(): void {
|
||||
);
|
||||
`);
|
||||
|
||||
// Migration: add icon column if missing (added in v2)
|
||||
try {
|
||||
db.exec(`ALTER TABLE "Button" ADD COLUMN "icon" TEXT;`);
|
||||
console.log('[DB Init] Migration applied: Button.icon column added.');
|
||||
} catch {
|
||||
// Column already exists — no action needed
|
||||
}
|
||||
|
||||
db.close();
|
||||
console.log('[DB Init] Schema ready.');
|
||||
} catch (err) {
|
||||
|
||||
Reference in new issue
Block a user