Skip to content

refactor(slm): consolidate User models to single UUID-PK (#1900)#1921

Merged
mrveiss merged 1 commit intoDev_new_guifrom
fix/consolidate-slm-users-1900
Mar 16, 2026
Merged

refactor(slm): consolidate User models to single UUID-PK (#1900)#1921
mrveiss merged 1 commit intoDev_new_guifrom
fix/consolidate-slm-users-1900

Conversation

@mrveiss
Copy link
Owner

@mrveiss mrveiss commented Mar 16, 2026

Summary

  • Consolidate two conflicting SLM User models (integer PK vs UUID PK) into a single UUID-PK model
  • Remove legacy User class from models/database.py (was slm_users table)
  • Update all auth services to use the user_management.models.user.User model
  • Add data migration to move legacy slm_users rows into UUID users table

Files Changed

File Change
models/database.py Removed User class (19 lines)
services/auth.py Import from user_management.models.user; is_adminis_platform_admin, last_loginlast_login_at
main.py _ensure_admin_user() rewritten to use UserService + get_slm_session()
api/auth.py DB session switched from get_db to get_slm_db for user operations
models/schemas.py UserResponse.id accepts UUID; added model_validate override for field mapping
migrations/consolidate_slm_users_to_uuid.py New — migrates slm_users rows to UUID users table, drops slm_users
migrations/runner.py Added migration to runner list

Consolidated User Model (UUID PK)

Single source: user_management/models/user.py with fields: id (UUID), email, username, password_hash, display_name, is_active, is_verified, mfa_enabled, is_platform_admin, preferences (JSONB), last_login_at, created_at, updated_at, deleted_at

Migration Strategy

  1. rename_users_to_slm_users (existing) — renames integer-PK usersslm_users
  2. consolidate_slm_users_to_uuid (new) — reads slm_users rows, inserts into UUID users table, drops slm_users

Safe to re-run. Fresh installs skip automatically (no slm_users table exists).

Notes

  • Docker workaround (separate slm_users database) remains as correct architecture — not a workaround
  • Two login endpoints coexist (/api/auth/login + /api/slm-auth/login) — dedup is a separate task
  • Frontend consuming POST /api/auth/users should be checked for integer-id assumptions (now returns UUID strings)

Test plan

  • SLM starts cleanly with no existing slm_users table (fresh install)
  • Migration runs correctly on existing data (moves rows, drops table)
  • Admin user creation works via _ensure_admin_user()
  • Login via /api/auth/login works with consolidated model
  • UserResponse serializes UUID id correctly

Closes #1900

Remove the legacy integer-PK User class from models/database.py and
consolidate all auth onto the user_management UUID-PK User model.

- Remove User class from models/database.py (was slm_users table)
- Update services/auth.py to import from user_management.models.user
- Update main.py _ensure_admin_user to use UserService
- Update api/auth.py to use slm_users database session
- Update models/schemas.py UserResponse for UUID compatibility
- Add consolidate_slm_users_to_uuid migration to move legacy rows
@mrveiss mrveiss merged commit 7e98fe4 into Dev_new_gui Mar 16, 2026
1 of 3 checks passed
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.

1 participant