From 8fd3b55830f256e1d2ff029fed5472d340aaf9b5 Mon Sep 17 00:00:00 2001 From: "Vaidehi (Vidhi) Gupta" Date: Sat, 26 Sep 2026 15:18:07 -0400 Subject: [PATCH 1/2] feat(db): add ItemPrice pricebook table keyed by item code Add a standalone ItemPrice table (pricebook) with one row per item code (NDC), holding the price, when it was entered, and which user entered it. No price history is kept; offers keep their own copy via LineItem.unitPrice. - ndc is unique (one row per code) - unitPrice uses Decimal @db.Money to match LineItem.unitPrice - enteredBy links to User; createdAt/updatedAt follow existing patterns - additive migration creates only the ItemPrice table (no existing table changed) Co-authored-by: Cursor --- .../migration.sql | 17 +++++++++++++++++ prisma/schema.prisma | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 prisma/migrations/20260926192617_add_item_price_table/migration.sql diff --git a/prisma/migrations/20260926192617_add_item_price_table/migration.sql b/prisma/migrations/20260926192617_add_item_price_table/migration.sql new file mode 100644 index 00000000..79dcbb60 --- /dev/null +++ b/prisma/migrations/20260926192617_add_item_price_table/migration.sql @@ -0,0 +1,17 @@ +-- CreateTable +CREATE TABLE "ItemPrice" ( + "id" SERIAL NOT NULL, + "ndc" TEXT NOT NULL, + "unitPrice" MONEY NOT NULL, + "enteredById" INTEGER NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "ItemPrice_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "ItemPrice_ndc_key" ON "ItemPrice"("ndc"); + +-- AddForeignKey +ALTER TABLE "ItemPrice" ADD CONSTRAINT "ItemPrice_enteredById_fkey" FOREIGN KEY ("enteredById") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 2ded52e6..9f7a40cf 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -138,6 +138,7 @@ model User { wishlists Wishlist[] invite UserInvite? notifications Notification[] + itemPrices ItemPrice[] streamUserId String? @unique streamUserToken String? @unique @@ -243,6 +244,22 @@ model LineItem { allocation Allocation? @relation } +// Pricebook: one row per item code (NDC) holding the price entered by a staff +// member, when it was entered, and who entered it. No price history is kept +// (offers store their own copy of the price they used via LineItem.unitPrice). +model ItemPrice { + id Int @id @default(autoincrement()) + + ndc String @unique // item code = the identity of the item + unitPrice Decimal @db.Money + + enteredById Int + enteredBy User @relation(fields: [enteredById], references: [id]) + + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt +} + model ItemEmbedding { id Int @id @default(autoincrement()) generalItemId Int? @unique From a646c7908f44f618332db3003c8acbd34f5938ef Mon Sep 17 00:00:00 2001 From: ezraexe Date: Sun, 4 Oct 2026 18:20:52 -0400 Subject: [PATCH 2/2] fixing seeds --- scripts/clear.ts | 1 + scripts/seed.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/scripts/clear.ts b/scripts/clear.ts index dab425c1..8425c347 100644 --- a/scripts/clear.ts +++ b/scripts/clear.ts @@ -54,6 +54,7 @@ async function run() { await tx.donorOffer.deleteMany(); await tx.distribution.deleteMany(); await tx.signOff.deleteMany(); + await tx.itemPrice.deleteMany(); await tx.user.deleteMany(); await tx.userInvite.deleteMany(); await tx.generalItem.deleteMany(); diff --git a/scripts/seed.ts b/scripts/seed.ts index 3406e7fc..1669939f 100644 --- a/scripts/seed.ts +++ b/scripts/seed.ts @@ -133,6 +133,7 @@ async function buildSeedData() { await db.userInvite.deleteMany(); await db.notification.deleteMany(); await db.passwordResetToken.deleteMany(); + await db.itemPrice.deleteMany(); await db.user.deleteMany(); await db.tag.deleteMany();