| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import { MenuType, PrismaClient } from '@prisma/mysql/client';
- const prisma = new PrismaClient();
- async function createUsers() {
- const role = await prisma.role.create({
- data: {
- name: '管理员',
- remark: '管理员专用',
- },
- });
- const adminUser = await prisma.user.create({
- data: {
- username: 'admin',
- password: '$2b$12$iS0UJ1YqSal0N3uwin/OvOABUINAclcZGjHNyGFC7mlwRYTFjGQ26',
- // $2b$12$W9.5wXqjTtHgBilPFpPx2.lpIvrY.HpnHSrEURg9YBiV3e/8tfn3m
- remark: '默认拥有所有菜单权限,不需要配置角色',
- // allowIps: ['127.0.0.1'],
- // quota: 1000000,
- },
- });
- await prisma.userRole.create({
- data: {
- userId: adminUser.id,
- roleId: role.id,
- },
- });
- }
- async function main() {
- console.log('开始初始化数据库...');
- await createUsers();
- console.log('数据库初始化完成');
- }
- main()
- .then(async () => {
- await prisma.$disconnect();
- })
- .catch(async (e) => {
- console.error(e);
- await prisma.$disconnect();
- process.exit(1);
- });
|