Skip to content

Commit 8d8720e

Browse files
ci: update to staging environemnt
- chore: update migration to drizzle-orm migration
1 parent b0887e8 commit 8d8720e

8 files changed

Lines changed: 51 additions & 8 deletions

File tree

.github/workflows/deploy-backend.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
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
@@ -76,7 +76,7 @@ jobs:
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"

.github/workflows/deploy-frontend.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
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

.github/workflows/deploy-monitoring.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
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

.github/workflows/deploy-ollama.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
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

backend/bun.lock

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
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
},
@@ -32,10 +33,11 @@
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
},

backend/src/lib/db/migrate.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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();

drizzle.config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
});

0 commit comments

Comments
 (0)