Implementiere robuste JSON-Fallback für SQLite-Datenbankprobleme

- Füge JSON-Fallback-Datenbank hinzu als Alternative wenn SQLite-Bindings nicht kompilieren
- Verbessere Startup-Skript mit automatischem SQLite-Rebuild beim Start
- Füge Fehlerbehandlung und Logging für Datenbankprobleme hinzu
- Aktualisiere Migrationsskript, um beide Datenbanktypen zu unterstützen
- Ersetze fehlerhaften npx-Install im Dockerfile (bereits in Node enthalten)

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-04-01 11:07:42 +02:00
parent de163719aa
commit 1f6feafecc
5 changed files with 162 additions and 21 deletions

View File

@@ -23,8 +23,7 @@ ENV CFLAGS="-fPIC" \
RUN pnpm install --unsafe-perm --no-optional --frozen-lockfile
# Hinweis: better-sqlite3 neu bauen verursacht Fehler mit Node 23.10
# Verwende eine alternative Lösung
RUN npm install -g npx
# npx ist bereits in Node.js integriert - kein zusätzlicher Install nötig
# Install tsx for running TypeScript files directly
RUN pnpm add -D tsx
@@ -41,7 +40,7 @@ RUN pnpm build || echo "Generate schema failed, but continuing..."
# Expose the port
EXPOSE 3000
# Startup script with fallback to JSON based approach
# Startup script with robust JSON fallback approach
RUN echo '#!/bin/sh' > /app/startup.sh && \
echo 'set -e' >> /app/startup.sh && \
echo 'mkdir -p /app/db' >> /app/startup.sh && \
@@ -64,9 +63,17 @@ RUN echo '#!/bin/sh' > /app/startup.sh && \
echo 'export DB_JSON_PATH=$DB_JSON' >> /app/startup.sh && \
echo 'echo "Datenbank wird unter $DB_PATH verwendet"' >> /app/startup.sh && \
echo 'echo "JSON Fallback unter $DB_JSON_PATH"' >> /app/startup.sh && \
echo '' >> /app/startup.sh && \
echo '# Try to rebuild better-sqlite3 for current platform, but continue if it fails' >> /app/startup.sh && \
echo 'if [ ! -d "/app/node_modules/.pnpm/better-sqlite3@9.6.0/node_modules/better-sqlite3/build" ]; then' >> /app/startup.sh && \
echo ' echo "SQLite Bindings nicht gefunden, versuche sie zu bauen..."' >> /app/startup.sh && \
echo ' cd /app && CFLAGS="-fPIC" LDFLAGS="-fPIC" CXXFLAGS="-fPIC" npm_config_build_from_source=true npm_config_sqlite=/usr/local npm_config_sqlite_libname=sqlite3 pnpm rebuild better-sqlite3 || echo "SQLite Rebuild fehlgeschlagen - wird JSON-Fallback verwenden"' >> /app/startup.sh && \
echo 'fi' >> /app/startup.sh && \
echo '' >> /app/startup.sh && \
echo 'echo "Führe Datenbank-Migration aus..."' >> /app/startup.sh && \
echo 'NODE_ENV=production npx tsx ./src/server/db/migrate.ts || echo "SQLite Migration fehlgeschlagen - wird beim Neustart erneut versucht"' >> /app/startup.sh && \
echo 'echo "Migration abgeschlossen"' >> /app/startup.sh && \
echo '' >> /app/startup.sh && \
echo 'echo "Starte Next.js Anwendung..."' >> /app/startup.sh && \
echo 'if [ -d ".next" ]; then' >> /app/startup.sh && \
echo ' NODE_OPTIONS="--no-warnings" pnpm start' >> /app/startup.sh && \