You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.3 KiB
Python

#!/usr/bin/env python3
import sys
import os
from pathlib import Path
# Add parent directories to path for imports
current_dir = Path(__file__).parent
sys.path.append(str(current_dir.parent.parent))
from shared.database.connection import create_tables, engine
from shared.database.init_db import init_database
def startup():
"""Initialize database on service startup"""
try:
print("Starting database initialization...")
# Create tables using SQLAlchemy
create_tables()
print("✓ Database tables created/verified")
# Check if we need to seed data
from sqlalchemy import text
with engine.connect() as conn:
result = conn.execute(text("SELECT COUNT(*) FROM themes")).scalar()
if result == 0:
print("No themes found, initializing sample data...")
init_database()
print("✓ Sample data loaded")
else:
print(f"✓ Database already has {result} themes")
print("Database initialization completed successfully!")
return True
except Exception as e:
print(f"❌ Database initialization failed: {e}")
return False
if __name__ == "__main__":
success = startup()
sys.exit(0 if success else 1)