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>
73 lines
2.2 KiB
Python
73 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""測試 HR Portal 資料庫連接"""
|
|
|
|
import sys
|
|
import os
|
|
|
|
# 添加 backend 路徑
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'backend'))
|
|
|
|
print("=" * 60)
|
|
print("HR Portal 資料庫連接測試")
|
|
print("=" * 60)
|
|
|
|
try:
|
|
# 測試環境變數載入
|
|
print("\n[1] 載入環境變數...")
|
|
from dotenv import load_dotenv
|
|
env_path = os.path.join(os.path.dirname(__file__), 'backend', '.env')
|
|
load_dotenv(env_path)
|
|
|
|
db_url = os.getenv('DATABASE_URL')
|
|
print(f" DATABASE_URL: {db_url[:50]}...")
|
|
|
|
# 測試資料庫連接
|
|
print("\n[2] 測試資料庫連接...")
|
|
from sqlalchemy import create_engine, text
|
|
|
|
engine = create_engine(db_url, echo=False)
|
|
|
|
with engine.connect() as conn:
|
|
# 測試基本查詢
|
|
result = conn.execute(text("SELECT version();"))
|
|
version = result.fetchone()[0]
|
|
print(f" [OK] PostgreSQL 版本: {version[:50]}...")
|
|
|
|
# 檢查資料表
|
|
result = conn.execute(text("""
|
|
SELECT tablename
|
|
FROM pg_tables
|
|
WHERE schemaname = 'public'
|
|
ORDER BY tablename
|
|
"""))
|
|
tables = [row[0] for row in result.fetchall()]
|
|
print(f"\n[3] 資料表列表 ({len(tables)} 個):")
|
|
for table in tables:
|
|
result = conn.execute(text(f'SELECT COUNT(*) FROM "{table}"'))
|
|
count = result.fetchone()[0]
|
|
print(f" - {table:30} {count:>6} 筆")
|
|
|
|
print("\n[4] 測試 Alembic 連接...")
|
|
from alembic.config import Config
|
|
from alembic import command
|
|
|
|
alembic_cfg = Config(os.path.join(os.path.dirname(__file__), 'backend', 'alembic.ini'))
|
|
alembic_cfg.set_main_option('script_location', os.path.join(os.path.dirname(__file__), 'backend', 'alembic'))
|
|
|
|
# 檢查當前版本
|
|
with engine.connect() as conn:
|
|
result = conn.execute(text("SELECT version_num FROM alembic_version"))
|
|
current_version = result.fetchone()[0]
|
|
print(f" 當前 Alembic 版本: {current_version}")
|
|
|
|
print("\n" + "=" * 60)
|
|
print("資料庫連接測試成功!")
|
|
print("=" * 60)
|
|
|
|
except Exception as e:
|
|
print(f"\n[FAIL] 測試失敗: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
sys.exit(1)
|