refactor(database): replace UserPasswordRepository Create with Set upsert - #292
Conversation
Replace delete-then-create password changes with a single INSERT ON CONFLICT upsert. Rename CreateUserPassword to SetUserPassword and update all call sites including SetPasswordUserAction, flow create_user, and bootstrap import. Co-authored-by: Silvan <adlerhurst@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This PR refactors user-password persistence to use a single upsert-style repository call (Set) for both initial password creation and subsequent password updates, replacing the previous delete-then-create flow.
Changes:
- Renames the domain/repository contract from
CreateUserPassword/CreatetoSetUserPassword/Set. - Updates the Postgres repository write to
INSERT ... ON CONFLICT (project_id, user_id) DO UPDATE, resettingfailed_attemptsandlast_successful_checkon update. - Updates affected services, flow handler wiring, bootstrap import, fakes, and adds an upsert-focused repository integration test.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| internal/storage/database/repository/user_password.go | Replaces Create insert with Set upsert using ON CONFLICT and update-side resets. |
| internal/storage/database/repository/user_credentials_test.go | Migrates CRUD test to Set and adds an upsert test asserting ID preservation + resets. |
| internal/service/user.go | Simplifies password-setting action to one repository call and updates error message. |
| internal/domain/user_password.go | Renames request type and repository interface method from Create to Set. |
| internal/domain/flow_state_machine_test.go | Updates fake password repo and assertions to the new Set contract. |
| internal/domain/flow_on_success_create_user.go | Renames flow password writer interface to Set and updates handler call/error text. |
| internal/bootstrap/users/import.go | Switches bootstrap password write from Create to Set and updates error text. |
|
@adlerhurst must be a member of the zitadel team on Vercel to deploy. Learn more about collaboration on Vercel and other options here. |
|
muhlemmer
left a comment
There was a problem hiding this comment.
Besides the comments from Flo, didn't find any issues ✅
Co-authored-by: Silvan <adlerhurst@users.noreply.github.com>
Summary
Replaces
UserPasswordRepository.Createwith aSetupsert method so password writes (initial set and change) are a single repository call instead of delete-then-create.CreateUserPassword→SetUserPasswordandCreate→Seton the domain interfaceINSERT ... ON CONFLICT (project_id, user_id) DO UPDATEin the repository, resettingfailed_attemptsandlast_successful_checkon updateSetPasswordUserActionto oneSetcall (noDeleteByUserIDfirst)create_userhandler, bootstrap import, fakes, repository tests, and password flow integration testCreate/CreateUserPasswordreferences are now removed from the codebaseValidation
go build ./...— passedgo test ./internal/domain/... ./internal/service/... ./internal/bootstrap/users/...— passedgo test -tags postgres_integration ./internal/storage/database/repository/ -run TestUserPasswordRepository— not run (Docker unavailable in cloud agent VM)Release notes / changeset
No changeset — server-only Go change, no public npm package impact.
Notes
Delete/DeleteByUserIDremain on the interface for explicit removal and CRUD tests. On upsert update the rowidis preserved (unlike the previous delete+insert pattern).