Skip to content

feat(db): add ItemPrice pricebook table keyed by item code - #370

Merged
ezraexe merged 2 commits into
mainfrom
vidhi/ndc-schema-build
Oct 4, 2026
Merged

ezraexe merged 2 commits into
mainfrom
vidhi/ndc-schema-build

Conversation

@vidhigupta413

Copy link
Copy Markdown
Contributor

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)

Description

Resolves ticket number: #365

Explain what your code changes:
Adds a new ItemPrice "pricebook" table to the Prisma schema, keyed by item
code (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.

  • New ItemPrice model in prisma/schema.prisma with:
    • ndc (item code) — unique, one row per code, no price history
    • unitPrice as Decimal @db.Money to match LineItem.unitPrice
    • enteredBy relation to User (who entered the price)
    • createdAt / updatedAt timestamps (when it was entered), following
      existing schema patterns
  • Adds an itemPrices ItemPrice[] back-relation on the User model (virtual
    field only — no column added to the User table)
  • New migration prisma/migrations/20260926192617_add_item_price_table/ that
    only creates the ItemPrice table; no existing table is changed

List the steps you took to test your code:

  • Ran npm run db:migrate to generate the migration
  • Ran npx prisma migrate reset to confirm the migration applies cleanly on a
    fresh database
  • Ran npx prisma validate — schema is valid
  • Ran npm run lint — no warnings or errors
  • Ran npm run build — project builds successfully
  • Reviewed the generated SQL to confirm only ItemPrice is created and no
    existing table is altered

Checklist

  • The ticket is mentioned above
  • The changes fulfill the success criteria of the ticket
  • The changes were self-reviewed
  • A review was requested

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>
@netlify

netlify Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for hope-for-haiti ready!

Name Link
🔨 Latest commit a646c79
🔍 Latest deploy log https://app.netlify.com/projects/hope-for-haiti/deploys/6ac2d14f11be63000817b027
😎 Deploy Preview https://deploy-preview-370--hope-for-haiti.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@greptile-apps

greptile-apps Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Disclaimer: This comment was AI-generated and is not necessarily completely accurate. Please take code comments with a grain of salt.

RetriggerConfidence Score: 4/5

[Critical risk] Adds database table for item pricing data.

The PR should not merge until seed and clear can delete users after pricebook entries exist.

Findings

  1. P1 Price entries block user deletion ▶

Summary

Adds an NDC-keyed ItemPrice table with a price, timestamps, and a required link to the user who entered it.

  • Backend improvement needed: make seed and clear workflows compatible with the new user relation.
  • Owner checklist score: 85/100.
Diagram
%%{init: {'theme': 'neutral'}}%%
erDiagram
  User ||--o{ ItemPrice : enteredBy
  ItemPrice {
    int id PK
    string ndc UK
    decimal unitPrice
    int enteredById FK
  }
  LineItem {
    int id PK
    decimal unitPrice
  }
Loading

Reviews (1) · Last reviewed commit: "feat(db): add ItemPrice pricebook table ..."

Comment thread prisma/schema.prisma
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

@ezraexe
ezraexe merged commit 723a43a into main Oct 4, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants