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>
110 lines
3.6 KiB
PowerShell
110 lines
3.6 KiB
PowerShell
# Run Database Setup on Ubuntu Server
|
|
# This script uploads files to Ubuntu Server and executes the setup
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host " HR Portal Database Setup Launcher" -ForegroundColor Cyan
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
$REMOTE_HOST = "ubuntu@10.1.0.254"
|
|
$REMOTE_DIR = "/tmp/hr-portal-setup"
|
|
$LOCAL_SCRIPT_DIR = "W:\DevOps-Workspace\hr-portal\scripts"
|
|
|
|
# Step 1: Create remote directory
|
|
Write-Host "[1/4] Preparing remote directory..." -ForegroundColor Yellow
|
|
|
|
ssh $REMOTE_HOST "mkdir -p $REMOTE_DIR && chmod 755 $REMOTE_DIR"
|
|
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host " [OK] Remote directory ready: $REMOTE_DIR" -ForegroundColor Green
|
|
} else {
|
|
Write-Host " [FAIL] Could not create remote directory" -ForegroundColor Red
|
|
Write-Host ""
|
|
Write-Host "Please ensure SSH key-based authentication is configured." -ForegroundColor Yellow
|
|
Write-Host "Run: type `$env:USERPROFILE\.ssh\id_rsa.pub | ssh ubuntu@10.1.0.254 'cat >> ~/.ssh/authorized_keys'" -ForegroundColor Gray
|
|
exit 1
|
|
}
|
|
|
|
Write-Host ""
|
|
|
|
# Step 2: Upload files
|
|
Write-Host "[2/4] Uploading setup files..." -ForegroundColor Yellow
|
|
|
|
$filesToUpload = @(
|
|
"setup-hr-portal-db.sh",
|
|
"init-db.sql",
|
|
"insert-test-data.sql"
|
|
)
|
|
|
|
foreach ($file in $filesToUpload) {
|
|
$localPath = Join-Path $LOCAL_SCRIPT_DIR $file
|
|
|
|
if (Test-Path $localPath) {
|
|
Write-Host " Uploading $file..." -ForegroundColor Gray
|
|
scp $localPath "${REMOTE_HOST}:${REMOTE_DIR}/"
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host " [FAIL] Failed to upload $file" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
} else {
|
|
Write-Host " [WARNING] File not found: $file" -ForegroundColor Yellow
|
|
}
|
|
}
|
|
|
|
Write-Host " [OK] Files uploaded successfully" -ForegroundColor Green
|
|
Write-Host ""
|
|
|
|
# Step 3: Make script executable
|
|
Write-Host "[3/4] Setting permissions..." -ForegroundColor Yellow
|
|
|
|
ssh $REMOTE_HOST "chmod +x $REMOTE_DIR/setup-hr-portal-db.sh"
|
|
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host " [OK] Script is executable" -ForegroundColor Green
|
|
} else {
|
|
Write-Host " [FAIL] Could not set permissions" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
Write-Host ""
|
|
|
|
# Step 4: Execute setup script
|
|
Write-Host "[4/4] Executing database setup on remote server..." -ForegroundColor Yellow
|
|
Write-Host " You will be prompted for database passwords" -ForegroundColor Gray
|
|
Write-Host ""
|
|
|
|
ssh -t $REMOTE_HOST "cd $REMOTE_DIR && bash setup-hr-portal-db.sh"
|
|
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host ""
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host " Database Setup Completed!" -ForegroundColor Cyan
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
Write-Host "Next steps:" -ForegroundColor Green
|
|
Write-Host " 1. The connection string has been displayed above" -ForegroundColor White
|
|
Write-Host " 2. Update W:\DevOps-Workspace\hr-portal\backend\.env" -ForegroundColor White
|
|
Write-Host " 3. Run insert-test-data.sql for sample data (optional)" -ForegroundColor White
|
|
Write-Host ""
|
|
} else {
|
|
Write-Host ""
|
|
Write-Host "[ERROR] Setup script failed" -ForegroundColor Red
|
|
Write-Host "Check the error messages above for details" -ForegroundColor Yellow
|
|
exit 1
|
|
}
|
|
|
|
# Cleanup prompt
|
|
Write-Host ""
|
|
$cleanup = Read-Host "Clean up remote setup files? (y/N)"
|
|
|
|
if ($cleanup -eq "y" -or $cleanup -eq "Y") {
|
|
Write-Host "Cleaning up..." -ForegroundColor Gray
|
|
ssh $REMOTE_HOST "rm -rf $REMOTE_DIR"
|
|
Write-Host " [OK] Cleanup complete" -ForegroundColor Green
|
|
}
|
|
|
|
Write-Host ""
|