Skip to content

refactor(database): replace UserPasswordRepository Create with Set upsert - #292

Merged
muhlemmer merged 4 commits into
mainfrom
cursor/password-repo-set-upsert-7695
Jun 23, 2026
Merged

refactor(database): replace UserPasswordRepository Create with Set upsert#292
muhlemmer merged 4 commits into
mainfrom
cursor/password-repo-set-upsert-7695

Conversation

@adlerhurst

@adlerhurst adlerhurst commented Jun 15, 2026

Copy link
Copy Markdown
Member

Summary

Replaces UserPasswordRepository.Create with a Set upsert method so password writes (initial set and change) are a single repository call instead of delete-then-create.

  • Renames CreateUserPasswordSetUserPassword and CreateSet on the domain interface
  • Implements PostgreSQL INSERT ... ON CONFLICT (project_id, user_id) DO UPDATE in the repository, resetting failed_attempts and last_successful_check on update
  • Simplifies SetPasswordUserAction to one Set call (no DeleteByUserID first)
  • Updates flow create_user handler, bootstrap import, fakes, repository tests, and password flow integration test
  • All Create / CreateUserPassword references are now removed from the codebase

Validation

  • go build ./... — passed
  • go test ./internal/domain/... ./internal/service/... ./internal/bootstrap/users/... — passed
  • go 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 / DeleteByUserID remain on the interface for explicit removal and CRUD tests. On upsert update the row id is preserved (unlike the previous delete+insert pattern).

Open in Web Open in Cursor 

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>
@vercel

vercel Bot commented Jun 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nextgen Error Error Jun 23, 2026 4:19am
nextgen-docs Error Error Jun 23, 2026 4:19am

Request Review

@adlerhurst
adlerhurst marked this pull request as ready for review June 15, 2026 14:19
Copilot AI review requested due to automatic review settings June 15, 2026 14:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/Create to SetUserPassword/Set.
  • Updates the Postgres repository write to INSERT ... ON CONFLICT (project_id, user_id) DO UPDATE, resetting failed_attempts and last_successful_check on 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.

@vercel

vercel Bot commented Jun 19, 2026

Copy link
Copy Markdown

@adlerhurst must be a member of the zitadel team on Vercel to deploy.
- Click here to add @adlerhurst to the team.
- If you initiated this build, request access.

Learn more about collaboration on Vercel and other options here.

@github-actions

github-actions Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

⚠️ No Changeset found

Latest commit: ee493aa

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Comment thread internal/domain/user_password.go

@muhlemmer muhlemmer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the comments from Flo, didn't find any issues ✅

Co-authored-by: Silvan <adlerhurst@users.noreply.github.com>
@muhlemmer
muhlemmer merged commit 0a8f00b into main Jun 23, 2026
5 of 7 checks passed
@muhlemmer
muhlemmer deleted the cursor/password-repo-set-upsert-7695 branch June 23, 2026 05:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants