修改prisma适配原有表
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
-- This migration is a placeholder because the tables already exist in the database
|
||||
-- The tables tb_consumable_goods and tb_consumable_sku were created outside of Prisma
|
||||
|
||||
-- No actual schema changes needed
|
||||
@@ -0,0 +1,8 @@
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `易耗品临时申请_易耗品条目` DROP FOREIGN KEY `易耗品临时申请_易耗品条目_catalogId_fkey`;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `易耗品临时申请_易耗品条目` DROP COLUMN `catalogId`;
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE `易耗品目录`;
|
||||
+69
-55
@@ -10,78 +10,92 @@ datasource db {
|
||||
|
||||
/// 申请单(“易耗品临时申请”)
|
||||
model v2_ConsumableTempRequest {
|
||||
id String @id @default(cuid())
|
||||
applicantName String? // 申请人姓名(可选)
|
||||
applicantPhone String // 申请人手机号
|
||||
department String? // 部门(可选)
|
||||
reason String? // 申请事由(可选)
|
||||
neededAt DateTime? // 期望领用时间(可选)
|
||||
|
||||
status v2_ConsumableTempRequestStatus @default(PENDING)
|
||||
approverId String? // 审批人(可选:员工ID/账号)
|
||||
approvedAt DateTime? // 审批时间(可选)
|
||||
remark String? // 备注(可选)
|
||||
|
||||
// 一对多:申请单包含多条物料明细
|
||||
id String @id @default(cuid())
|
||||
applicantName String?
|
||||
applicantPhone String
|
||||
department String?
|
||||
reason String?
|
||||
neededAt DateTime?
|
||||
status v2_ConsumableTempRequestStatus @default(PENDING)
|
||||
approverId String?
|
||||
approvedAt DateTime?
|
||||
remark String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
items v2_ConsumableTempRequestItem[]
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@index([applicantPhone, createdAt])
|
||||
@@index([status, createdAt])
|
||||
|
||||
// 如需将表名映射为中文(或你既有库的真实表名),取消下一行注释:
|
||||
@@map("易耗品临时申请")
|
||||
}
|
||||
|
||||
/// 申请明细(易耗品条目)
|
||||
model v2_ConsumableTempRequestItem {
|
||||
id String @id @default(cuid())
|
||||
|
||||
requestId String
|
||||
request v2_ConsumableTempRequest @relation(fields: [requestId], references: [id], onDelete: Cascade)
|
||||
|
||||
name String // 物料名称(如“打印纸”)
|
||||
spec String? // 规格/型号(如“A4 70g”)
|
||||
quantity Int // 数量
|
||||
unit String? // 单位(如“包/箱/个”)
|
||||
estimatedUnitCost Decimal? // 预估单价(可选)
|
||||
remark String? // 明细备注(可选)
|
||||
|
||||
// 如果你有物料目录表,可在此做可选关联(下面给了 Catalog 模型)
|
||||
catalogId String?
|
||||
catalog v2_ConsumableTempCatalog? @relation(fields: [catalogId], references: [id])
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
id String @id @default(cuid())
|
||||
requestId String
|
||||
name String
|
||||
spec String?
|
||||
quantity Int
|
||||
unit String?
|
||||
estimatedUnitCost Decimal?
|
||||
remark String?
|
||||
catalogId String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
request v2_ConsumableTempRequest @relation(fields: [requestId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([requestId])
|
||||
@@index([name])
|
||||
// 如需把表名映射为既有库命名,取消注释并替换:
|
||||
@@index([catalogId], map: "易耗品临时申请_易耗品条目_catalogId_fkey")
|
||||
@@map("易耗品临时申请_易耗品条目")
|
||||
}
|
||||
|
||||
/// 可选:物料目录(如你已有标准物料清单,便于下拉选择)
|
||||
model v2_ConsumableTempCatalog {
|
||||
id String @id @default(cuid())
|
||||
name String
|
||||
spec String?
|
||||
unit String?
|
||||
isActive Boolean @default(true)
|
||||
model tb_consumable_goods {
|
||||
id BigInt @id @default(autoincrement())
|
||||
goods_name String @db.VarChar(100)
|
||||
category_id BigInt?
|
||||
brand String? @db.VarChar(50)
|
||||
status Int? @default(0) @db.TinyInt
|
||||
create_time DateTime? @default(now()) @db.Timestamp(0)
|
||||
update_time DateTime? @default(now()) @db.Timestamp(0)
|
||||
delete_flag Boolean? @default(false)
|
||||
hosp_id String? @db.VarChar(32)
|
||||
|
||||
// 反向关系:哪些申请明细引用了该条目录
|
||||
requestItems v2_ConsumableTempRequestItem[]
|
||||
// 关联 SKU
|
||||
tb_consumable_sku tb_consumable_sku[]
|
||||
|
||||
@@unique([name, spec, unit])
|
||||
@@index([isActive])
|
||||
@@map("易耗品目录")
|
||||
@@index([category_id], map: "idx_goods_category")
|
||||
}
|
||||
|
||||
model tb_consumable_sku {
|
||||
id BigInt @id @default(autoincrement())
|
||||
goods_id BigInt
|
||||
sku_code String? @unique(map: "uk_sku_code") @db.VarChar(50)
|
||||
specification String? @db.VarChar(200)
|
||||
barcode String @unique(map: "uk_sku_barcode") @db.VarChar(50)
|
||||
supplier_id BigInt?
|
||||
purchase_price Decimal? @db.Decimal(10, 2)
|
||||
selling_price Decimal? @db.Decimal(10, 2)
|
||||
unit String? @db.VarChar(20)
|
||||
min_stock Int? @default(0)
|
||||
max_stock Int?
|
||||
status Int? @default(0) @db.TinyInt
|
||||
create_time DateTime? @default(now()) @db.Timestamp(0)
|
||||
update_time DateTime? @default(now()) @db.Timestamp(0)
|
||||
delete_flag Boolean? @default(false)
|
||||
hosp_id String? @db.VarChar(32)
|
||||
|
||||
// 关联商品
|
||||
tb_consumable_goods tb_consumable_goods @relation(fields: [goods_id], references: [id])
|
||||
|
||||
@@index([goods_id], map: "idx_sku_goods")
|
||||
@@index([supplier_id], map: "idx_sku_supplier")
|
||||
}
|
||||
|
||||
enum v2_ConsumableTempRequestStatus {
|
||||
PENDING // 待审批
|
||||
APPROVED // 通过
|
||||
REJECTED // 驳回
|
||||
CANCELLED // 取消
|
||||
COMPLETED // 已完成(已领用)
|
||||
}
|
||||
PENDING
|
||||
APPROVED
|
||||
REJECTED
|
||||
CANCELLED
|
||||
COMPLETED
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user