File size: 1,146 Bytes
363cda9 f95198a 363cda9 f95198a 363cda9 f95198a 363cda9 f95198a |
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 35 36 37 38 39 40 41 42 |
"""
Database initialization script.
This is a standalone script to initialize the database.
Kept separate from client.py to avoid circular import issues
when running with `python -m`.
Usage:
python -m src.database.candidates.init_db
"""
from src.database.candidates.client import engine
from src.database.candidates.models import Base
from sqlalchemy import inspect
def init_db():
"""
Creates all database tables if they don't exist.
Intended for dev setup / Docker initialization.
"""
try:
print("π Starting database initialization...")
Base.metadata.create_all(bind=engine)
# Verify tables
inspector = inspect(engine)
tables = inspector.get_table_names()
print(f"π Found tables: {tables}")
if "candidates" in tables:
print("β
Database initialized successfully.")
return True
else:
print("β Error: 'candidates' table was not created!")
except Exception as e:
print(f"β Failed to initialize database: {e}")
raise
if __name__ == "__main__":
init_db() |