Admin user creation moved to scripts

This commit is contained in:
2025-10-19 15:53:56 +02:00
parent d7439fce46
commit 53e5916c6c
2 changed files with 167 additions and 33 deletions

View File

@@ -31,32 +31,6 @@ async def lifespan(app: FastAPI):
# === STARTUP ===
app_logger = setup_logging()
app_logger.info("Starting up ecommerce API")
# === REMOVED: Database table creation ===
# Base.metadata.create_all(bind=engine) # Removed - handled by Alembic
# create_indexes() # Removed - handled by Alembic
# === KEPT: Application-level initialization ===
# Create default admin user (after migrations have run)
db = SessionLocal()
try:
auth_manager.create_default_admin_user(db)
logger.info("Default admin user initialization completed")
except Exception as e:
logger.error(f"Failed to create default admin user: {e}")
# In development, this might fail if tables don't exist yet
# That's OK - migrations should be run separately
finally:
db.close()
# Add any other application-level initialization here
# Examples:
# - Load configuration
# - Initialize caches
# - Set up external service connections
# - Load initial data (AFTER migrations)
logger.info("[OK] Application startup completed")
yield
@@ -66,13 +40,6 @@ async def lifespan(app: FastAPI):
# Add cleanup tasks here if needed
# === REMOVED FUNCTION ===
# def create_indexes():
# """Create database indexes."""
# # This is now handled by Alembic migrations
# pass
# === NEW HELPER FUNCTION ===
def check_database_ready():
"""Check if database is ready (migrations have been run)."""