Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
17 changes: 17 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ model User {
wishlists Wishlist[]
invite UserInvite?
notifications Notification[]
itemPrices ItemPrice[]

streamUserId String? @unique
streamUserToken String? @unique
Expand Down Expand Up @@ -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])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Price entries block user deletion

Once a pricebook entry exists, this required relation prevents its user from being deleted. Both db:seed and db:clear delete users without first deleting pricebook entries, so those reset workflows fail. Because db:seed does not run its deletions in a transaction, it can leave the database partly cleared. Delete pricebook entries before users, or define the intended deletion behavior.

Knowledge Base Used: Data model and operational tooling


createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

model ItemEmbedding {
id Int @id @default(autoincrement())
generalItemId Int? @unique
Expand Down
1 change: 1 addition & 0 deletions scripts/clear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions scripts/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Loading