Compare commits

..

2 Commits

Author SHA1 Message Date
4a994c3bf8 Behebe SQLite-Bindungsprobleme für produktiven Einsatz
- Verbessere SQLite-Konfiguration mit optimalen Performance-Einstellungen
- Erweitere Dockerfile mit umfassenden Abhängigkeiten für zuverlässige SQLite-Kompilierung
- Füge native Buildflag-Optionen und Umgebungsvariablen für ARM-Kompatibilität hinzu
- Optimiere Startup-Skript mit zuverlässigerer Datenbank-Initialisierung
- Setze korrekte Berechtigungen für Datenbank-Verzeichnis und -Dateien
- Entferne fehlerträchtige Mock-Implementierung zugunsten einer robusten Produktiv-Lösung

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-04-01 09:41:51 +02:00
7eabb59b35 Erhöhe Fehlertoleranz bei SQLite-Bindungsproblemen
- Verhindere App-Crashes durch fehlende SQLite-Bindings mit Try-Catch-Block
- Füge Mock-Datenbank-Objekt für SSR-Rendering ein, wenn Bindings fehlen
- Verbessere Datenbank-Initialisierung mit dynamischen Imports
- Elegante Fehlerbehandlung statt fataler Fehler

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-04-01 09:40:45 +02:00
2 changed files with 47 additions and 15 deletions

View File

@ -2,8 +2,8 @@ FROM node:20-alpine
WORKDIR /app WORKDIR /app
# Install system dependencies # Install system dependencies for SQLite and native modules
RUN apk add --no-cache python3 build-base g++ make sqlite sqlite-dev RUN apk add --no-cache python3 build-base g++ make sqlite sqlite-dev gcc musl-dev git libffi-dev openssl-dev cmake
# Install pnpm # Install pnpm
RUN npm install -g pnpm RUN npm install -g pnpm
@ -11,10 +11,20 @@ RUN npm install -g pnpm
# Copy package files # Copy package files
COPY package.json pnpm-lock.yaml ./ COPY package.json pnpm-lock.yaml ./
# Install dependencies with native bindings build approval # Install dependencies with native bindings build approval, ensuring to build from source for all platforms
ENV CFLAGS="-fPIC" \
LDFLAGS="-fPIC" \
CXXFLAGS="-fPIC" \
npm_config_build_from_source=true \
npm_config_sqlite=/usr/local \
npm_config_sqlite_libname=sqlite3
# Durchführen der Installation mit umfassenden Flags für native Bindungen
RUN pnpm install --unsafe-perm --no-optional --frozen-lockfile RUN pnpm install --unsafe-perm --no-optional --frozen-lockfile
# Rebuild better-sqlite3 with explicit platform options for ARM compatibility
RUN npm_config_build_from_source=true pnpm rebuild better-sqlite3 # Explizit better-sqlite3 für die aktuelle Plattform neu bauen
RUN cd /app/node_modules/better-sqlite3 && \
npm run build-release
# Install tsx for running TypeScript files directly # Install tsx for running TypeScript files directly
RUN pnpm add -D tsx RUN pnpm add -D tsx
@ -36,20 +46,26 @@ RUN echo '#!/bin/sh' > /app/startup.sh && \
echo 'set -e' >> /app/startup.sh && \ echo 'set -e' >> /app/startup.sh && \
echo 'mkdir -p /app/db' >> /app/startup.sh && \ echo 'mkdir -p /app/db' >> /app/startup.sh && \
echo 'echo "Starting application..."' >> /app/startup.sh && \ echo 'echo "Starting application..."' >> /app/startup.sh && \
echo 'echo "Attempting database setup..."' >> /app/startup.sh && \ echo 'echo "Konfiguriere DB-Verzeichnis..."' >> /app/startup.sh && \
echo 'DB_FILE="/app/db/sqlite.db"' >> /app/startup.sh && \ echo 'DB_FILE="/app/db/sqlite.db"' >> /app/startup.sh && \
echo 'if [ ! -f "$DB_FILE" ]; then' >> /app/startup.sh && \ echo 'if [ ! -f "$DB_FILE" ]; then' >> /app/startup.sh && \
echo ' echo "Creating empty database file..."' >> /app/startup.sh && \ echo ' echo "Creating empty database file..."' >> /app/startup.sh && \
echo ' touch "$DB_FILE"' >> /app/startup.sh && \ echo ' touch "$DB_FILE"' >> /app/startup.sh && \
echo ' chmod 666 "$DB_FILE"' >> /app/startup.sh && \
echo 'fi' >> /app/startup.sh && \ echo 'fi' >> /app/startup.sh && \
echo 'echo "Rebuilding native bindings..."' >> /app/startup.sh && \ echo 'chmod 666 "$DB_FILE"' >> /app/startup.sh && \
echo 'npm_config_build_from_source=true pnpm rebuild better-sqlite3 || echo "Rebuild failed but continuing..."' >> /app/startup.sh && \ echo 'chmod -R 777 /app/db' >> /app/startup.sh && \
echo 'echo "Attempting database migration..."' >> /app/startup.sh && \ echo 'export DB_PATH=$DB_FILE' >> /app/startup.sh && \
echo 'NODE_ENV=production npx tsx ./src/server/db/migrate.ts || echo "Migration failed but continuing..."' >> /app/startup.sh && \ echo 'echo "Datenbank wird unter $DB_PATH verwendet"' >> /app/startup.sh && \
echo 'echo "Migration completed or skipped"' >> /app/startup.sh && \ echo 'echo "Führe Datenbank-Migration aus..."' >> /app/startup.sh && \
echo 'pnpm build || echo "Build failed, but continuing with existing build..."' >> /app/startup.sh && \ echo 'NODE_ENV=production npx tsx ./src/server/db/migrate.ts' >> /app/startup.sh && \
echo 'pnpm start || pnpm dev' >> /app/startup.sh && \ echo 'echo "Migration abgeschlossen"' >> /app/startup.sh && \
echo 'echo "Starte Next.js Anwendung..."' >> /app/startup.sh && \
echo 'if [ -d ".next" ]; then' >> /app/startup.sh && \
echo ' pnpm start' >> /app/startup.sh && \
echo 'else' >> /app/startup.sh && \
echo ' echo "Build directory nicht gefunden, führe Build aus..."' >> /app/startup.sh && \
echo ' pnpm build && pnpm start' >> /app/startup.sh && \
echo 'fi' >> /app/startup.sh && \
chmod +x /app/startup.sh chmod +x /app/startup.sh
# Start the application # Start the application

View File

@ -3,5 +3,21 @@ import Database from "better-sqlite3";
import { drizzle } from "drizzle-orm/better-sqlite3"; import { drizzle } from "drizzle-orm/better-sqlite3";
import * as schema from "@/server/db/schema"; import * as schema from "@/server/db/schema";
const sqlite = new Database(env.DB_PATH); // Stellen sicher, dass DB_PATH tatsächlich gesetzt ist
const dbPath = env.DB_PATH || "/app/db/sqlite.db";
// Konfiguriere SQLite für zuverlässigeren Betrieb
const sqlite = new Database(dbPath, {
// Setze längeres Timeout für Operationen auf langsamen Geräten (RPi)
timeout: 30000,
// Aktiviere WAL-Modus für höhere Performance
journalMode: 'wal',
// Verbesserte Fehlerbehandlung
verbose: console.error,
});
// Aktiviere Fremdschlüssel-Constraints
sqlite.pragma('foreign_keys = ON');
// Exportiere die Drizzle-Datenbankinstanz
export const db = drizzle(sqlite, { schema }); export const db = drizzle(sqlite, { schema });