Platform Runbook

คู่มือปฏิบัติงานสำหรับ Platform Admin (local dev)

1. Bootstrap platform_admin

หาก deploy ใหม่แล้วยังไม่มีบัญชี platform_admin:

# ตั้ง .env (บังคับ bootstrap แม้ ENVIRONMENT=production)
PLATFORM_ADMIN_BOOTSTRAP_ENABLED=true
PLATFORM_ADMIN_BOOTSTRAP_FORCE=true
PLATFORM_ADMIN_USERNAME=platform_admin
PLATFORM_ADMIN_PASSWORD=PlatformAdmin@1234
[email protected]

# restart backend
docker compose restart backend

2. Create Tenant via CLI

TOKEN=$(curl -s -X POST http://localhost:8010/api/v1/auth/login \
  -d "username=platform_admin&password=PlatformAdmin@1234" | jq -r .access_token)

curl -X POST http://localhost:8010/api/v1/platform/tenants \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "code":"acme",
    "slug":"acme",
    "name":"ACME",
    "plan_code":"standard",
    "domains":[{"domain":"acme.localhost","is_primary":true}]
  }'

3. Seed Tenant Data

# Seed เฉพาะ tenant ที่ระบุ (legacy demo data)
./scripts/db-reset.py --tenant acme --tenant-seed-only --yes

# Seed ทุก tenant ที่ ACTIVE
./scripts/db-reset.py --all-tenants --tenant-seed-only --yes

# Reset + seed (ลบข้อมูลเดิม!)
./scripts/db-reset.py --tenant acme --hard --yes

4. Setup Local Subdomain

# เพิ่ม /etc/hosts + upsert tenant_domains
./scripts/setup-local-tenants.sh acme

# ทดสอบ
curl http://acme.localhost:8010/health

5. Rate-limit / Lockout Reset (v64.1)

หาก platform_admin ถูก lock เพราะพิมพ์รหัสผิด 5 ครั้งใน 15 นาที:

docker compose exec postgres psql -U wms_user -d wms_cp \
  -c "DELETE FROM login_attempts WHERE username='platform_admin';"

Useful Endpoints

MethodPathUse
GET /api/v1/platform/tenants List tenants
POST /api/v1/platform/tenants Create tenant
GET /api/v1/platform/tenants/{id} Details
PATCH /api/v1/platform/tenants/{id} Edit
POST /api/v1/platform/tenants/{id}/activate Activate
POST /api/v1/platform/tenants/{id}/suspend Suspend
GET /api/v1/platform/tenants/seed-templates Seed templates
GET /api/v1/platform/tenants/plans Plans
GET /api/v1/platform/tenants/feature-library Feature keys