Add development mode with automatic test data seeding
- Add ORCHARD_ENV setting (defaults to 'development') - Add seed.py with test projects, packages, artifacts, and tags - Automatically seed database on startup in development mode - Skip seeding if database already contains data - Skip seeding in production mode (ORCHARD_ENV=production) Test data includes: - 4 projects (3 public, 1 private) - 8 packages across projects - 5 artifacts with various content types - 10 tags including version tags and 'latest'
This commit is contained in:
@@ -2,19 +2,35 @@ from fastapi import FastAPI
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.responses import FileResponse
|
||||
from contextlib import asynccontextmanager
|
||||
import logging
|
||||
import os
|
||||
|
||||
from .config import get_settings
|
||||
from .database import init_db
|
||||
from .database import init_db, SessionLocal
|
||||
from .routes import router
|
||||
from .seed import seed_database
|
||||
|
||||
settings = get_settings()
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
# Startup: initialize database
|
||||
init_db()
|
||||
|
||||
# Seed test data in development mode
|
||||
if settings.is_development:
|
||||
logger.info(f"Running in {settings.env} mode - checking for seed data")
|
||||
db = SessionLocal()
|
||||
try:
|
||||
seed_database(db)
|
||||
finally:
|
||||
db.close()
|
||||
else:
|
||||
logger.info(f"Running in {settings.env} mode - skipping seed data")
|
||||
|
||||
yield
|
||||
# Shutdown: cleanup if needed
|
||||
|
||||
|
||||
Reference in New Issue
Block a user