feat: implement Docker support with entrypoint script and environment configuration for data directory

This commit is contained in:
2025-11-13 03:07:03 +01:00
parent 5afd604e85
commit 23cdc27ffd
6 changed files with 113 additions and 5 deletions

View File

@@ -7,7 +7,10 @@
"dev": "nodemon server.js",
"start": "node server.js",
"prisma:generate": "prisma generate",
"prisma:migrate": "prisma migrate dev --name init"
"prisma:migrate-dev": "prisma migrate dev --name init",
"prisma:migrate-deploy": "prisma migrate deploy",
"prisma:studio": "prisma studio",
"prisma:deploy": "npx prisma migrate deploy && npx prisma generate"
},
"dependencies": {
"@prisma/client": "^6.19.0",

View File

@@ -1,6 +1,6 @@
datasource db {
provider = "sqlite"
url = "file:../data/sqlite.db"
url = env("DATABASE_URL")
}
generator client {

View File

@@ -5,8 +5,6 @@ const path = require('path')
const cors = require('cors')
const { PrismaClient } = require('@prisma/client')
const prisma = new PrismaClient()
// small, configurable logger used across the app
const LOG_LEVEL = (process.env.LOG_LEVEL || 'info').toLowerCase() // 'error'|'info'|'debug'
const levels = { error: 0, info: 1, debug: 2 }
@@ -22,7 +20,7 @@ const log = {
},
}
// store all runtime data under backend/data
// store runtime data under DATA_DIR env if provided, else backend/data
const DATA_DIR = process.env.DATA_DIR
? path.resolve(process.env.DATA_DIR)
: path.join(__dirname, 'data')
@@ -33,6 +31,14 @@ const UPLOAD_DIR = path.join(DATA_DIR, 'uploads')
if (!fs.existsSync(DATA_DIR)) fs.mkdirSync(DATA_DIR, { recursive: true })
if (!fs.existsSync(UPLOAD_DIR)) fs.mkdirSync(UPLOAD_DIR, { recursive: true })
// ensure DATABASE_URL points to the DB under DATA_DIR for Prisma at runtime
if (!process.env.DATABASE_URL) {
process.env.DATABASE_URL = `file:${path.join(DATA_DIR, 'sqlite.db')}`
}
// instantiate Prisma client AFTER DATA_DIR / DATABASE_URL are ready
const prisma = new PrismaClient()
const upload = multer({ dest: UPLOAD_DIR }) // local storage for uploads
const app = express()