-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_db.py
More file actions
34 lines (26 loc) · 1.03 KB
/
Copy pathinit_db.py
File metadata and controls
34 lines (26 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
"""
Initialize database - create all tables from SQLAlchemy models
"""
import sys
from pathlib import Path
# Add services/shared to path
sys.path.insert(0, str(Path(__file__).parent / "services" / "shared"))
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from services.shared.db.base import Base
from services.shared.db import models # Import all models
# Database URL - use localhost:5433 for host access to Docker container
DATABASE_URL = "postgresql+psycopg://spectra:spectra@localhost:5433/spectra"
def init_database():
"""Create all tables from models"""
print(f"Connecting to database...")
engine = create_engine(DATABASE_URL, echo=True)
print(f"\nCreating all tables...")
Base.metadata.create_all(bind=engine)
print(f"\n✓ Database initialized successfully!")
print(f" Created {len(Base.metadata.tables)} tables:")
for table_name in sorted(Base.metadata.tables.keys()):
print(f" - {table_name}")
if __name__ == "__main__":
init_database()