From 4704adcba126e650c8da9234f669f253351732c0 Mon Sep 17 00:00:00 2001 From: wangziqi Date: Thu, 2 Jul 2026 14:31:51 +0800 Subject: [PATCH] fix: replace orIgnore with findOne for SQLite compat; set backend port 3003 --- backend/src/main.ts | 4 ++-- backend/src/rbac/rbac.service.ts | 26 +++++++++++--------------- frontend/vite.config.ts | 2 +- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/backend/src/main.ts b/backend/src/main.ts index 718c548..04ea33e 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -7,7 +7,7 @@ async function bootstrap() { app.setGlobalPrefix('api'); app.enableCors(); app.useGlobalPipes(new ValidationPipe({ transform: true, whitelist: true })); - await app.listen(process.env.PORT ?? 3001); - console.log(`Server running on http://localhost:${process.env.PORT ?? 3001}`); + await app.listen(process.env.PORT ?? 3003); + console.log(`Server running on http://localhost:${process.env.PORT ?? 3003}`); } bootstrap(); diff --git a/backend/src/rbac/rbac.service.ts b/backend/src/rbac/rbac.service.ts index 6c4a35b..dccc19c 100644 --- a/backend/src/rbac/rbac.service.ts +++ b/backend/src/rbac/rbac.service.ts @@ -109,27 +109,23 @@ export class RbacService { ) {} async seedData(): Promise { - // Step 1: 幂等插入所有权限点 + // Step 1: 幂等插入所有权限点(先查后插,兼容 SQLite/MySQL) for (const p of PRESET_PERMISSIONS) { - await this.permRepo - .createQueryBuilder() - .insert() - .into(Permission) - .values(p) - .orIgnore() - .execute(); + const exists = await this.permRepo.findOne({ where: { code: p.code } }); + if (!exists) { + await this.permRepo.save(this.permRepo.create(p)); + } } const allPerms = await this.permRepo.find(); // Step 2: 幂等插入预置角色 for (const r of PRESET_ROLES) { - await this.roleRepo - .createQueryBuilder() - .insert() - .into(Role) - .values({ name: r.name, description: r.description, isSystem: r.isSystem }) - .orIgnore() - .execute(); + const exists = await this.roleRepo.findOne({ where: { name: r.name } }); + if (!exists) { + await this.roleRepo.save( + this.roleRepo.create({ name: r.name, description: r.description, isSystem: r.isSystem }), + ); + } } const allRoles = await this.roleRepo.find({ relations: ['permissions'] }); diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 6e79f2c..0b3ce82 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -8,7 +8,7 @@ export default defineConfig({ port: 3002, proxy: { '/api': { - target: 'http://localhost:3001', + target: 'http://localhost:3003', changeOrigin: true, }, },