This commit is contained in:
Mikan
2026-06-21 02:41:48 +03:00
parent c21a13d2a3
commit bd85e186dc
31 changed files with 1372 additions and 319 deletions

View File

@@ -245,7 +245,12 @@ BUILTIN_PRESETS = [FANTASY_PRESET, SCI_FI_PRESET]
async def seed_builtin_presets(session: AsyncSession) -> None:
"""Insert builtin presets if they don't yet exist. Owned by the first admin (or a system sentinel)."""
"""Insert builtin presets if they don't yet exist.
Builtin presets have owner_id=NULL (they are system presets, not owned by
any specific user). This avoids the FK violation that occurred on first
startup when no admin user existed yet.
"""
for preset_data in BUILTIN_PRESETS:
existing = (
await session.execute(
@@ -254,18 +259,8 @@ async def seed_builtin_presets(session: AsyncSession) -> None:
).scalar_one_or_none()
if existing is not None:
continue
# Find any admin to own the preset, or use a sentinel UUID
from app.models import User
from sqlalchemy import func
admin = (
await session.execute(
select(User).where(User.is_admin.is_(True)).limit(1)
)
).scalar_one_or_none()
owner_id = admin.id if admin else uuid.UUID("00000000-0000-0000-0000-000000000001")
preset = WorldPreset(
owner_id=owner_id,
owner_id=None, # system preset — no owner
**preset_data,
version=1,
)