Commit 5decdd7
fix(database): separate user lifecycle ownership from team membership (#287)
<!-- CURSOR_AGENT_PR_BODY_BEGIN -->
## Summary
Fixes #267
Align user/team storage with [ADR
024](docs/adrs/024-user-team-lifecycle-ownership.md):
- Replace `users.team_id` with nullable `lifecycle_owner_team_id` (NULL
= self-owned, set = team-owned)
- Add `users.status` (active/suspended/deactivated/pending_purge)
- Add `team_memberships` N:N table with membership status
- Add `teams.status` and lifecycle `Deactivate` methods on team/user
repositories
- Remove `ON DELETE CASCADE` on the user/team graph; lifecycle deletes
via repository policy
- Backfill existing `team_id` data in migration
`000011_user_team_lifecycle.sql` (Postgres + Spanner)
## Validation
- `go test -tags=postgres_integration
./internal/storage/database/repository/... -count=1`
- `corepack pnpm run check -- --only go`
## Release notes / changeset
`.changeset/user-team-lifecycle-storage.md` — `@zitadel/server` patch:
align user/team lifecycle storage with ADR 024.
## Notes
Closes #267
Branch merged with `main` before review fixes. Harness mutex fix landed
via #289.
Migration backfill maps legacy `users.team_id` to
`lifecycle_owner_team_id` as a conservative alpha default (old schema
required a team context, so self-serve vs enterprise provenance cannot
be distinguished retroactively). New creates stay self-owned unless
`LifecycleOwnerTeamID` is set.
Acceptance checklist:
- [x] Self-owned user survives team deletion
- [x] Team-owned user deactivated when owning team deleted
- [x] Deleting a user does not cascade-delete teams they created
- [x] No ON DELETE CASCADE on user/team graph
- [x] Team-owned users lose all memberships when owning team is
deactivated
<!-- CURSOR_AGENT_PR_BODY_END -->
<div><a
href="https://cursor.com/agents/bc-f52f2c82-7c40-4962-bf78-39a8915c3d00"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-web-light.png"><img
alt="Open in Web" width="114" height="28"
src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a> <a
href="https://cursor.com/background-agent?bcId=bc-f52f2c82-7c40-4962-bf78-39a8915c3d00"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img
alt="Open in Cursor" width="131" height="28"
src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a> </div>
---------
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Silvan <adlerhurst@users.noreply.github.com>
Co-authored-by: Florian Forster <florian@zitadel.com>1 parent 6d88a39 commit 5decdd7
34 files changed
Lines changed: 1716 additions & 211 deletions
File tree
- .changeset
- internal
- api/integration_test
- bootstrap/users
- domain
- mock
- storage/database
- dialect
- postgres/migration/sql
- user_examples
- spanner/migration/sql
- repository
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
270 | 270 | | |
271 | 271 | | |
272 | 272 | | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
278 | 278 | | |
279 | 279 | | |
280 | 280 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
| 77 | + | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments