Fix database persistence and add analytics

- Fixed Prisma client not being available in Docker container
- Added isTestTrade flag to exclude test trades from analytics
- Created analytics views for net positions (matches Drift UI netting)
- Added API endpoints: /api/analytics/positions and /api/analytics/stats
- Added test trade endpoint: /api/trading/test-db
- Updated Dockerfile to properly copy Prisma client from builder stage
- Database now successfully stores all trades with full details
- Supports position netting calculations to match Drift perpetuals behavior
This commit is contained in:
mindesbunister
2025-10-27 09:35:01 +01:00
parent 1da5db5e75
commit 8e5c592cac
9 changed files with 589 additions and 8 deletions

View File

@@ -27,10 +27,19 @@ RUN npm install --production && \
# ================================
FROM node:20-alpine AS builder
# Install system dependencies for Prisma
RUN apk add --no-cache \
python3 \
make \
g++ \
libc6-compat \
openssl
WORKDIR /app
# Copy dependencies from deps stage
COPY --from=deps /app/node_modules ./node_modules
# Copy package files and install ALL dependencies (including dev)
COPY package*.json ./
RUN npm install
# Copy source code
COPY . .
@@ -67,8 +76,11 @@ COPY --from=builder /app/package*.json ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# Copy node_modules
COPY --from=deps --chown=nextjs:nodejs /app/node_modules ./node_modules
# Copy Prisma schema and generated client from builder
COPY --from=builder /app/prisma ./prisma
# Copy node_modules from builder (includes Prisma client)
COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules
# Set environment variables
ENV NODE_ENV production