mirror of
https://github.com/dyzulk/trustlab-api.git
synced 2026-01-26 05:15:35 +07:00
feat: implement separate CA database with documentation and standardized workflows
This commit is contained in:
34
.agent/workflows/database-guidelines.md
Normal file
34
.agent/workflows/database-guidelines.md
Normal file
@@ -0,0 +1,34 @@
|
||||
---
|
||||
description: Panduan Manajemen Database (Multi-Database Architecture)
|
||||
---
|
||||
|
||||
# Aturan & Panduan Database
|
||||
|
||||
Proyek ini menggunakan arsitektur **Multi-Database** untuk memisahkan data User/App dengan data High-Security (Certificate Authority).
|
||||
|
||||
## Arsitektur
|
||||
|
||||
1. **Main Database Connection (`mysql`)**
|
||||
* **Kegunaan**: Menyimpan data aplikasi umum (`users`, `tickets`, `certificates` (leaf), dll).
|
||||
* **Reset Policy**: Boleh di-reset saat development (`php artisan migrate:fresh --seed`).
|
||||
* **Dependency**: Terikat dengan logic aplikasi utama.
|
||||
|
||||
2. **CA Database Connection (`mysql_ca`)**
|
||||
* **Kegunaan**: KHUSUS untuk `ca_certificates` (Root & Intermediate CA).
|
||||
* **Reset Policy**: **DILARANG RESET** sembarangan. Command `migrate:fresh` default TIDAK akan menyentuh database ini.
|
||||
* **Driver**: Menggunakan `mysql` di Production (sama seperti Main DB), bukan SQLite atau D1 (kecuali ada instruksi spesifik).
|
||||
|
||||
## Aturan Migrasi
|
||||
|
||||
1. **Pembuatan Tabel Baru**:
|
||||
* Tentukan tabel masuk ke kategori mana (App vs CA).
|
||||
* Jika CA, gunakan `Schema::connection('mysql_ca')->create(...)`.
|
||||
* Jika App, gunakan `Schema::create(...)` biasa.
|
||||
|
||||
2. **Data Safety**:
|
||||
* Sebelum menjalankan query raw atau operasi destructive, pastikan koneksi yang dipilih benar.
|
||||
* Gunakan command `php artisan ca:migrate-data` hanya jika perlu memindahkan data antar database.
|
||||
|
||||
## Cloudflare D1
|
||||
* Saat ini D1 **TIDAK DIGUNAKAN** untuk kompatibilitas penuh dengan server berbasis VPS/Hosting standar.
|
||||
* Jangan mengusulkan migrasi ke D1 kecuali infrastruktur berpindah ke Cloudflare Workers sepenuhnya.
|
||||
51
.agent/workflows/deployment.md
Normal file
51
.agent/workflows/deployment.md
Normal file
@@ -0,0 +1,51 @@
|
||||
---
|
||||
description: SOP Deployment (CI/CD via aaPanel)
|
||||
---
|
||||
|
||||
# Alur Kerja Deployment
|
||||
|
||||
Proyek ini menggunakan **CI/CD Otomatis** via aaPanel Webhook yang terintegrasi dengan GitHub/Git.
|
||||
|
||||
## 1. Automated Deployment (CI/CD)
|
||||
|
||||
Setiap kali Anda melakukan push ke branch `main`, script webhook di server akan berjalan.
|
||||
**Apa yang dilakukan script otomatis:**
|
||||
1. `git pull origin main`
|
||||
2. `composer install` & `npm install` + `vite build`
|
||||
3. **Update Config:** Mengcopy isi `.env.production.editable` ke `.env` (Pastikan file editable sudah benar di repo!).
|
||||
4. `php artisan migrate --force` (Main & CA Database).
|
||||
5. `php artisan optimize`.
|
||||
|
||||
**Script Reference:**
|
||||
* **Repo (Public):** `scripts/deploy-webhook.example.sh` (Template aman, gunakan ini untuk copy-paste ke aaPanel lalu edit manual).
|
||||
* **Local (Private):** `scripts/deploy-webhook.local.sh` (Backup pribadi Anda dengan path asli, ter-ignore oleh git).
|
||||
|
||||
## 2. Manual Pre-Requisites (Sebelum Push)
|
||||
|
||||
Sebelum Anda push code, pastikan:
|
||||
1. **Environment Variables**:
|
||||
* Jika ada perubahan config, update `.env.production.editable`.
|
||||
* Ingat: Script akan menimpa `.env` server dengan isi `.env.production.editable`.
|
||||
2. **Database**:
|
||||
* Jika membuat DB baru (seperti kasus CA ini), pastikan database fisik sudah dibuat di server MySQL (`CREATE DATABASE ...`).
|
||||
|
||||
## 3. Manual Post-Deployment (Intervensi Khusus)
|
||||
|
||||
Script CI/CD tidak menangani edge-cases. Anda perlu masuk ke server (SSH) untuk kasus berikut:
|
||||
|
||||
1. **Data Migration Khusus**:
|
||||
* Kasus: Memisahkan table CA ke database baru.
|
||||
* Action: Login SSH, lalu jalankan:
|
||||
```bash
|
||||
cd /www/wwwroot/trustlab-api-ftp/trustlab-api.dyzulk.com
|
||||
php artisan ca:migrate-data
|
||||
```
|
||||
|
||||
2. **Rollback**:
|
||||
* Jika deploy gagal total, Anda mungkin perlu restore backup database manual via aaPanel atau `php artisan migrate:rollback`.
|
||||
|
||||
## 4. Platform Lain (Non-aaPanel)
|
||||
Jika berpindah dari aaPanel, adaptasi script `scripts/deploy-webhook.example.sh`:
|
||||
* Ganti Path project (`PROJECT_PATH`).
|
||||
* Ganti Path PHP Binary (`PHP_BIN`).
|
||||
* Ganti mekanisme trigger (misal gunakan GitHub Actions, Jenkins, atau Laravel Forge).
|
||||
48
.agent/workflows/manage-env.md
Normal file
48
.agent/workflows/manage-env.md
Normal file
@@ -0,0 +1,48 @@
|
||||
---
|
||||
description: Memahami dan Mengelola Environment Variables (5-File System)
|
||||
---
|
||||
|
||||
# Aturan Manajemen Environment Variables
|
||||
|
||||
Proyek ini menggunakan sistem **5-File Environment** yang ketat untuk mencegah kesalahan konfigurasi produksi. AI dan Developer Wajib mengikuti aturan ini.
|
||||
|
||||
## Struktur File
|
||||
|
||||
1. **`.env`** (Local Development)
|
||||
* Digunakan untuk pengembangan visual/lokal.
|
||||
* Berisi kredensial lokal (localhost, root, dll).
|
||||
* **Aturan:** Menjadi acuan utama *struktur* dan *urutan* key untuk file lainnya.
|
||||
|
||||
2. **`.env.example.for.local`** (Template Local)
|
||||
* Template untuk developer lain.
|
||||
* Struktur HARUS sama persis dengan `.env`.
|
||||
* Value kosong atau default aman.
|
||||
|
||||
3. **`.env.example.for.production`** (Template Production)
|
||||
* Gambaran konfigurasi produksi.
|
||||
* Struktur HARUS sama persis dengan `.env`.
|
||||
* Value disesuaikan untuk konteks produksi (misal `APP_ENV=production`, `APP_DEBUG=false`).
|
||||
|
||||
4. **`.env.production.editable`** (Staging/Pre-Production)
|
||||
* File ini berisi konfigurasi produksi yang *siap* untuk diedit/standardisasi.
|
||||
* **CRITICAL:** Struktur dan urutan key HARUS 100% sama dengan `.env`.
|
||||
* Berisi kredensial RILL/ASLI dari server produksi.
|
||||
|
||||
5. **`.env.production.soft.copy`** (Snapshot Server - **READ ONLY**)
|
||||
* Merupakan salinan langsung dari server saat ini.
|
||||
* **DILARANG EDIT** file ini kecuali server aktual telah berubah.
|
||||
* File ini digunakan sebagai validasi/referensi state server sekarang.
|
||||
* Jangan menambahkan config baru di sini sebelum server di-update.
|
||||
|
||||
## Workflow Perubahan Environment
|
||||
|
||||
Jika Anda perlu menambahkan Variable baru (misal `DB_CA_...`):
|
||||
|
||||
1. **Tambahkan di `.env`** lokal terlebih dahulu.
|
||||
2. **Standardisasi urutan** di `.env.production.editable` (copy struktur `.env`, lalu isi value produksi).
|
||||
3. **Update Template** `.env.example.for.local` dan `.env.example.for.production`.
|
||||
4. **JANGAN SENTUH** `.env.production.soft.copy` (biarkan apa adanya sampai deployment selesai dan snapshot baru diambil).
|
||||
|
||||
## Prompting AI
|
||||
Untuk memastikan AI mengerti konteks ini, mintalah:
|
||||
> "Baca aturan environment di `.agent/workflows/manage-env.md` sebelum melakukan perubahan pada file .env"
|
||||
Reference in New Issue
Block a user