diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 98edc95..9ca238e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,8 +32,6 @@ jobs: - name: Prisma validate run: npx prisma validate - env: - DATABASE_URL: file:./dev.db - name: Test run: npm test @@ -41,6 +39,68 @@ jobs: - name: Build run: npm run build env: - DATABASE_URL: file:./dev.db - DIRECT_URL: file:./dev.db - SESSION_SECRET: ${{ secrets.SESSION_SECRET || 'ci-placeholder-secret-must-be-32-chars-min' }} + DATABASE_URL: ${{ secrets.DATABASE_URL }} + DIRECT_URL: ${{ secrets.DIRECT_URL }} + SESSION_SECRET: ${{ secrets.SESSION_SECRET }} + + deploy-preview: + name: Deploy Preview (PR) + runs-on: ubuntu-latest + needs: ci + if: github.event_name == 'pull_request' + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Install Vercel CLI + run: npm install -g vercel@latest + + - name: Deploy Preview to Vercel + run: vercel deploy --token=${{ secrets.VERCEL_TOKEN }} + env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + + deploy-production: + name: Deploy Production (main) + runs-on: ubuntu-latest + needs: ci + if: github.ref == 'refs/heads/main' && github.event_name == 'push' + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Install Vercel CLI + run: npm install -g vercel@latest + + - name: Run database migrations + run: npx prisma migrate deploy + env: + DATABASE_URL: ${{ secrets.DATABASE_URL }} + DIRECT_URL: ${{ secrets.DIRECT_URL }} + + - name: Deploy Production to Vercel + run: vercel deploy --prod --token=${{ secrets.VERCEL_TOKEN }} + env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} diff --git a/prisma.config.ts b/prisma.config.ts index f178e82..f4b4cb4 100644 --- a/prisma.config.ts +++ b/prisma.config.ts @@ -13,5 +13,6 @@ export default defineConfig({ }, datasource: { url: process.env.DATABASE_URL!, + directUrl: process.env.DIRECT_URL, }, }) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 61bee86..4f5a1c3 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -3,7 +3,9 @@ generator client { } datasource db { - provider = "sqlite" + provider = "postgresql" + url = env("DATABASE_URL") + directUrl = env("DIRECT_URL") } enum Role { diff --git a/prisma/seed.ts b/prisma/seed.ts index 30d5dd1..d58183f 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -1,5 +1,4 @@ import { PrismaClient } from '@prisma/client' -import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3' import * as dotenv from 'dotenv' import * as path from 'path' import * as bcrypt from 'bcryptjs' @@ -15,9 +14,19 @@ async function main() { const url = process.env.DATABASE_URL if (!url) throw new Error('DATABASE_URL is not set. Check .env.local') - // For SQLite: adapter takes a config object with url - const adapter = new PrismaBetterSqlite3({ url }) - prisma = new PrismaClient({ adapter }) + if (url.startsWith('file:')) { + // SQLite (local development) + const { PrismaBetterSqlite3 } = await import('@prisma/adapter-better-sqlite3') + const adapter = new PrismaBetterSqlite3({ url }) + prisma = new PrismaClient({ adapter }) + } else { + // PostgreSQL (Neon / production) + const { Pool } = await import('pg') + const { PrismaPg } = await import('@prisma/adapter-pg') + const pool = new Pool({ connectionString: url }) + const adapter = new PrismaPg(pool) + prisma = new PrismaClient({ adapter }) + } console.log('Seeding database...')