Improve and debug calculate metrics script

This commit is contained in:
2025-01-12 14:52:46 -05:00
parent ac8563325a
commit 271a40f2c5
4 changed files with 350 additions and 101 deletions

View File

@@ -50,7 +50,8 @@ CREATE TABLE product_categories (
FOREIGN KEY (product_id) REFERENCES products(product_id) ON DELETE CASCADE,
FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE CASCADE,
INDEX idx_category (category_id),
INDEX idx_product (product_id)
INDEX idx_product (product_id),
INDEX idx_product_categories_both (product_id, category_id)
) ENGINE=InnoDB;
-- Create orders table with its indexes
@@ -80,6 +81,7 @@ CREATE TABLE orders (
INDEX idx_date (date),
INDEX idx_status (status),
INDEX idx_orders_metrics (product_id, date, canceled, quantity, price),
INDEX idx_orders_product_date (product_id, date),
UNIQUE KEY unique_order_product (order_number, product_id)
) ENGINE=InnoDB;
@@ -104,6 +106,8 @@ CREATE TABLE purchase_orders (
INDEX idx_vendor (vendor),
INDEX idx_status (status),
INDEX idx_purchase_orders_metrics (product_id, date, status, ordered, received),
INDEX idx_po_product_date (product_id, date),
INDEX idx_po_product_status (product_id, status),
UNIQUE KEY unique_po_product (po_id, product_id)
) ENGINE=InnoDB;