From db27943785682bb368c369f24185a6b062f0bf51 Mon Sep 17 00:00:00 2001 From: elpatron Date: Mon, 12 Jan 2026 22:40:38 +0100 Subject: [PATCH] fix: force absolute database path via environment variable to prevent data loss on container update --- Dockerfile | 9 +++++++-- prisma/schema.prisma | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index b027187..3f1374d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,8 @@ RUN npm install # Build the application COPY . . -ENV DATABASE_URL="file:/app/data/dev.db" +# Use a temporary DB for generation +ENV DATABASE_URL="file:./temp.db" RUN npx prisma generate RUN npm run build @@ -20,6 +21,7 @@ WORKDIR /app # Set production environment ENV NODE_ENV=production ENV PORT=3000 +# Force absolute path in production ENV DATABASE_URL="file:/app/data/dev.db" # Install production dependencies only @@ -31,6 +33,8 @@ COPY --from=builder /app/.next ./.next COPY --from=builder /app/public ./public COPY --from=builder /app/next.config.mjs ./ COPY --from=builder /app/prisma ./prisma +# Copy dictionaries since they are needed at runtime +COPY --from=builder /app/dictionaries ./dictionaries COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma @@ -43,7 +47,8 @@ RUN printf "#!/bin/sh\n\ echo \"Starting initialization...\"\n\ echo \"Database URL: \$DATABASE_URL\"\n\ echo \"Running migrations...\"\n\ - npx prisma migrate deploy\n\ + # Use npx prisma migrate deploy with explicit schema path to be safe\n\ + npx prisma migrate deploy --schema ./prisma/schema.prisma\n\ echo \"Starting application...\"\n\ npm start" > /app/start.sh diff --git a/prisma/schema.prisma b/prisma/schema.prisma index c5ef726..0904061 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -1,6 +1,6 @@ datasource db { provider = "sqlite" - url = "file:./dev.db" + url = env("DATABASE_URL") } generator client {