fix: prisma db push 移到启动时执行(保留用户数据)

构建时执行会覆盖用户拷贝的数据库文件,
改为容器启动时执行,已有数据则跳过。
This commit is contained in:
胡旭
2026-06-24 16:48:07 +08:00
parent e6839da566
commit 92d190a081
2 changed files with 16 additions and 2 deletions
+4 -2
View File
@@ -18,7 +18,6 @@ RUN npm install -g pnpm@9
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ENV NEXT_TELEMETRY_DISABLED=1
RUN pnpm exec prisma db push --skip-generate
RUN pnpm build
# ── 运行层 ──
@@ -47,4 +46,7 @@ EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]
COPY start.sh ./start.sh
RUN chmod +x ./start.sh
CMD ["sh", "./start.sh"]
+12
View File
@@ -0,0 +1,12 @@
#!/bin/sh
# 启动前确保数据库表存在
node -e "
const { execSync } = require('child_process');
try {
execSync('npx prisma db push --skip-generate', { stdio: 'inherit' });
} catch (e) {
console.error('prisma db push failed:', e.message);
}
"
# 启动应用
exec node server.js