Garment.id
🇮🇩 Indonesian
  • 🇮🇩 Indonesian
  • 🇺🇸 English
Home
Core APITenant APISupport CenterChangelog
Home
Core APITenant APISupport CenterChangelog
Github
Instagram
|
🇮🇩 Indonesian
  • 🇮🇩 Indonesian
  • 🇺🇸 English
🇮🇩 Indonesian
  • 🇮🇩 Indonesian
  • 🇺🇸 English
  1. Home
  • Introduction
  • 01 - Project Structure
  • 02 - Context Boundaries
  • 03 - Central Auth Runtime
  • 04 - Central Billing
  • 05 - Tenant Runtime
  • 06 - FE Integration Contracts
  • 07 - Security, Middleware, and RLS
  • 08 - Events, Jobs, Listeners, Notifications, Observers
  • 09 - Testing and Quality Gates
  • 10 - Operations Runbook
  • 11 - Architecture Decisions (ADR Ringkas)
  • 12 - API Endpoint Catalog (v1)
  • 13 - Class Catalog by Context
  • 14 - Feature Development Playbook
  • 15 - Migration and Model Conventions
  • 16 - Service, Support, and Trait Contracts
  • 17 - Auth Business Scenarios and Decision Tree
  • 18 - Config Reference and Impact
  • 19 - Migration and Model Cookbook
  • 20 - Billing and Provisioning Business Flows
  • 21 - FE Error Handling Matrix
  • 22 - Incident Playbooks
  • 23 - Data Ownership Matrix
  • 24 - Documentation Governance and Changelog
  • 25 - Tenant Authorization Backend Guide
Home
Core APITenant APISupport CenterChangelog
Home
Core APITenant APISupport CenterChangelog
Github
Instagram
|
🇮🇩 Indonesian
  • 🇮🇩 Indonesian
  • 🇺🇸 English
🇮🇩 Indonesian
  • 🇮🇩 Indonesian
  • 🇺🇸 English
  1. Home

15 - Migration and Model Conventions

Dokumen ini menjelaskan standar migration dan model untuk central/tenant context.

Migration Placement Rules#

Central Migration#

Taruh di database/migrations/central jika:
data global platform
auth identity global
tenant registry/metadata global
billing source-of-truth global
audit/security global

Tenant Migration#

Taruh di database/migrations/tenant jika:
data operasional tenant
data master lokal tenant
role/permission tenant-scoped
audit tenant-scoped

Tenant Migration (PostgreSQL + RLS) Rules#

Untuk migration tenant di proyek ini, pattern default adalah PostgreSQL + RLS.

Wajib untuk tabel tenant-scoped#

1.
Gunakan trait:
use InteractsWithPostgresRls;
2.
Simpan kolom tenant context:
tenant_id (UUID, indexed).
3.
Aktifkan RLS:
$this->enableRls('<table>');
4.
Buat minimal satu isolation policy tenant:
tenant_isolation_policy atau policy setara.
5.
Pada down(), drop policy sebelum drop table.

Sangat direkomendasikan#

1.
Tambah partial index untuk query path aktif (misal is_active = true).
2.
Tambah policy tambahan sesuai business role (misal owner visibility).
3.
Gunakan helper trait untuk expression SQL agar konsisten:
tenantIsolationUsing()
partialIndex()
createPolicy()

Referensi implementasi aktual#

database/migrations/tenant/2026_02_14_032023_create_tenant_user_table.php
database/migrations/tenant/2026_02_25_000039_create_taxonomies_table.php
app/Support/Database/Concerns/InteractsWithPostgresRls.php

Naming Conventions#

file: {timestamp}_create_{table}_table.php
alter: {timestamp}_add_{column}_to_{table}_table.php
gunakan nama singular/plural konsisten dengan existing schema

Migration Template Guidelines#

Checklist kolom:
primary key UUID/ULID sesuai standar proyek
timestamps
softDeletes jika perlu
index untuk query frequent path
foreign key eksplisit jika relasi intra-context
Untuk tenant table:
jika model akan diakses via tenant context + trait, jangan hardcode koneksi di migration logic selain kebutuhan khusus.
wajib follow helper/project convention untuk RLS:
enableRls()
createPolicy()
dropPolicy()
tenantIsolationUsing()
partialIndex()

Model Placement Rules#

central model: app/Models/Central/{Domain}/*
tenant model: app/Models/Tenant/{Domain}/*
user/auth model global: app/Models/User/*

Tenant Model Rule#

Gunakan HasTenantClusterConnection bila model:
harus resolve koneksi cluster tenant otomatis berdasarkan TenantContext.
Contoh use case:
tenant master data
tenant identity mirror
tenant RBAC

Cross-Context Rules#

central controller/service tidak boleh query model tenant tanpa boundary resolver/context yang benar.
tenant runtime tidak boleh bergantung langsung pada mutable central domain data tanpa kontrak yang jelas.

Seeder and Migration Order#

Gunakan command orchestration proyek:
Urutan inti:
1.
migration central
2.
seed cluster registry minimal
3.
migration tenant clusters
4.
seed data central

Anti-Patterns#

menaruh migration tenant di folder central karena cepat.
menaruh model tenant di namespace central.
membuat logic tenant connection resolve manual berulang di banyak service.
merubah payload API tanpa update docs dan FE contract.
membuat table tenant tanpa tenant_id + policy RLS.
membuat index hanya index biasa untuk query aktif padahal butuh partial index.
Diubah pada 2026-03-03 22:25:30
Sebelumnya
14 - Feature Development Playbook
Berikutnya
16 - Service, Support, and Trait Contracts
Built with