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 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();