NM-272: Migrate Pending Users and User Invites#3965
Conversation
1. Schema Definition for Pending Users table. 2. Use the newer table everywhere. 3. Migration stubs for v1.5.2. 4. Migration code for Pending Users table;
|
VishalDalwadi does not have a Code Reviewer seat assigned. All seats are in use — you can purchase additional seats in billing. |
1. Schema Definition for User Invites table. 2. Use the newer table everywhere. 3. Migration code for User Invites table;
|
Tenki Code Review - Complete Files Reviewed: 16 By Severity:
This PR migrates Files Reviewed (16 files) |
There was a problem hiding this comment.
Risk: 🟡 Medium (45/100) — 2 medium findings, 1 low · 700 LOC across 16 files
Overview
This PR completes the SQL schema migration for PendingUser and UserInvite models, adding new schema.PendingUser and schema.UserInvite GORM models, a new migrateV1_5_2 migration step, and refactoring the business logic and OAuth callbacks to use the new schema types directly.
Functional Regression: NetworkRoles Silently Dropped
The most impactful issue is a silent data loss regression in schema/user_invites.go. The old models.UserInvite struct contained a NetworkRoles field (map[schema.NetworkID]map[schema.UserRoleID]struct{}). The new schema.UserInvite omits this field entirely. This affects:
- New invites created via
inviteUsersinpro/controllers/users.go: theinviteReq.NetworkRolesfrom the request body is now silently discarded. - Existing invite migration in
migrate/migrate_v1_5_2.go:NetworkRolesfrom KV-store invites is not mapped to the new struct. - User signup from invite in
PrepareOauthUserFromInviteanduserInviteSignUp: network role assignment is never applied.
Transaction Commit Semantics Change
In the refactored migrate/migrate_schema.go, the single outer transaction now covers both v1.5.1 and v1.5.2 migration steps. In the old code, commit = true was set immediately after v1.5.1 succeeded. Now if v1.5.2 fails, the deferred Rollback() will also undo the v1.5.1 job marker, causing v1.5.1 to attempt re-execution on the next restart — which could result in duplicate key errors against existing SQL rows.
Raw SQL Table Name Concatenation
The fetchAll function in migrate/migrate_schema.go (also present in the original migrate_v1_5_1.go) builds a raw SQL query by direct string concatenation of tableName. Current callers pass only hardcoded database.*_TABLE_NAME constants, so there is no active injection risk, but the function has no guard against misuse.
…ommitting before moving to the next
Describe your changes
Provide Issue ticket number if applicable/not in title
Provide testing steps
Checklist before requesting a review