fix(persistence): Robustes /data Volume für SQLite data.db & WAL-Dateien
All checks were successful
Build and Deploy / build (push) Successful in 1m11s
All checks were successful
Build and Deploy / build (push) Successful in 1m11s
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,5 +2,6 @@ node_modules/
|
||||
data.db
|
||||
data.db-wal
|
||||
data.db-shm
|
||||
data/
|
||||
.env
|
||||
.DS_Store
|
||||
|
||||
9
db.js
9
db.js
@@ -3,9 +3,16 @@ const path = require('path');
|
||||
const Database = require('better-sqlite3');
|
||||
const bcrypt = require('bcryptjs');
|
||||
|
||||
const dbPath = path.join(__dirname, 'data.db');
|
||||
// Verzeichnis für Persistenz sicherstellen (/data im Docker Container oder local dir)
|
||||
const dataDir = process.env.DATA_DIR || (fs.existsSync('/data') ? '/data' : __dirname);
|
||||
if (!fs.existsSync(dataDir)) {
|
||||
fs.mkdirSync(dataDir, { recursive: true });
|
||||
}
|
||||
|
||||
const dbPath = path.join(dataDir, 'data.db');
|
||||
const db = new Database(dbPath);
|
||||
|
||||
// Standard Journal Mode
|
||||
db.pragma('journal_mode = WAL');
|
||||
|
||||
// Tabellen anlegen
|
||||
|
||||
@@ -6,5 +6,7 @@ services:
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "8085:80"
|
||||
environment:
|
||||
- DATA_DIR=/data
|
||||
volumes:
|
||||
- ./data.db:/app/data.db
|
||||
- ./data:/data
|
||||
|
||||
Reference in New Issue
Block a user