From f842c508b76d88042e67047d9785b6b42797a8d4 Mon Sep 17 00:00:00 2001 From: WuYongJie Date: Tue, 10 Mar 2026 19:13:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=B5=84=E4=BA=A7=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E7=AE=80=E7=A7=B0=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20260310_drop_asset_type_short_name_unique/migration.sql | 4 ++++ backend/prisma/schema.prisma | 3 ++- backend/src/controllers/assetTypeController.ts | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 backend/prisma/migrations/20260310_drop_asset_type_short_name_unique/migration.sql diff --git a/backend/prisma/migrations/20260310_drop_asset_type_short_name_unique/migration.sql b/backend/prisma/migrations/20260310_drop_asset_type_short_name_unique/migration.sql new file mode 100644 index 0000000..67715a6 --- /dev/null +++ b/backend/prisma/migrations/20260310_drop_asset_type_short_name_unique/migration.sql @@ -0,0 +1,4 @@ +DROP INDEX `asset_type_short_name_key` ON `asset_type`; + +CREATE INDEX `asset_type_short_name_idx` + ON `asset_type`(`short_name`); diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index 2f56ff9..5d1c34b 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -13,7 +13,7 @@ datasource db { model AssetType { id Int @id @default(autoincrement()) name String @unique @db.VarChar(50) - short_name String? @unique @db.VarChar(20) + short_name String? @db.VarChar(20) status String @default("active") @db.VarChar(20) can_be_parent Boolean @default(false) // 可作为父资产 can_be_child Boolean @default(false) // 可作为子资产 @@ -23,6 +23,7 @@ model AssetType { equipments Equipment[] @@index([status]) + @@index([short_name]) @@map("asset_type") } diff --git a/backend/src/controllers/assetTypeController.ts b/backend/src/controllers/assetTypeController.ts index 9e04005..95f24c6 100644 --- a/backend/src/controllers/assetTypeController.ts +++ b/backend/src/controllers/assetTypeController.ts @@ -116,7 +116,7 @@ export const createAssetType = async (req: Request, res: Response) => { successResponse(res, assetType, '新增资产类型成功') } catch (error: any) { if (error.code === 'P2002') { - return errorResponse(res, '类型名称或简称已存在') + return errorResponse(res, '类型名称已存在') } errorResponse(res, error.message || '新增资产类型失败') } @@ -168,7 +168,7 @@ export const updateAssetType = async (req: Request, res: Response) => { successResponse(res, updated, '更新资产类型成功') } catch (error: any) { if (error.code === 'P2002') { - return errorResponse(res, '类型名称或简称已存在') + return errorResponse(res, '类型名称已存在') } errorResponse(res, error.message || '更新资产类型失败') }