Skip to content
1 change: 1 addition & 0 deletions api/transformerlab/routers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ async def get_user_teams(user: User = Depends(current_active_user), session: Asy
user_teams = result.scalars().all()

# If user has no team associations, create personal team as owner
# (dont seed experiment as existing user may already have experiments from old workspace)
if not user_teams:
personal_team = await create_personal_team(session, user)
user_team = UserTeam(user_id=str(user.id), team_id=personal_team.id, role=TeamRole.OWNER.value)
Expand Down
8 changes: 8 additions & 0 deletions api/transformerlab/routers/teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from datetime import datetime, timedelta
from os import getenv

from lab import Experiment


class TeamCreate(BaseModel):
name: str
Expand Down Expand Up @@ -76,6 +78,12 @@ async def create_team(
session.add(user_team)
await session.commit()

# Add logic to seed experiment if no experiments exist
existing_experiments = Experiment.get_all()
if len(existing_experiments) == 0:
_ = Experiment("alpha", create_new=True)
print(f"✅ Created alpha experiment for team '{team.name}' (id={team.id})")

return TeamResponse(id=team.id, name=team.name)


Expand Down
4 changes: 4 additions & 0 deletions api/transformerlab/services/experiment_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ async def migrate_workspace_to_org(team_id: str):
# Directory not empty or other error, leave it
pass

# Recreate workspace directory (default sdk behaviour is to create this directory again when auth isnt done -- which will happen at startup)
if not storage.exists(old_workspace):
storage.makedirs(old_workspace, exist_ok=True)

# Add a text file in the old workspace saying where the migration happened
with open(os.path.join(old_workspace, "migration.txt"), "w") as f:
f.write(f"Migration happened from {old_workspace} to {new_workspace}")
Expand Down
9 changes: 5 additions & 4 deletions api/transformerlab/shared/models/user_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class User(SQLAlchemyBaseUserTableUUID, Base):
- is_active (boolean)
- is_superuser (boolean)
- is_verified (boolean)

We add custom fields below:
"""

first_name: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
last_name: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)

Expand All @@ -49,11 +50,11 @@ async def create_personal_team(session: AsyncSession, user) -> Team:
"""
Create a personal team for the user named "Username's Team".
Each user gets their own team.

Args:
session: Database session
user: User object with first_name, last_name, or email

Returns:
Team: The created personal team
"""
Expand All @@ -63,7 +64,7 @@ async def create_personal_team(session: AsyncSession, user) -> Team:
else:
# Fallback to email username if no first_name
team_name = f"{user.email.split('@')[0]}'s Team"

# Create new team for this user
team = Team(name=team_name)
session.add(team)
Expand Down
Loading