refactor(users): rename Prisma User model to UserDirectoryEntry #230
Reference in New Issue
Block a user
Delete Branch "fix/rename-user-to-user-directory-entry"
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
Mechanical refactor only, prerequisite to ADR-0026 PR 1. Renames the existing Prisma
Usermodel (the ADR-0020 user-directory cache,oidPK, written byUserDirectoryService.recordSignIn) toUserDirectoryEntry. Frees theUsername for the upcoming ADR-0026 model (UUID PK, FK toPerson,lastSignInAt— different semantics).Zero behavioural change. Same columns, same indexes, same constraints, same call sites — just a different identifier on the model and the table.
What lands
apps/portal-bff/prisma/schema.prismamodel User→model UserDirectoryEntry.@@map("users")→@@map("user_directory_entries"). Comment block extended to flag the upcoming distinction from ADR-0026's newUser.apps/portal-bff/prisma/migrations/20260526200000_rename_users_to_user_directory_entries/migration.sqlALTER TABLE "users" RENAME TO "user_directory_entries"+ALTER INDEXrenames for the PK constraint and the two named indexes (Postgres doesn't auto-rename these on table rename).apps/portal-bff/src/users/user-directory.service.tsUserDirectoryEntry→RecordSignInInput(the existing name was a misnomer — it's the input torecordSignIn, not the entry itself, and would collide with the Prisma-generatedUserDirectoryEntrytype after the model rename). The Prisma client refthis.prisma.user.upsert→this.prisma.userDirectoryEntry.upsert.apps/portal-bff/src/users/user-directory.service.spec.tsapps/portal-bff/src/admin/admin-users-reader.service.tsthis.prisma.user.{count,findMany}→this.prisma.userDirectoryEntry.{count,findMany}.Prisma.UserWhereInput→Prisma.UserDirectoryEntryWhereInput. Doc comments mentioningpublic.usersupdated topublic.user_directory_entries. The class nameAdminUsersReader, the endpoint URL/api/admin/users, the DTOAdminUserDto, and the localinterface UserRoware unchanged — these are SPA/HTTP-facing identifiers, where the URL semantics ("admin user list") still hold regardless of the backing table name.apps/portal-bff/src/admin/admin-users-reader.service.spec.tsWhy two renames in one file
apps/portal-bff/src/users/user-directory.service.tshad a TypeScriptinterface UserDirectoryEntrycarrying the input shape ofrecordSignIn(entry: UserDirectoryEntry). After the Prisma model rename toUserDirectoryEntry, that name would clash with the Prisma-generated row type. The fix is to rename the TS interface to its proper role —RecordSignInInput— at the same time. Net effect: clearer naming on both sides (the call-input name now describes the call, the persisted-row type name now describes the row).Recovery procedure (for anyone with the old migration applied locally)
The new migration
20260526200000_rename_users_to_user_directory_entriesis a pureALTER TABLE ... RENAME+ index renames — Prisma'smigrate devruns it forward without prompting:No
down -vneeded — existing data carries over.Test plan
node scripts/check-catalogue-drift.mjs— clean (4 / 24 / 7).node --test scripts/check-catalogue-drift.spec.mjs— 22 tests passing.pnpm exec prettier --checkclean on the touched files.model User,prisma.user.,Prisma.UserWhereInput,interface UserDirectoryEntry, orpublic.usersreferences anywhere underapps/portal-bff/src/orapps/portal-bff/prisma/.pnpm exec prisma migrate devapplies the rename migration cleanly;pnpm exec nx test portal-bffruns the updated specs green.user-directory.service.ts, the migration'sALTER INDEXclauses (don't forget those —ALTER TABLE ... RENAMEdoes NOT cascade to index names in Postgres), the unchanged class/URL/DTO/local-interface identifiers inadmin-users-reader.service.ts.Why ship as a separate PR
ADR-0026 PR 1's nominal scope is
Person+User+UserScope+ provisioner + drift gate + PrincipalBuilder — already ~15+ files touched. Folding the rename into that PR would mix mechanical refactor with new design. Splitting keeps both PRs reviewable for what they actually do.What's next (post-merge)
ADR-0026 PR 1 —
Person+ newUser+UserScopeschema +PersonAndUserProvisionerwired intoSessionEstablisher+Person.sourcecatalogue + drift-gate extension +PrincipalBuilderpopulatingPrincipal.user.{id, personId}from real rows. Now unblocked.