Skip to content

Commit 723a43a

Browse files
authored
Merge pull request #370 from GTBitsOfGood/vidhi/ndc-schema-build
feat(db): add ItemPrice pricebook table keyed by item code
2 parents d19b7ac + a646c79 commit 723a43a

4 files changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-- CreateTable
2+
CREATE TABLE "ItemPrice" (
3+
"id" SERIAL NOT NULL,
4+
"ndc" TEXT NOT NULL,
5+
"unitPrice" MONEY NOT NULL,
6+
"enteredById" INTEGER NOT NULL,
7+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
8+
"updatedAt" TIMESTAMP(3) NOT NULL,
9+
10+
CONSTRAINT "ItemPrice_pkey" PRIMARY KEY ("id")
11+
);
12+
13+
-- CreateIndex
14+
CREATE UNIQUE INDEX "ItemPrice_ndc_key" ON "ItemPrice"("ndc");
15+
16+
-- AddForeignKey
17+
ALTER TABLE "ItemPrice" ADD CONSTRAINT "ItemPrice_enteredById_fkey" FOREIGN KEY ("enteredById") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

‎prisma/schema.prisma‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ model User {
138138
wishlists Wishlist[]
139139
invite UserInvite?
140140
notifications Notification[]
141+
itemPrices ItemPrice[]
141142
142143
streamUserId String? @unique
143144
streamUserToken String? @unique
@@ -243,6 +244,22 @@ model LineItem {
243244
allocation Allocation? @relation
244245
}
245246

247+
// Pricebook: one row per item code (NDC) holding the price entered by a staff
248+
// member, when it was entered, and who entered it. No price history is kept
249+
// (offers store their own copy of the price they used via LineItem.unitPrice).
250+
model ItemPrice {
251+
id Int @id @default(autoincrement())
252+
253+
ndc String @unique // item code = the identity of the item
254+
unitPrice Decimal @db.Money
255+
256+
enteredById Int
257+
enteredBy User @relation(fields: [enteredById], references: [id])
258+
259+
createdAt DateTime @default(now())
260+
updatedAt DateTime @updatedAt
261+
}
262+
246263
model ItemEmbedding {
247264
id Int @id @default(autoincrement())
248265
generalItemId Int? @unique

‎scripts/clear.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ async function run() {
5454
await tx.donorOffer.deleteMany();
5555
await tx.distribution.deleteMany();
5656
await tx.signOff.deleteMany();
57+
await tx.itemPrice.deleteMany();
5758
await tx.user.deleteMany();
5859
await tx.userInvite.deleteMany();
5960
await tx.generalItem.deleteMany();

‎scripts/seed.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ async function buildSeedData() {
133133
await db.userInvite.deleteMany();
134134
await db.notification.deleteMany();
135135
await db.passwordResetToken.deleteMany();
136+
await db.itemPrice.deleteMany();
136137
await db.user.deleteMany();
137138
await db.tag.deleteMany();
138139

0 commit comments

Comments
 (0)