sysmgr-nest/prisma/sync-resources.ts
liuyun 86832ce32d feat(session): 在线会话强踢 + 账号锁定/解锁
- JWT 引入 sid,单会话精确强退(sid 黑名单)与按用户踢全部(tokenVersion)
- User 新增 lockedAt/lockReason,登录/刷新/守卫统一拒绝锁定
- sessions 模块:活跃会话列表 + 单会话强退;users 新增 lock/unlock/kick-sessions
- 资源注册 + syncTenantResources 存量租户补齐脚本

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-11 21:35:43 +08:00

31 lines
1.1 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { PrismaClient } from '@prisma/client';
import { PLATFORM_ROLE_CODE, PLATFORM_TENANT_CODE, TENANT_ADMIN_ROLE_CODE } from '../src/common/constants.js';
import { syncTenantResources } from '../src/common/tenant-template.js';
const prisma = new PrismaClient();
/** 为所有存量租户补齐资源/字典/授权(幂等;不触碰用户/密码)。 */
async function main(): Promise<void> {
const tenants = await prisma.tenant.findMany({ select: { code: true } });
for (const t of tenants) {
const isPlatform = t.code === PLATFORM_TENANT_CODE;
await syncTenantResources({
prisma,
tenantCode: t.code,
adminRoleCode: isPlatform ? PLATFORM_ROLE_CODE : TENANT_ADMIN_ROLE_CODE,
includePlatformPerms: isPlatform,
});
console.log(`已同步资源:${t.code}(${isPlatform ? '平台' : '业务'}租户)`);
}
console.log(`syncTenantResources 完成,共 ${tenants.length} 个租户。`);
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});