ec-nest/prisma/seed.ts
liuyun 198517bde4 feat(c0): 长护服务菜单组 + 目录 seed 骨架
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-10-14 12:42:53 +08:00

47 lines
1.4 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 } from '../src/common/constants.js';
import { initTenant } from '../src/common/tenant-template.js';
import { seedCatalog } from './seed-catalog.js';
const prisma = new PrismaClient();
const TENANT = PLATFORM_TENANT_CODE;
const SUPER_ROLE = PLATFORM_ROLE_CODE;
const ADMIN_USERNAME = 'touyun';
const ADMIN_PASSWORD = 'Touyun@123';
async function main(): Promise<void> {
// 1. 平台租户
await prisma.tenant.upsert({
where: { code: TENANT },
update: { name: '投云', status: 'enabled' },
create: { code: TENANT, name: '投云', status: 'enabled' },
});
// 2. 平台租户初始化(根组织 + 超管角色 + 管理员 + 全量资源 + 内置字典 + 授权)
await initTenant({
prisma,
tenantCode: TENANT,
tenantName: '投云',
adminRoleCode: SUPER_ROLE,
adminRoleName: '超级管理员',
adminUsername: ADMIN_USERNAME,
adminPassword: ADMIN_PASSWORD,
includePlatformPerms: true,
});
// 3. 全局目录 seed(loc_config 骨架 + 国家基准库样例)
await seedCatalog(prisma);
console.log(`seed 完成:平台租户 ${TENANT}、用户 ${ADMIN_USERNAME}、角色 ${SUPER_ROLE}。`);
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});