From 41a30d18559e952b136cb74f7800efadad986842 Mon Sep 17 00:00:00 2001 From: Sundog Date: Wed, 1 Nov 2023 09:34:33 -0400 Subject: [PATCH] updates models and schema doc, adds final purchase related tables --- MODELS.md | 2 +- SCHEMA.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/MODELS.md b/MODELS.md index 45d3957..1c733f5 100644 --- a/MODELS.md +++ b/MODELS.md @@ -467,7 +467,7 @@ struct Purchase { id: String, items: Vec, state: PurchaseState, - purchased_by: Person, + purchased_by: Option, purchased_at: Option, fulfilled_by: Option, fulfilled_at: Option, diff --git a/SCHEMA.md b/SCHEMA.md index 96c4ac8..de862ba 100644 --- a/SCHEMA.md +++ b/SCHEMA.md @@ -909,4 +909,58 @@ CREATE TABLE CouponCodeSkus ( CONSTRAINT CouponCodeSkus_FK FOREIGN KEY (coupon_code_id) REFERENCES CouponCodes(id), CONSTRAINT CouponCodeSkus_FK_1 FOREIGN KEY (sku_id) REFERENCES Skus(id) ); +``` + +# Purchases +The Purchases table will contain Purchases! + +``` sql +CREATE TABLE Purchases ( + id TEXT(36), + state TEXT, + purchased_by TEXT(36), + purchased_at INTEGER, + fulfilled_by TEXT(36), + fulfilled_at INTEGER, + total_charge NUMERIC DEFAULT (0.00), + CONSTRAINT Purchases_PK PRIMARY KEY (id), + CONSTRAINT Purchases_FK FOREIGN KEY (purchased_by) REFERENCES Persons(id), + CONSTRAINT Purchases_FK_1 FOREIGN KEY (fulfilled_by) REFERENCES Persons(id) +); +CREATE INDEX Purchases_state_IDX ON Purchases (state); +CREATE INDEX Purchases_purchased_by_IDX ON Purchases (purchased_by); +CREATE INDEX Purchases_purchased_at_IDX ON Purchases (purchased_at); +CREATE INDEX Purchases_fulfilled_by_IDX ON Purchases (fulfilled_by); +CREATE INDEX Purchases_fulfilled_at_IDX ON Purchases (fulfilled_at); +CREATE INDEX Purchases_total_charge_IDX ON Purchases (total_charge); +``` + +# PurchaseLineItems +The PurchaseLineItems table will relate a Purchase to one or more LineItems. + +``` sql +CREATE TABLE PurchaseLineItems ( + purchase_id TEXT(36), + line_item_id TEXT(36), + CONSTRAINT PurchaseLineItems_PK PRIMARY KEY (purchase_id,line_item_id), + CONSTRAINT PurchaseLineItems_FK FOREIGN KEY (purchase_id) REFERENCES Purchases(id), + CONSTRAINT PurchaseLineItems_FK_1 FOREIGN KEY (line_item_id) REFERENCES LineItems(id) ON DELETE CASCADE +); +CREATE INDEX PurchaseLineItems_purchase_id_IDX ON PurchaseLineItems (purchase_id); +CREATE INDEX PurchaseLineItems_line_item_id_IDX ON PurchaseLineItems (line_item_id); +``` + +# PurchaseCouponCodes +The PurchaseCouponCodes table will relate a Purchase to one or more CouponCodes that were successfully applied to the Purchase. + +``` sql +CREATE TABLE PurchaseCouponCodes ( + purchase_id TEXT(36), + coupon_code_id TEXT(36), + CONSTRAINT PurchaseCouponCodes_PK PRIMARY KEY (purchase_id,coupon_code_id), + CONSTRAINT PurchaseCouponCodes_FK FOREIGN KEY (purchase_id) REFERENCES Purchases(id), + CONSTRAINT PurchaseCouponCodes_FK_1 FOREIGN KEY (coupon_code_id) REFERENCES CouponCodes(id) +); +CREATE INDEX PurchaseCouponCodes_purchase_id_IDX ON PurchaseCouponCodes (purchase_id); +CREATE INDEX PurchaseCouponCodes_coupon_code_id_IDX ON PurchaseCouponCodes (coupon_code_id); ``` \ No newline at end of file