adds more store-focused data structures

This commit is contained in:
Sundog 2023-10-25 12:41:54 -04:00
parent 4bba521103
commit c5ebcc8204
2 changed files with 97 additions and 4 deletions

View File

@ -445,12 +445,12 @@ struct Sku {
item: PurchaseItemType,
variant: Option<String>,
description: Option<String>,
price: Option<rusty_money::Money>,
price: rusty_money::Money,
requires_shipping: bool,
shipping_charge: Option<rusty_money::Money>,
}
struct PurchaseItem {
id: PurchaseItemId,
struct LineItem {
id: LineItemId,
sku: SkuId,
quantity: usize,
}
@ -465,7 +465,7 @@ enum PurchaseState {
}
struct Purchase {
id: String,
items: Vec<PurchaseItem>,
items: Vec<LineItem>,
state: PurchaseState,
purchased_by: Person,
purchased_at: Option<chrono::DateTime>,

View File

@ -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)
);
```