Skip to content

Commit 0d36d37

Browse files
committed
Refactor database handling to use Prisma
- Replace Drizzle ORM with Prisma for database interactions, including migration and CRUD operations. - Update package.json to include Prisma dependencies and adjust scripts for database commands. - Modify Dockerfile to accommodate Prisma client generation and adjust build stages. - Remove obsolete drizzle configuration and migration files. - Update API routes to utilize Prisma for database queries and mutations. - Enhance type definitions to align with Prisma models.
1 parent 672b312 commit 0d36d37

File tree

24 files changed

+272
-489
lines changed

24 files changed

+272
-489
lines changed

apps/web/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
out/
44

55
# typescript
6-
next-env.d.ts
6+
next-env.d.ts
7+
/src/generated/prisma

apps/web/Dockerfile

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,77 @@
1-
# Stage 1: Dependencies
2-
FROM public.ecr.aws/lambda/nodejs:18-x86_64 AS deps
1+
# syntax=docker/dockerfile:1
2+
3+
# ==========================================
4+
# BASE STAGE - Common setup for all stages
5+
# ==========================================
6+
FROM oven/bun:1 AS base
37
WORKDIR /app
48

5-
# Install unzip (required for Bun installer) and Bun
6-
RUN yum update -y && yum install -y unzip && \
7-
curl -fsSL https://bun.sh/install | bash && \
8-
ln -s /root/.bun/bin/bun /usr/local/bin/bun
9+
# ==========================================
10+
# DEPS STAGE - Install production dependencies
11+
# ==========================================
12+
FROM base AS deps
13+
# Copy package files for dependency installation
14+
COPY package.json bun.lockb* ./
15+
# Install production dependencies only
16+
RUN bun install --frozen-lockfile --production
17+
18+
# ==========================================
19+
# BUILD STAGE - Build the Next.js application
20+
# ==========================================
21+
FROM base AS builder
22+
WORKDIR /app
923

10-
# Copy only package files first (for better caching)
11-
COPY package.json bun.lock* ./
24+
# Copy package files
25+
COPY package.json bun.lockb* ./
26+
# Install all dependencies (including devDependencies needed for build)
1227
RUN bun install --frozen-lockfile
1328

14-
# Stage 2: Builder
15-
FROM public.ecr.aws/lambda/nodejs:18-x86_64 AS builder
16-
WORKDIR /app
29+
# Copy source code
30+
COPY . .
1731

18-
# Install unzip (required for Bun installer) and Bun
19-
RUN yum update -y && yum install -y unzip && \
20-
curl -fsSL https://bun.sh/install | bash && \
21-
ln -s /root/.bun/bin/bun /usr/local/bin/bun
32+
# Copy Prisma schema and generate client
33+
COPY prisma ./prisma
34+
RUN bunx prisma generate
2235

23-
# Accept DATABASE_URL as build argument
36+
# Build arguments for compile-time environment variables
2437
ARG DATABASE_URL
25-
ENV DATABASE_URL=$DATABASE_URL
26-
ENV NODE_ENV=production
38+
ARG NODE_ENV=production
2739

28-
# Copy dependencies from previous stage
29-
COPY --from=deps /app/node_modules ./node_modules
30-
COPY . .
40+
# Set environment variables for build
41+
ENV DATABASE_URL=$DATABASE_URL
42+
ENV NODE_ENV=$NODE_ENV
43+
ENV NEXT_TELEMETRY_DISABLED=1
3144

3245
# Build the application
3346
RUN bun run build
3447

35-
# Stage 3: Runner
36-
FROM public.ecr.aws/lambda/nodejs:18-x86_64 AS runner
48+
# ==========================================
49+
# RUNNER STAGE - Production runtime
50+
# ==========================================
51+
FROM base AS runner
3752
WORKDIR /app
3853

39-
# Install unzip (required for Bun installer) and Bun
40-
RUN yum update -y && yum install -y unzip && \
41-
curl -fsSL https://bun.sh/install | bash && \
42-
ln -s /root/.bun/bin/bun /usr/local/bin/bun
43-
54+
# Set production environment
4455
ENV NODE_ENV=production
4556
ENV NEXT_TELEMETRY_DISABLED=1
57+
ENV PORT=3000
58+
ENV HOSTNAME="0.0.0.0"
4659

47-
# Cache bust to force rebuild
48-
LABEL build_date="2024-12-08-15:08"
60+
# Create non-root user for security
61+
RUN addgroup --system --gid 1001 nodejs && \
62+
adduser --system --uid 1001 nextjs
4963

50-
# Copy only necessary files
64+
# Copy necessary files from builder stage
5165
COPY --from=builder /app/public ./public
52-
COPY --from=builder /app/.next/standalone ./
53-
COPY --from=builder /app/.next/static ./.next/static
66+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
67+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
5468

55-
# Copy migration files and scripts for database migrations
56-
COPY --from=builder /app/src ./src
57-
COPY --from=builder /app/scripts ./scripts
58-
COPY --from=builder /app/package.json ./package.json
59-
COPY --from=builder /app/drizzle.config.ts ./drizzle.config.ts
60-
COPY --from=builder /app/node_modules ./node_modules
69+
# Switch to non-root user
70+
USER nextjs
6171

72+
# Expose the application port
6273
EXPOSE 3000
6374

64-
ENV PORT=3000
65-
ENV HOSTNAME="0.0.0.0"
66-
75+
# Start the application
6776
CMD ["bun", "server.js"]
6877

apps/web/buildspec.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,16 @@ phases:
1717
- echo "DATABASE_URL length:" ${#DATABASE_URL}
1818
- echo "DATABASE_URL (masked):" $(echo "$DATABASE_URL" | sed 's/:[^@]*@/:***@/')
1919
- echo "NODE_ENV:" $NODE_ENV
20-
21-
# === FIX FOR AWS RDS SSL CERTIFICATE ===
22-
# AWS RDS uses self-signed certificates, we need to configure SSL properly
23-
- export PGSSLMODE=require
24-
- export NODE_TLS_REJECT_UNAUTHORIZED=0
25-
- echo "PGSSLMODE set to:" $PGSSLMODE
26-
- echo "NODE_TLS_REJECT_UNAUTHORIZED set to:" $NODE_TLS_REJECT_UNAUTHORIZED
27-
2820
- cd apps/web
2921

3022
- echo "=== INSTALLING DEPENDENCIES ==="
23+
- export PGSSLMODE=require
24+
- export NODE_TLS_REJECT_UNAUTHORIZED=0
3125
- SKIP_ENV_VALIDATION=true /root/.bun/bin/bun install --frozen-lockfile
3226

27+
- echo "=== GENERATING PRISMA CLIENT ==="
28+
- npx prisma generate
29+
3330
- echo "=== RUNNING DATABASE MIGRATIONS ==="
3431
- echo "Running migrations before build..."
3532
- /root/.bun/bin/bun run db:migrate:runtime

0 commit comments

Comments
 (0)