Files
star-erp/docs/multi-tenancy-deployment.md
sky121113 4f745c1021
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Successful in 1m3s
Koori-ERP-Deploy-System / deploy-production (push) Has been skipped
feat: 實作 Multi-tenancy 多租戶架構 (stancl/tenancy)
- 安裝並設定 stancl/tenancy 套件
- 分離 Central / Tenant migrations
- 建立 Tenant Model 與資料遷移指令
- 建立房東後台 CRUD (Landlord Dashboard)
- 新增租戶管理頁面 (列表、新增、編輯、詳情)
- 新增域名管理功能
- 更新部署手冊
2026-01-15 13:15:18 +08:00

72 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Multi-tenancy 部署手冊
> 記錄本地開發完成後,上 Demo/Production 環境時需要手動執行的操作。
> CI/CD 會自動執行的項目已排除。
---
## Step 1: 安裝 stancl/tenancy
**CI/CD 會自動執行**`composer install`
**手動操作**:無
---
## Step 2: 設定 Central Domain + Tenant 識別
**手動操作**
1. 修改 `.env`,加入:
```bash
# Demo 環境 (192.168.0.103)
CENTRAL_DOMAINS=192.168.0.103,localhost
# Production 環境 (erp.koori.tw)
CENTRAL_DOMAINS=erp.koori.tw
```
---
## Step 3: 分離 Migrations
**CI/CD 會自動執行**`php artisan migrate --force`
**手動操作**:無
> 注意migrations 結構已調整如下:
> - `database/migrations/` - Central tables (tenants, domains)
> - `database/migrations/tenant/` - Tenant tables (所有業務表)
---
## Step 4: 遷移現有資料到 tenant_koori
**首次部署手動操作**
1. 授予 MySQL sail 使用者 CREATE DATABASE 權限:
```bash
docker exec koori-erp-mysql mysql -uroot -p[PASSWORD] -e "GRANT ALL PRIVILEGES ON *.* TO 'sail'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES;"
```
2. 建立第一個租戶 (小小冰室)
```bash
docker exec -w /var/www/html koori-erp-laravel php artisan tinker --execute="
use App\Models\Tenant;
Tenant::create(['id' => 'koori', 'name' => '小小冰室']);
"
```
3. 為租戶綁定域名:
```bash
docker exec -w /var/www/html koori-erp-laravel php artisan tinker --execute="
use App\Models\Tenant;
Tenant::find('koori')->domains()->create(['domain' => 'koori.your-domain.com']);
"
```
4. 執行資料遷移 (從 central DB 複製到 tenant DB)
```bash
docker exec -w /var/www/html koori-erp-laravel php artisan tenancy:migrate-data koori
```
## Step 5: 建立房東後台
**手動操作**:無
---
## 其他注意事項
- 待補充...