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 { 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(); });