manicanldes-backend/prisma/partner-orders.prisma

65 lines
3.3 KiB
Plaintext

model B2bPartnerOrder {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
accountId String @map("account_id") @db.Uuid
quoteId String @map("quote_id") @db.Uuid
createdById String @map("created_by_id") @db.Uuid
number String @db.VarChar(24)
partnerReference String @map("partner_reference") @db.VarChar(80)
note String? @db.VarChar(500)
accountSnapshot Json @map("account_snapshot") @db.JsonB
currency String @db.Char(3)
merchandiseTotal Decimal @map("merchandise_total") @db.Decimal(18,2)
idempotencyKey String @map("idempotency_key") @db.Uuid
requestHash String @map("request_hash") @db.Char(64)
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Restrict)
account BusinessAccount @relation(fields: [accountId, organizationId], references: [id, organizationId], onDelete: Restrict)
quote B2bQuote @relation(fields: [quoteId, organizationId], references: [id, organizationId], onDelete: Restrict)
createdBy User @relation(fields: [createdById, organizationId], references: [id, organizationId], onDelete: Restrict)
lines B2bPartnerOrderLine[]
cancellation B2bPartnerOrderCancellation?
@@unique([id, organizationId])
@@unique([organizationId, number])
@@unique([quoteId, organizationId])
@@unique([organizationId, accountId, partnerReference])
@@unique([organizationId, idempotencyKey])
@@index([organizationId, accountId, createdAt, id])
@@map("b2b_partner_orders")
}
model B2bPartnerOrderLine {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
orderId String @map("order_id") @db.Uuid
variantId String @map("variant_id") @db.Uuid
sku String @db.VarChar(64)
name String @db.VarChar(160)
quantity Int
minQuantity Int @map("min_quantity")
unitPrice Decimal @map("unit_price") @db.Decimal(12,2)
lineTotal Decimal @map("line_total") @db.Decimal(18,2)
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Restrict)
order B2bPartnerOrder @relation(fields: [orderId, organizationId], references: [id, organizationId], onDelete: Restrict)
variant ProductVariant @relation(fields: [variantId, organizationId], references: [id, organizationId], onDelete: Restrict)
@@unique([orderId, variantId])
@@index([organizationId, orderId, id])
@@map("b2b_partner_order_lines")
}
model B2bPartnerOrderCancellation {
orderId String @id @map("order_id") @db.Uuid
organizationId String @map("organization_id") @db.Uuid
actorId String @map("actor_id") @db.Uuid
reason String @db.VarChar(500)
idempotencyKey String @map("idempotency_key") @db.Uuid
requestHash String @map("request_hash") @db.Char(64)
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Restrict)
order B2bPartnerOrder @relation(fields: [orderId, organizationId], references: [id, organizationId], onDelete: Restrict)
actor User @relation(fields: [actorId, organizationId], references: [id, organizationId], onDelete: Restrict)
@@unique([orderId, organizationId])
@@unique([organizationId, idempotencyKey])
@@map("b2b_partner_order_cancellations")
}