Files
roa2web-service-auto/shared/database
Claude Agent b137e80b71 feat: multi-Oracle server support with runtime switching
Complete implementation of multi-server Oracle database support:

Backend:
- Multi-pool Oracle with lazy loading per server
- Email-to-server cache for automatic server discovery
- JWT tokens include server_id claim
- /auth/check-identity and /auth/check-email endpoints
- /auth/my-servers endpoint for listing user's accessible servers
- Server switch with password re-authentication

Frontend:
- New ServerSelector component for header dropdown
- Multi-step login flow (identity → server → password)
- Server switching from header with password modal
- Mobile drawer menu with server selection
- Dark mode support for all new components
- URL bookmark support with ?server= query param

Scripts:
- Unified start.sh replacing start-prod.sh/start-test.sh
- Unified ssh-tunnel.sh with multi-server support
- Updated status.sh for new architecture

Tests:
- E2E tests for multi-server and single-server login flows
- Backend unit tests for all new endpoints
- Oracle multi-pool integration tests

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-26 22:39:06 +00:00
..

ROA2WEB Shared Database Pool

Sistem de pool de conexiuni Oracle partajat între toate microserviciile ROA2WEB.

Componente

📦 oracle_pool.py

Clasa singleton OraclePool pentru gestionarea pool-ului de conexiuni Oracle.

📋 models.py

Modele Pydantic comune:

  • User - Model pentru utilizatori
  • Company - Model pentru firme/scheme Oracle
  • DatabaseConfig - Configurare conexiune database

⚙️ config.py (în utils/)

Configurări partajate prin environment variables.

exceptions.py (în utils/)

Exception handlers personalizate pentru ROA2WEB.

Utilizare

Inițializare în aplicații FastAPI

from contextlib import asynccontextmanager
from fastapi import FastAPI
import sys
import os

# Import shared pool
sys.path.append(os.path.join(os.path.dirname(__file__), '../../../shared'))
from database.oracle_pool import oracle_pool

@asynccontextmanager
async def lifespan(app: FastAPI):
    # Startup - inițializare pool
    await oracle_pool.initialize()
    print("📊 Oracle pool initialized")
    
    yield
    
    # Shutdown - închidere pool
    await oracle_pool.close_pool()
    print("📊 Oracle pool closed")

app = FastAPI(lifespan=lifespan)

Utilizare conexiune în endpoint-uri

from fastapi import APIRouter, HTTPException
from database.oracle_pool import oracle_pool

router = APIRouter()

@router.get("/companies")
async def get_companies():
    try:
        async with oracle_pool.get_connection() as conn:
            with conn.cursor() as cursor:
                cursor.execute("SELECT schema, firma FROM vdef_util_grup WHERE id_firma <> 0")
                results = cursor.fetchall()
                
                companies = []
                for row in results:
                    companies.append({
                        "code": row[0],
                        "name": row[1]
                    })
                
                return companies
                
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"Database error: {str(e)}")

Configurare Environment Variables

# Oracle Database
ORACLE_USER=your_oracle_username
ORACLE_PASSWORD=your_oracle_password
ORACLE_DSN=your_oracle_dsn

# Pool Settings
DB_MIN_CONNECTIONS=2
DB_MAX_CONNECTIONS=10
DB_CONNECTION_INCREMENT=1

# JWT (pentru autentificare)
JWT_SECRET_KEY=your-super-secret-key
ACCESS_TOKEN_EXPIRE_MINUTES=30

Testare

Pentru a testa pool-ul de conexiuni:

cd roa2web/shared/database
python test_pool.py

Notă: Testul necesită configurarea variabilelor de environment pentru Oracle.

Caracteristici

Singleton Pattern - O singură instanță de pool pentru toată aplicația
Async Context Manager - Gestionare automată a conexiunilor
Connection Pooling - Performanță optimizată prin reutilizarea conexiunilor
Configurabil - Setări flexibile prin environment variables
Logging - Urmărirea operațiilor de pool
Error Handling - Excepții personalizate pentru debugging

Următorii Pași

👉 ZIUA 3: Implementarea sistemului JWT partajat (shared/auth/)


Documentație generată pentru ROA2WEB Shared Database Pool - ZIUA 2 🚀