From c5ebcc8204093759348040519196c080d30a6f5c Mon Sep 17 00:00:00 2001 From: Sundog Date: Wed, 25 Oct 2023 12:41:54 -0400 Subject: [PATCH] adds more store-focused data structures --- MODELS.md | 8 ++--- SCHEMA.md | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 4 deletions(-) diff --git a/MODELS.md b/MODELS.md index fc388ac..45d3957 100644 --- a/MODELS.md +++ b/MODELS.md @@ -445,12 +445,12 @@ struct Sku { item: PurchaseItemType, variant: Option, description: Option, - price: Option, + price: rusty_money::Money, requires_shipping: bool, shipping_charge: Option, } -struct PurchaseItem { - id: PurchaseItemId, +struct LineItem { + id: LineItemId, sku: SkuId, quantity: usize, } @@ -465,7 +465,7 @@ enum PurchaseState { } struct Purchase { id: String, - items: Vec, + items: Vec, state: PurchaseState, purchased_by: Person, purchased_at: Option, diff --git a/SCHEMA.md b/SCHEMA.md index 3624716..96c4ac8 100644 --- a/SCHEMA.md +++ b/SCHEMA.md @@ -817,3 +817,96 @@ CREATE TABLE CollectionOtherProducts ( CREATE INDEX CollectionOtherProducts_collection_id_IDX ON CollectionOtherProducts (collection_id); CREATE INDEX CollectionOtherProducts_other_product_id_IDX ON CollectionOtherProducts (other_product_id); ``` + +# Skus +The Skus table will contain SKUs () representing items available for Purchase through the server. + +``` sql +CREATE TABLE Skus ( + id TEXT(36), + item_type TEXT, + item_id TEXT(36), + variant TEXT, + description TEXT, + price NUMERIC DEFAULT (0.00), + requires_shipping INTEGER DEFAULT (0), + shipping_charge NUMERIC DEFAULT (0.00), + CONSTRAINT Skus_PK PRIMARY KEY (id) +); +CREATE INDEX Skus_item_type_IDX ON Skus (item_type); +CREATE INDEX Skus_item_id_IDX ON Skus (item_id); +CREATE INDEX Skus_variant_IDX ON Skus (variant); +CREATE INDEX Skus_description_IDX ON Skus (description); +CREATE INDEX Skus_price_IDX ON Skus (price); +CREATE INDEX Skus_requires_shipping_IDX ON Skus (requires_shipping); +CREATE INDEX Skus_shipping_charge_IDX ON Skus (shipping_charge); +``` + +# LineItems +The LineItems table will contain individual SKUs and their associated quantites as part of a Purchase. + +``` sql +CREATE TABLE LineItems ( + id TEXT(36), + sku_id TEXT(36), + quantity INTEGER DEFAULT (1), + CONSTRAINT LineItems_PK PRIMARY KEY (id), + CONSTRAINT LineItems_FK FOREIGN KEY (sku_id) REFERENCES Skus(id) +); +CREATE INDEX LineItems_sku_id_IDX ON LineItems (sku_id); +CREATE INDEX LineItems_quantity_IDX ON LineItems (quantity); +``` + +# CouponCodes +The CouponCodes table will contain coupon codes that can be redeemed for a discount, either by amount or percentage, on a Purchase. + +``` sql +CREATE TABLE CouponCodes ( + id TEXT(36), + name TEXT, + code TEXT, + uses INTEGER DEFAULT (0), + max_uses INTEGER DEFAULT (0), + expiration INTEGER, + discount_flat NUMERIC DEFAULT (0.00), + discount_percentage NUMERIC DEFAULT (0.00), + is_sku_specific INTEGER DEFAULT (0), + is_active INTEGER DEFAULT (0), + created_by TEXT(36), + created_at INTEGER, + modified_by TEXT(36), + modified_at INTEGER, + deleted_by TEXT(36), + deleted_at INTEGER, + CONSTRAINT CouponCodes_PK PRIMARY KEY (id), + CONSTRAINT CouponCodes_FK FOREIGN KEY (created_by) REFERENCES Persons(id), + CONSTRAINT CouponCodes_FK_1 FOREIGN KEY (modified_by) REFERENCES Persons(id), + CONSTRAINT CouponCodes_FK_2 FOREIGN KEY (deleted_by) REFERENCES Persons(id) +); +CREATE INDEX CouponCodes_name_IDX ON CouponCodes (name); +CREATE UNIQUE INDEX CouponCodes_code_IDX ON CouponCodes (code); +CREATE INDEX CouponCodes_uses_IDX ON CouponCodes (uses); +CREATE INDEX CouponCodes_max_uses_IDX ON CouponCodes (max_uses); +CREATE INDEX CouponCodes_expiration_IDX ON CouponCodes (expiration); +CREATE INDEX CouponCodes_is_sku_specific_IDX ON CouponCodes (is_sku_specific); +CREATE INDEX CouponCodes_is_active_IDX ON CouponCodes (is_active); +CREATE INDEX CouponCodes_created_by_IDX ON CouponCodes (created_by); +CREATE INDEX CouponCodes_created_at_IDX ON CouponCodes (created_at); +CREATE INDEX CouponCodes_modified_by_IDX ON CouponCodes (modified_by); +CREATE INDEX CouponCodes_modified_at_IDX ON CouponCodes (modified_at); +CREATE INDEX CouponCodes_deleted_by_IDX ON CouponCodes (deleted_by); +CREATE INDEX CouponCodes_deleted_at_IDX ON CouponCodes (deleted_at); +``` + +# CouponCodeSkus +The CouponCodeSkus table will relate a CouponCode to one or more Skus the CouponCode can be applied to, if CouponCode.is_sku_specific is true. (If CouponCode.is_sku_specific is false the CouponCode can be applied to an entire Purchase regardless of the Skus being purchased.) + +``` sql +CREATE TABLE CouponCodeSkus ( + coupon_code_id TEXT(36), + sku_id TEXT(36), + CONSTRAINT CouponCodeSkus_PK PRIMARY KEY (coupon_code_id,sku_id), + CONSTRAINT CouponCodeSkus_FK FOREIGN KEY (coupon_code_id) REFERENCES CouponCodes(id), + CONSTRAINT CouponCodeSkus_FK_1 FOREIGN KEY (sku_id) REFERENCES Skus(id) +); +``` \ No newline at end of file