mirror of
https://github.com/R0m1k3/Menu.git
synced 2026-10-11 17:28:28 +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
+62
-35
No files matched your search
+4
-1
@@ -46,11 +46,14 @@ COPY --from=builder /app/.next/static ./.next/static
|
||||
COPY --from=builder /app/prisma ./prisma
|
||||
COPY --from=builder /app/prisma.config.ts ./prisma.config.ts
|
||||
|
||||
# Explicitly copy Prisma and native node_modules (required for standalone mode)
|
||||
# Explicitly copy all native/prisma node_modules (required for standalone mode)
|
||||
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
|
||||
COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma
|
||||
COPY --from=builder /app/node_modules/better-sqlite3 ./node_modules/better-sqlite3
|
||||
COPY --from=builder /app/node_modules/bcrypt ./node_modules/bcrypt
|
||||
COPY --from=builder /app/node_modules/bindings ./node_modules/bindings
|
||||
COPY --from=builder /app/node_modules/file-uri-to-path ./node_modules/file-uri-to-path
|
||||
COPY --from=builder /app/node_modules/node-addon-api ./node_modules/node-addon-api
|
||||
|
||||
# Ensure prisma directory is accessible and writable for SQLite
|
||||
RUN mkdir -p /app/prisma && chmod -R 777 /app/prisma
|
||||
|
||||
+6
-19
@@ -1,29 +1,16 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Exit immediately if a command exits with a non-zero status
|
||||
set -e
|
||||
|
||||
echo "=== Menu Professional Entrypoint ==="
|
||||
echo "Node version: $(node -v)"
|
||||
echo "Working directory: $(pwd)"
|
||||
echo "DATABASE_URL: ${DATABASE_URL}"
|
||||
|
||||
# Check permissions
|
||||
echo "Checking prisma directory permissions..."
|
||||
ls -ld /app/prisma
|
||||
touch /app/prisma/test_write && echo "Write check: SUCCESS" && rm /app/prisma/test_write || echo "Write check: FAILED"
|
||||
# Ensure the prisma directory exists and is writable
|
||||
mkdir -p /app/prisma
|
||||
chmod -R 777 /app/prisma
|
||||
|
||||
echo "Locating Prisma engine binary..."
|
||||
find ./node_modules -name "libquery_engine*" || echo "Engine binary NOT found!"
|
||||
echo "Write check on /app/prisma..."
|
||||
touch /app/prisma/.write_test && echo "OK" && rm /app/prisma/.write_test
|
||||
|
||||
# Run database synchronization
|
||||
echo "Synchronizing database schema with Prisma..."
|
||||
# Ensure DATABASE_URL is set for the CLI
|
||||
export DATABASE_URL=${DATABASE_URL:-"file:/app/prisma/dev.db"}
|
||||
npx prisma db push --accept-data-loss || echo "Database sync failed, but proceeding..."
|
||||
|
||||
# Show database file if exists
|
||||
ls -l /app/prisma/dev.db || echo "Database file dev.db not yet created"
|
||||
|
||||
# Start the application
|
||||
echo "Launching server on port ${PORT:-3214}..."
|
||||
exec node server.js
|
||||
@@ -1,32 +1,24 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3';
|
||||
import { initializeDatabase } from './initDb';
|
||||
|
||||
const globalForPrisma = global as unknown as { prisma: PrismaClient };
|
||||
|
||||
const createPrismaClient = () => {
|
||||
try {
|
||||
const dbUrl = process.env.DATABASE_URL || 'file:/app/prisma/dev.db';
|
||||
const filePath = dbUrl.replace('file:', '');
|
||||
console.log(`[DB] Connecting to: ${dbUrl}`);
|
||||
|
||||
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.");
|
||||
}
|
||||
// Ensure schema exists before creating the Prisma client
|
||||
initializeDatabase();
|
||||
|
||||
const adapter = new PrismaBetterSqlite3({ url: dbUrl });
|
||||
const client = new PrismaClient({ adapter });
|
||||
|
||||
const client = new PrismaClient({
|
||||
adapter,
|
||||
log: ['error', 'warn']
|
||||
});
|
||||
|
||||
console.log(`[DB Init] Prisma Client initialized successfully with adapter.`);
|
||||
console.log('[DB] Prisma client ready.');
|
||||
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
|
||||
console.error('[DB] Critical initialization failure:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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