Major Features: - ✅ Multi-tenant architecture (tenant isolation) - ✅ Employee CRUD with lifecycle management (onboarding/offboarding) - ✅ Department tree structure with email domain management - ✅ Company info management (single-record editing) - ✅ System functions CRUD (permission management) - ✅ Email account management (multi-account per employee) - ✅ Keycloak SSO integration (auth.lab.taipei) - ✅ Redis session storage (10.1.0.254:6379) - Solves Cookie 4KB limitation - Cross-system session sharing - Sliding expiration (8 hours) - Automatic token refresh Technical Stack: Backend: - FastAPI + SQLAlchemy - PostgreSQL 16 (10.1.0.20:5433) - Keycloak Admin API integration - Docker Mailserver integration (SSH) - Alembic migrations Frontend: - Next.js 14 (App Router) - NextAuth 4 with Keycloak Provider - Redis session storage (ioredis) - Tailwind CSS Infrastructure: - Redis 7 (10.1.0.254:6379) - Session + Cache - Keycloak 26.1.0 (auth.lab.taipei) - Docker Mailserver (10.1.0.254) Architecture Highlights: - Session管理由 Keycloak + Redis 統一控制 - 支援多系統 (HR/WebMail/Calendar/Drive/Office) 共享 session - Token 自動刷新,異質服務整合 - 未來可無縫遷移到雲端 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
HR Portal 資料庫設計
📋 Schema 版本
- 版本: v2.0
- 創建日期: 2026-02-10
- 設計依據: 員工多身份設計文件.md
🗂️ 資料表結構
核心表格
- employees - 員工基本資料
- business_units - 事業部
- departments - 部門
- employee_identities - 員工身份 (多對多關係)
- network_drives - 網路硬碟 (一對一關係)
- audit_logs - 審計日誌
關聯圖
employees (員工)
│
├──< employee_identities (身份) ──> business_units (事業部)
│ ──> departments (部門)
│
└──< network_drives (NAS 帳號)
🚀 快速開始
方法一: Docker Compose (推薦)
# 進入 database 目錄
cd W:\DevOps-Workspace\3.Develop\4.HR_Portal\database
# 啟動資料庫
docker-compose up -d
# 執行測試腳本
docker-compose exec postgres psql -U hr_admin -d hr_portal -f /test_schema.sql
# 或從本地執行
docker exec -i hr-portal-db-test psql -U hr_admin -d hr_portal < test_schema.sql
詳細測試說明請參考 TESTING.md
方法二: 本地 PostgreSQL
# 1. 創建資料庫
createdb hr_portal
# 或使用 psql
psql -U postgres -c "CREATE DATABASE hr_portal;"
# 2. 執行 Schema
psql -U postgres -d hr_portal -f schema.sql
# 3. 執行測試
psql -U postgres -d hr_portal -f test_schema.sql
驗證
# 檢查表格
psql -U postgres -d hr_portal -c "\dt"
# 檢查視圖
psql -U postgres -d hr_portal -c "\dv"
# 查看初始資料
psql -U postgres -d hr_portal -c "SELECT * FROM business_units;"
📝 重要設計概念
員工多身份
一個員工 (employees) 可以有多個身份 (employee_identities),每個身份對應一個事業部:
- 同事業部多部門: 共用一個 SSO 帳號
- 跨事業部: 獨立的 SSO 帳號
SSO 帳號命名
格式: {username_base}@{email_domain}
範例:
- porsche.chen@lab.taipei (智能發展部)
- porsche.chen@ease.taipei (業務發展部)
- porsche.chen@porscheworld.tw (營運管理部)
NAS 帳號
- 一個員工只有一個 NAS 帳號
- 帳號名稱 =
username_base - 配額由最高職級決定
🔧 開發工具
Docker Compose
提供完整的測試環境,包含 PostgreSQL 16 和 pgAdmin 4。
啟動:
docker-compose up -d
訪問 pgAdmin: http://localhost:5050
- Email: admin@lab.taipei
- Password: admin
資料庫連線資訊:
- Host: postgres (Docker 內部) / localhost (外部)
- Port: 5433 (外部) / 5432 (內部)
- Database: hr_portal
- User: hr_admin
- Password: hr_dev_password_2026
測試腳本
提供完整的測試腳本 test_schema.sql,包含:
- 表格結構驗證
- 外鍵約束測試
- 唯一約束測試
- 索引檢查
- 模擬資料插入
詳見 TESTING.md
遷移工具
建議使用 Alembic 進行資料庫遷移管理。
📖 相關文檔
- TESTING.md - 資料庫測試指南
- 員工多身份設計文件
- [HR Portal 設計文件](../../../2.專案設計區/4.HR_Portal/HR Portal設計文件.md)
📂 檔案清單
schema.sql- 資料庫 Schema (v2.0)test_schema.sql- 測試腳本docker-compose.yml- Docker 測試環境TESTING.md- 測試指南README.md- 本文件