Skip to content

Latest commit

 

History

History
66 lines (48 loc) · 2.64 KB

File metadata and controls

66 lines (48 loc) · 2.64 KB

Railway Deployment Speed Optimizations

Changes Made

1. Removed Redundant Prisma Generation

  • Before: prisma generate ran in both postinstall script AND build script
  • After: prisma generate only runs once during the install phase (via nixpacks.toml)
  • Impact: Saves ~10-20 seconds per deployment

2. Removed prisma db push from Start Command

  • Before: prisma db push ran on every app start/restart (slow database operation)
  • After: Start command only runs next start (fast)
  • Impact: Saves 30-60 seconds on every restart/deployment

3. Added NIXPACKS Configuration

  • Created nixpacks.toml to optimize build caching
  • Uses npm ci instead of npm install for faster, reproducible installs
  • Explicitly sets Node.js version for consistency
  • Impact: Better caching, faster installs

4. Added .railwayignore

  • Excludes unnecessary files from upload (node_modules, .next, etc.)
  • Impact: Faster upload times

Database Schema Updates

Note: prisma db push syncs your database schema with your Prisma schema file - it's not for data migration. Since Railway is your main/production database, you only need to run this when you change your Prisma schema.

When to run: Only when you modify prisma/schema.prisma (add/remove models, change fields, etc.)

Option 1: Railway CLI (Recommended)

railway run npm run railway:deploy

Option 2: Railway Dashboard

  1. Go to your Railway project
  2. Open the service
  3. Click "Deployments" → "Latest" → "View Logs"
  4. Use the "Run Command" feature to execute: npm run railway:deploy

Why this is better: Running prisma db push on every deployment was slow and unnecessary. Now it only runs when you explicitly need to update the schema.

Expected Performance Improvements

  • Build time: Reduced by ~20-30 seconds (removed redundant Prisma generation)
  • Start time: Reduced by ~30-60 seconds (removed db push from start)
  • Total deployment: Should now take 1-2 minutes instead of 3+ minutes

Testing the Changes

  1. Push these changes to your repository
  2. Railway will automatically trigger a new deployment
  3. Monitor the build logs to see the improved times
  4. Your app will start faster since it's not running prisma db push on every start
  5. Only run prisma db push manually when you modify your Prisma schema:
    railway run npm run railway:deploy

Notes

  • The railway:deploy script runs prisma db push --skip-generate (skips generation since it's already done)
  • For local development, migrations still work the same way
  • The postinstall script was removed to avoid double generation