feat: Auto-seed admin user on container start
- prestart.sh: runs seed_admin.py after migrations - seed_admin.py: reads ADMIN_EMAIL and ADMIN_PASSWORD from env vars - Creates default tenant + admin role + admin user if not exists
This commit is contained in:
@@ -100,6 +100,9 @@ asyncio.run(set_password())
|
|||||||
"
|
"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "[prestart] Seeding admin user if not exists..."
|
||||||
|
python3 /app/scripts/seed_admin.py || echo "[prestart] WARNING: Admin seed failed (may already exist)"
|
||||||
|
|
||||||
echo "[prestart] Starting uvicorn on 0.0.0.0:8000 (workers=1)..."
|
echo "[prestart] Starting uvicorn on 0.0.0.0:8000 (workers=1)..."
|
||||||
exec uvicorn app.main:app \
|
exec uvicorn app.main:app \
|
||||||
--host 0.0.0.0 \
|
--host 0.0.0.0 \
|
||||||
|
|||||||
@@ -69,12 +69,12 @@ async def seed():
|
|||||||
print(f"Admin role exists: {role.id}")
|
print(f"Admin role exists: {role.id}")
|
||||||
|
|
||||||
# Check if admin user exists
|
# Check if admin user exists
|
||||||
result = await db.execute(select(User).where(User.email == "admin@media-on.de"))
|
result = await db.execute(select(User).where(User.email == os.environ.get("ADMIN_EMAIL", "admin@media-on.de")))
|
||||||
user = result.scalar_one_or_none()
|
user = result.scalar_one_or_none()
|
||||||
|
|
||||||
if user is None:
|
if user is None:
|
||||||
user = User(
|
user = User(
|
||||||
email="admin@media-on.de",
|
email=os.environ.get("ADMIN_EMAIL", "admin@media-on.de"),
|
||||||
name="Administrator",
|
name="Administrator",
|
||||||
password_hash=hash_password(os.environ.get("ADMIN_PASSWORD", "Admin123!")),
|
password_hash=hash_password(os.environ.get("ADMIN_PASSWORD", "Admin123!")),
|
||||||
is_active=True,
|
is_active=True,
|
||||||
|
|||||||
Reference in New Issue
Block a user