fix: referral-service启动时自动执行seed

- 添加ts-node依赖用于执行seed.ts
- 在start.sh中添加prisma db seed命令
- 与identity-service保持一致

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-21 17:19:16 -08:00
parent f98f7b2d39
commit 17121da422
1 changed files with 6 additions and 3 deletions

View File

@ -41,9 +41,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
&& rm -rf /var/lib/apt/lists/*
# Install production dependencies only
# Install production dependencies + ts-node for seed
COPY package*.json ./
RUN npm ci --only=production
COPY tsconfig*.json ./
RUN npm ci --only=production && npm install ts-node typescript @types/node --save-dev
# Copy Prisma schema and generate client (dummy DATABASE_URL for build time only)
COPY prisma ./prisma/
@ -52,11 +53,13 @@ RUN DATABASE_URL="postgresql://user:pass@localhost:5432/db" npx prisma generate
# Copy built files
COPY --from=builder /app/dist ./dist
# Create startup script that runs migrations before starting the app
# Create startup script that runs migrations and seed before starting the app
RUN echo '#!/bin/sh\n\
set -e\n\
echo "Running database migrations..."\n\
npx prisma migrate deploy || npx prisma db push --accept-data-loss\n\
echo "Running database seed..."\n\
npx prisma db seed || echo "Seed completed (or already seeded)"\n\
echo "Starting application..."\n\
exec node dist/main.js\n' > /app/start.sh && chmod +x /app/start.sh