feat(teams): add Team entity and replace PersonDepartment with teamId #6
Reference in New Issue
Block a user
Delete Branch "feature/add-teams"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Replaces the
PersonDepartmentenum with a user-managedTeamentity. Teams are created, renamed, and deleted from/people?tab=teams(ADMIN-gated).Person.departmentbecomesPerson.teamId(nullable FK,onDelete: SetNull). Migration backfillsPerson.teamIdfrom the old enum and drops the enum and column in one transaction.What's in
TeamPrisma model (id, name, createdAt, updatedAt) with a case-insensitive unique index onlower("name").Person.teamIdFK (nullable,onDelete: SetNull).Teamtable and the case-insensitive unique index.Person.teamIdfrom the oldPersonDepartmentenum.Person.departmentcolumn, the old index, and thePersonDepartmentenum.src/schemas/team.schema.ts,src/services/team.service.ts,src/use-cases/team.use-cases.ts,src/actions/team.actions.ts,src/types/team.ts./people?tab=teamswithTeamsTab,TeamListTable,TeamCreateForm,TeamEditForm.person.team?.name(with—fallback).—fallback).en.tsandes.ts: newinventory.teams.*keys, removedinventory.people.departments, addedinventory.people.*team keys.Key decisions
deletedAt). FKonDelete: SetNullhandles cascade automatically.CREATE UNIQUE INDEX team_name_lower_unique ON "Team" (lower("name")). Prisma's partial unique indexes don't support functional expressions in this version.src/app/(dashboard)/people/layout.tsx). The team picker is open to any authenticated user (needed for the person form).z.union([z.string().uuid(), z.literal("")]).transform((val) => val === "" ? null : val).Verification
bun run test:unit— 223 testsbun run test:integration— 86 testsbun run test:e2e— 4 people e2e tests pass (tab routing, team CRUD, person with/without team)bunx tsc --noEmitbunx prisma validatebunx biome check .PR chain (already merged)
feature/add-teamsRelated
openspec/changes/add-teams/proposal.mdopenspec/changes/add-teams/specs/team-management.md,openspec/changes/add-teams/specs/person-team.mdopenspec/changes/add-teams/design.mdopenspec/changes/add-teams/tasks.mdDeployment notes
PersonDepartmentenum andPerson.departmentcolumn). Runbunx prisma migrate deployand verify the seed teams and backfilledPerson.teamIdvalues before declaring the deploy successful./admin/usersroute is fully replaced by/people. No redirect is needed because the route was already migrated to/peoplein a previous change.