box_admin)box_admin.User (prisma/mysql/schema/user.prisma)Role (prisma/mysql/schema/role.prisma)UserRole (prisma/mysql/schema/user-role.prisma)Menu (prisma/mysql/schema/menu.prisma)RoleMenu (prisma/mysql/schema/role-menu.prisma)ApiPermission (prisma/mysql/schema/api-permission.prisma)RoleApiPermission (prisma/mysql/schema/role-api-permission.prisma)LoginLog (prisma/mysql/schema/login-log.prisma)OperationLog (prisma/mysql/schema/operation-log.prisma)QuotaLog (prisma/mysql/schema/quota-log.prisma)CacheSyncAction (prisma/mysql/schema/cache-sync-action.prisma)ImageConfig (schema deleted; no runtime references; table removed before Mongo migration)ProviderVideoSync (model data flows from provider sync code and now lives under prisma/mongo/schema/sys-providerVideoSync.prisma)| Model | Primary Key | Unique Constraints | Relations |
|---|---|---|---|
| User | id (auto-increment int) |
username |
UserRole.userId -> User.id |
| Role | id |
name |
UserRole.roleId -> Role.id, RoleMenu.roleId -> Role.id, RoleApiPermission.roleId -> Role.id |
| UserRole | id |
(userId, roleId) |
userId -> User, roleId -> Role |
| Menu | id |
frontendAuth |
self relation (parentId -> Menu.id), RoleMenu.menuId -> Menu.id, ApiPermission.menuId -> Menu.id |
| RoleMenu | id |
(roleId, menuId) |
roleId -> Role, menuId -> Menu |
| ApiPermission | id |
(menuId, path, method) |
menuId -> Menu, RoleApiPermission.apiPermissionId -> ApiPermission.id |
| RoleApiPermission | id |
(roleId, apiPermissionId) |
roleId -> Role, apiPermissionId -> ApiPermission |
| LoginLog | id |
none | none |
| OperationLog | id |
none | menuId is nullable but not enforced by FK in schema |
| QuotaLog | id |
none | none |
| CacheSyncAction | id (BigInt) |
none | none; indexed by status,nextAttemptAt and entityType,entityId |
MenuType (DIRECTORY, MENU, SUBMENU, BUTTON)LoginType / LoginStatusOperationTypeUser.twoFARecoveryCodes, User.allowIpsMenu.metaOperationLog.body, OperationLog.responseCacheSyncAction.payloadMenu.frontendAuth queried by findUnique in apps/box-mgnt-api/src/mgnt-backend/core/menu/menu.service.tsbox_admin)sys_user
id (int), username, password, status, nick, photo, remark, twoFA, twoFALastUsedStep, twoFARecoveryCodes, allowIps, jwtToken, oAuthJwtToken, lastLoginTime, create_time, update_timeusername, index on status (optional for listing)sys_role
id (int), name, status, remark, create_time, update_timenamesys_user_role
id (int), user_id, role_id, create_time, update_time(user_id, role_id); index on user_id, role_idsys_menu
id (int), parent_id, title, status, type, order, frontend_auth, path, name, icon, redirect, component_key, meta, canView, canCreate, canUpdate, canDelete, create_time, update_timefrontend_auth, index on parent_id, index on typesys_role_menu
id (int), role_id, menu_id, canView, canCreate, canUpdate, canDelete, create_time, update_time(role_id, menu_id); index on role_id, menu_idsys_api_permission
id (int), menu_id, path, method, create_time, update_time(menu_id, path, method); index on menu_idsys_role_api_permission
id (int), role_id, api_permission_id, create_time, update_time(role_id, api_permission_id); index on role_id, api_permission_idsys_login_log
id (int), type, status, username, ip_address, user_agent, create_time, update_timeusername, create_timesys_operation_log
id (int), username, menu_id, description, type, status, method, path, body, response, ip_address, call_method, create_time, update_timeusername, menu_id, create_timesys_quota_log
id (int), username, op_username, amount, is_inc, quota, remark, create_time, update_timeusername, create_timecache_sync_action
id (long), entityType, entityId, operation, status, attempts, nextAttemptAt, lastError, payload, createdAt, updatedAt(status, nextAttemptAt), (entityType, entityId)prisma/mongo/schema/sys-user.prisma → maps to sys_user (mirrors prisma/mysql/schema/user.prisma)prisma/mongo/schema/sys-role.prisma → maps to sys_roleprisma/mongo/schema/sys-user-role.prisma → maps to sys_user_roleprisma/mongo/schema/sys-menu.prisma → maps to sys_menuprisma/mongo/schema/sys-role-menu.prisma → maps to sys_role_menuprisma/mongo/schema/sys-api-permission.prisma → maps to sys_api_permissionprisma/mongo/schema/sys-role-api-permission.prisma → maps to sys_role_api_permissionprisma/mongo/schema/sys-login-log.prisma → maps to sys_login_logprisma/mongo/schema/sys-operation-log.prisma → maps to sys_operation_logprisma/mongo/schema/sys-cache-sync-action.prisma → maps to sys_cacheSyncAction (preserves BigInt PK/indexes from the MySQL schema)prisma/mongo/schema/sys-providerVideoSync.prisma → maps to sys_providerVideoSync (moved out of prisma/mysql/schema/main.prisma so Mongo owns the provider sync store)sys_quota_log intentionally remains only in MySQL; no Mongo schema file is created so Mongo services keep relying on the existing prisma/mysql/schema/quota-log.prisma.Every Mongo schema file uses @@map("sys_<table>") so the collection name stays aligned with the MySQL table while Prisma now loads the Mongo-friendly schema per file.
User.id, Role.id, Menu.id).| Schema | Mgnt service(s) still touching it | What to verify before cut-over |
|---|---|---|
sys_user |
apps/box-mgnt-api/src/mgnt-backend/core/user/user.service.ts (User CRUD/role assignment) and apps/box-mgnt-api/src/mgnt-backend/core/auth/auth.service.ts (lookup during login). |
Ensure SysUser stays feature-compatible while token, password/2FA, and role-linking flows move to the Mongo client. |
sys_role |
apps/box-mgnt-api/src/mgnt-backend/core/role/role.service.ts. |
Confirm role creation/updating in Mongo respects the same Menu grants and status flags. |
sys_user_role |
user.service.ts (link/unlink roles) and role.service.ts (read assignments). |
Validate transactional user+role updates work once sys_user_role is served from Mongo. |
sys_menu |
apps/box-mgnt-api/src/mgnt-backend/core/menu/menu.service.ts, role.service.ts (menu grant computations), and operation-log.service.ts (frontendAuth lookup). |
Keep the menu tree, related meta, and frontendAuth resolution identical in Mongo. |
sys_role_menu |
role.service.ts (grant storage). |
Ensure create/delete/replace flows still maintain (roleId, menuId) uniqueness. |
sys_api_permission |
menu.service.ts (API-permission CRUD) and role.service.ts (permission-based exports). |
Preserve (menuId, path, method) uniqueness and any joins/resets. |
sys_role_api_permission |
role.service.ts (grant updates / queries). |
Confirm transactions that delete/recreate role-permission links continue to run. |
sys_login_log |
apps/box-mgnt-api/src/mgnt-backend/core/logging/login-log/login-log.service.ts and the auth flow (via LoginLogService). |
Logins will keep writing to SysLoginLog for auditing, so the new Mongo collection must mirror the MySQL schema. |
sys_operation_log |
apps/box-mgnt-api/src/mgnt-backend/core/logging/operation-log/operation-log.service.ts (and the decorator/operation-log controller that reads it). |
Validate the operation decorator still resolves menuId via MenuService and writes request/response bodies as JSON. |
sys_cacheSyncAction |
apps/box-mgnt-api/src/cache-sync/cache-sync.service.ts (queue callback) plus every mgnt feature (ads/category/channel/tag/video) that calls it and the cache-sync controllers/checklist services. |
The durable action queue must keep its BigInt PK/indexes and retry semantics while CacheSyncService continues scheduling old entity types. |
sys_providerVideoSync |
apps/box-mgnt-api/src/mgnt-backend/feature/provider-video-sync/provider-video-sync.service.ts. |
Provider sync writes counts/counters to Mongo, so verify the new collection respects the original lastSyncedAt/syncStatus semantics. |
sys_* models; the next checkpoint is to implement a counters collection (e.g., { _id: "sys_user", seq: 123 }) so each Mongo schema can request the next integer ID before inserting.Sys* collection has Prisma + service wiring in place; the CounterService can live alongside the Mongo Prisma client or inside a shared @box/db helper.UserRole (list, get, update)
apps/box-mgnt-api/src/mgnt-backend/core/user/user.service.tsinclude on userRoles.role and where clauses with userRoles.someRoleMenu (get permissions)
apps/box-mgnt-api/src/mgnt-backend/core/role/role.service.tsApiPermission + RoleApiPermission
apps/box-mgnt-api/src/mgnt-backend/core/menu/menu.service.tsapps/box-mgnt-api/src/mgnt-backend/core/menu/menu.service.tsRoleService.create and RoleService.update use $transaction to insert role + roleMenu or replace roleMenuUserService.create, UserService.update, UserService.delete use $transaction to change user and userRole togetherMenuService.updatePermission deletes roleApiPermission + apiPermission, then recreates in a $transactionMenuService.delete deletes roleMenu + menu in a $transactionUserService.list and RoleService.list use $transaction to fetch list + countsys_user_role, sys_role_menu, sys_role_api_permission) and perform multi-step queries in services.roleIds on sys_user and menuIds on sys_role) to reduce query count.include and some relational filters with:
$lookup aggregation pipelines (only if performance is acceptable)counters with { _id: "sys_user", seq: 123 }).prisma/mysql/schema/user.prismaprisma/mysql/schema/role.prismaprisma/mysql/schema/user-role.prismaprisma/mysql/schema/menu.prismaprisma/mysql/schema/role-menu.prismaprisma/mysql/schema/api-permission.prismaprisma/mysql/schema/role-api-permission.prismaprisma/mysql/schema/login-log.prismaprisma/mysql/schema/operation-log.prismaprisma/mysql/schema/quota-log.prismaprisma/mysql/schema/cache-sync-action.prisma