Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Database Implementation Verification Script | |
| Validates that all Neon database components are correctly installed | |
| """ | |
| import sys | |
| from pathlib import Path | |
| # Add backend to path | |
| backend_dir = Path(__file__).parent.parent | |
| sys.path.insert(0, str(backend_dir)) | |
| print("=" * 70) | |
| print("NEON POSTGRES DATABASE - IMPLEMENTATION VERIFICATION") | |
| print("=" * 70) | |
| # Test 1: Import database connection | |
| print("\n[1/6] Testing database connection imports...") | |
| try: | |
| from app.database import db, get_db, lifespan_manager, Base | |
| print("β Database connection manager imported") | |
| except ImportError as e: | |
| print(f"β Failed to import database connection: {e}") | |
| sys.exit(1) | |
| # Test 2: Import all models | |
| print("\n[2/6] Testing model imports...") | |
| try: | |
| from app.database.models import ( | |
| User, Organization, UserProfile, Role, UserRole, | |
| Assessment, PipelineStage, BiomarkerValue, | |
| RetinalResult, SpeechResult, CardiologyResult, | |
| RadiologyResult, DermatologyResult, CognitiveResult, | |
| ChatThread, ChatMessage, AIExplanation, | |
| UploadedFile, AuditEvent | |
| ) | |
| model_count = 17 | |
| print(f"β All {model_count} models imported successfully") | |
| except ImportError as e: | |
| print(f"β Failed to import models: {e}") | |
| sys.exit(1) | |
| # Test 3: Import repository | |
| print("\n[3/6] Testing repository imports...") | |
| try: | |
| from app.database.repositories import AssessmentRepository | |
| print("β Assessment repository imported") | |
| except ImportError as e: | |
| print(f"β Failed to import repository: {e}") | |
| sys.exit(1) | |
| # Test 4: Check dependencies | |
| print("\n[4/6] Checking dependencies...") | |
| try: | |
| import alembic | |
| print(f"β Alembic {alembic.__version__} installed") | |
| except ImportError: | |
| print("β Alembic not installed") | |
| sys.exit(1) | |
| try: | |
| import asyncpg | |
| print(f"β asyncpg {asyncpg.__version__} installed") | |
| except ImportError: | |
| print("β asyncpg not installed") | |
| sys.exit(1) | |
| try: | |
| import tenacity | |
| print(f"β tenacity {tenacity.__version__} installed") | |
| except ImportError: | |
| print("β tenacity not installed") | |
| sys.exit(1) | |
| # Test 5: Check Alembic configuration | |
| print("\n[5/6] Checking Alembic configuration...") | |
| alembic_ini = backend_dir / "alembic.ini" | |
| migrations_env = backend_dir / "migrations" / "env.py" | |
| if alembic_ini.exists(): | |
| print("β alembic.ini found") | |
| else: | |
| print("β alembic.ini missing") | |
| sys.exit(1) | |
| if migrations_env.exists(): | |
| print("β migrations/env.py found") | |
| else: | |
| print("β migrations/env.py missing") | |
| sys.exit(1) | |
| # Test 6: Check environment configuration | |
| print("\n[6/6] Checking environment configuration...") | |
| env_example = backend_dir / ".env.example" | |
| if env_example.exists(): | |
| with open(env_example, 'r') as f: | |
| content = f.read() | |
| if "NEON_DATABASE_URL" in content: | |
| print("β .env.example contains NEON_DATABASE_URL") | |
| else: | |
| print("β .env.example missing NEON_DATABASE_URL") | |
| else: | |
| print("β .env.example not found") | |
| env_file = backend_dir / ".env" | |
| if env_file.exists(): | |
| print("β .env file exists") | |
| with open(env_file, 'r') as f: | |
| content = f.read() | |
| if "NEON_DATABASE_URL" in content: | |
| # Check if it's configured (not default) | |
| if "your-neon-host" not in content: | |
| print("β NEON_DATABASE_URL appears to be configured") | |
| else: | |
| print("β NEON_DATABASE_URL needs configuration") | |
| else: | |
| print("β .env missing NEON_DATABASE_URL") | |
| else: | |
| print("β .env file not found - copy from .env.example") | |
| # Summary | |
| print("\n" + "=" * 70) | |
| print("VERIFICATION COMPLETE") | |
| print("=" * 70) | |
| print("\nβ All core components installed successfully!") | |
| print("\nπ Next Steps:") | |
| print(" 1. Create Neon database at https://neon.tech") | |
| print(" 2. Copy .env.example to .env") | |
| print(" 3. Add your NEON_DATABASE_URL to .env") | |
| print(" 4. Run: alembic revision --autogenerate -m 'Initial schema'") | |
| print(" 5. Run: alembic upgrade head") | |
| print(" 6. Run: python scripts/init_db.py") | |
| print("\nπ See DATABASE_SETUP.md for detailed instructions") | |
| print("=" * 70) | |