feat: PostgreSQL support en Vercel CI/CD deployment
- Prisma schema: sqlite → postgresql provider met directUrl - prisma.config.ts: directUrl toegevoegd - seed.ts: dynamisch SQLite of PostgreSQL adapter op basis van DATABASE_URL - ci.yml: preview deploy op PR, productie deploy op push naar main Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
d11b114fc1
commit
08de004ae7
4 changed files with 82 additions and 10 deletions
70
.github/workflows/ci.yml
vendored
70
.github/workflows/ci.yml
vendored
|
|
@ -32,8 +32,6 @@ jobs:
|
||||||
|
|
||||||
- name: Prisma validate
|
- name: Prisma validate
|
||||||
run: npx prisma validate
|
run: npx prisma validate
|
||||||
env:
|
|
||||||
DATABASE_URL: file:./dev.db
|
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: npm test
|
run: npm test
|
||||||
|
|
@ -41,6 +39,68 @@ jobs:
|
||||||
- name: Build
|
- name: Build
|
||||||
run: npm run build
|
run: npm run build
|
||||||
env:
|
env:
|
||||||
DATABASE_URL: file:./dev.db
|
DATABASE_URL: ${{ secrets.DATABASE_URL }}
|
||||||
DIRECT_URL: file:./dev.db
|
DIRECT_URL: ${{ secrets.DIRECT_URL }}
|
||||||
SESSION_SECRET: ${{ secrets.SESSION_SECRET || 'ci-placeholder-secret-must-be-32-chars-min' }}
|
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 }}
|
||||||
|
|
|
||||||
|
|
@ -13,5 +13,6 @@ export default defineConfig({
|
||||||
},
|
},
|
||||||
datasource: {
|
datasource: {
|
||||||
url: process.env.DATABASE_URL!,
|
url: process.env.DATABASE_URL!,
|
||||||
|
directUrl: process.env.DIRECT_URL,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,9 @@ generator client {
|
||||||
}
|
}
|
||||||
|
|
||||||
datasource db {
|
datasource db {
|
||||||
provider = "sqlite"
|
provider = "postgresql"
|
||||||
|
url = env("DATABASE_URL")
|
||||||
|
directUrl = env("DIRECT_URL")
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Role {
|
enum Role {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import { PrismaClient } from '@prisma/client'
|
import { PrismaClient } from '@prisma/client'
|
||||||
import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3'
|
|
||||||
import * as dotenv from 'dotenv'
|
import * as dotenv from 'dotenv'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import * as bcrypt from 'bcryptjs'
|
import * as bcrypt from 'bcryptjs'
|
||||||
|
|
@ -15,9 +14,19 @@ async function main() {
|
||||||
const url = process.env.DATABASE_URL
|
const url = process.env.DATABASE_URL
|
||||||
if (!url) throw new Error('DATABASE_URL is not set. Check .env.local')
|
if (!url) throw new Error('DATABASE_URL is not set. Check .env.local')
|
||||||
|
|
||||||
// For SQLite: adapter takes a config object with url
|
if (url.startsWith('file:')) {
|
||||||
const adapter = new PrismaBetterSqlite3({ url })
|
// SQLite (local development)
|
||||||
prisma = new PrismaClient({ adapter })
|
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...')
|
console.log('Seeding database...')
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue