File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1313 deploy-to-production :
1414 name : Deploy to Server & Run Migrations
1515 runs-on : ubuntu-latest
16- environment : server_pustipd
16+ environment : staging
1717
1818 steps :
1919 - name : Checkout repository
7676 docker network inspect minigrafana-net >/dev/null 2>&1 || docker network create minigrafana-net
7777
7878 # Menjalankan migrasi Drizzle secara terisolasi ke database production
79- docker run --rm --network minigrafana-net --env-file backend/.env ghcr.io/${{ github.repository }}-backend:latest bun run db:migrate
79+ docker run --rm --network minigrafana-net --env-file backend/.env ghcr.io/${{ github.repository }}-backend:latest bun run db:migrate:prod
8080
8181 echo "=========================================================="
8282 echo " [5/5] Merestart Container Aplikasi Backend"
Original file line number Diff line number Diff line change 1212 deploy-frontend :
1313 name : Deploy Frontend Stack via SSH
1414 runs-on : ubuntu-latest
15- environment : server_pustipd
15+ environment : staging
1616
1717 steps :
1818 - name : Checkout repository
Original file line number Diff line number Diff line change 1313 deploy-monitoring :
1414 name : Deploy Monitoring Stack via SSH
1515 runs-on : ubuntu-latest
16- environment : server_pustipd
16+ environment : staging
1717
1818 steps :
1919 - name : Checkout repository
Original file line number Diff line number Diff line change 1313 deploy-ollama :
1414 name : Deploy Ollama Stack via SSH
1515 runs-on : ubuntu-latest
16- environment : server_pustipd
16+ environment : staging
1717
1818 steps :
1919 - name : Checkout repository
Original file line number Diff line number Diff line change 1919 "test:e2e" : " jest --config ./test/jest-e2e.json" ,
2020 "db:generate" : " drizzle-kit generate" ,
2121 "db:migrate" : " drizzle-kit migrate" ,
22+ "db:migrate:prod" : " node dist/db/migrate.js" ,
2223 "db:push" : " drizzle-kit push" ,
2324 "db:studio" : " drizzle-kit studio"
2425 },
3233 "class-transformer" : " ^0.5.1" ,
3334 "class-validator" : " ^0.15.1" ,
3435 "dotenv" : " ^17.4.2" ,
35- "drizzle-orm" : " ^1.0.0-rc.4 " ,
36+ "drizzle-orm" : " ^0.45.2 " ,
3637 "nestjs-pino" : " ^4.6.1" ,
3738 "pg" : " ^8.22.0" ,
3839 "pino" : " ^10.3.1" ,
40+ "postgres" : " ^3.4.9" ,
3941 "reflect-metadata" : " ^0.2.2" ,
4042 "rxjs" : " ^7.8.1"
4143 },
Original file line number Diff line number Diff line change 1+ // src/db/migrate.ts
2+ import { drizzle } from 'drizzle-orm/postgres-js' ;
3+ import { migrate } from 'drizzle-orm/postgres-js/migrator' ;
4+ import postgres from 'postgres' ;
5+ import * as dotenv from 'dotenv' ;
6+
7+ dotenv . config ( ) ;
8+
9+ async function runMigration ( ) {
10+ console . log ( '--- ⏳ Running Production Database Migrations ---' ) ;
11+
12+ // Gunakan max 1 connection khusus untuk migrasi
13+ const migrationClient = postgres ( process . env . DATABASE_URL ! , { max : 1 } ) ;
14+ const db = drizzle ( migrationClient ) ;
15+
16+ try {
17+ // Membaca folder SQL migrasi dan mengeksekusi ke PostgreSQL
18+ await migrate ( db , { migrationsFolder : './drizzle' } ) ;
19+ console . log ( '--- ✅ Migrations Completed Successfully! ---' ) ;
20+ process . exit ( 0 ) ;
21+ } catch ( error ) {
22+ console . error ( '--- ❌ Migration Failed! ---' , error ) ;
23+ process . exit ( 1 ) ;
24+ }
25+ }
26+
27+ runMigration ( ) ;
Original file line number Diff line number Diff line change 1+ import "dotenv/config" ;
2+ import { defineConfig } from "drizzle-kit" ;
3+
4+ export default defineConfig ( {
5+ out : "./drizzle" ,
6+ schema : "./src/lib/db/schema.ts" ,
7+ dialect : "postgresql" ,
8+ dbCredentials : {
9+ url : process . env . DATABASE_URL ! ,
10+ } ,
11+ } ) ;
You can’t perform that action at this time.
0 commit comments