Repository navigation
feat(db): add ItemPrice pricebook table keyed by item code - #370
Conversation
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 <cursoragent@cursor.com>
✅ Deploy Preview for hope-for-haiti ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Disclaimer: This comment was AI-generated and is not necessarily completely accurate. Please take code comments with a grain of salt.
|
| unitPrice Decimal @db.Money | ||
|
|
||
| enteredById Int | ||
| enteredBy User @relation(fields: [enteredById], references: [id]) |
There was a problem hiding this comment.
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
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.
Description
Resolves ticket number: #365
Explain what your code changes:
Adds a new
ItemPrice"pricebook" table to the Prisma schema, keyed by itemcode (NDC), so a drug's price can be stored once per code and reused across
offers instead of being re-entered by hand every time.
ItemPricemodel inprisma/schema.prismawith:ndc(item code) — unique, one row per code, no price historyunitPriceasDecimal @db.Moneyto matchLineItem.unitPriceenteredByrelation toUser(who entered the price)createdAt/updatedAttimestamps (when it was entered), followingexisting schema patterns
itemPrices ItemPrice[]back-relation on theUsermodel (virtualfield only — no column added to the
Usertable)prisma/migrations/20260926192617_add_item_price_table/thatonly creates the
ItemPricetable; no existing table is changedList the steps you took to test your code:
npm run db:migrateto generate the migrationnpx prisma migrate resetto confirm the migration applies cleanly on afresh database
npx prisma validate— schema is validnpm run lint— no warnings or errorsnpm run build— project builds successfullyItemPriceis created and noexisting table is altered
Checklist