updates models and schema doc, adds final purchase related tables

This commit is contained in:
Sundog 2023-11-01 09:34:33 -04:00
parent c5ebcc8204
commit 41a30d1855
2 changed files with 55 additions and 1 deletions

View File

@ -467,7 +467,7 @@ struct Purchase {
id: String, id: String,
items: Vec<LineItem>, items: Vec<LineItem>,
state: PurchaseState, state: PurchaseState,
purchased_by: Person, purchased_by: Option<Person>,
purchased_at: Option<chrono::DateTime>, purchased_at: Option<chrono::DateTime>,
fulfilled_by: Option<Person>, fulfilled_by: Option<Person>,
fulfilled_at: Option<chrono::DateTime>, fulfilled_at: Option<chrono::DateTime>,

View File

@ -910,3 +910,57 @@ CREATE TABLE CouponCodeSkus (
CONSTRAINT CouponCodeSkus_FK_1 FOREIGN KEY (sku_id) REFERENCES Skus(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);
```