Split off config schema, update settings page

This commit is contained in:
2025-01-12 15:00:54 -05:00
parent 271a40f2c5
commit b815062525
5 changed files with 935 additions and 986 deletions

View File

@@ -88,30 +88,6 @@ CREATE TABLE IF NOT EXISTS vendor_metrics (
PRIMARY KEY (vendor)
);
-- New table for stock threshold configurations
CREATE TABLE IF NOT EXISTS stock_thresholds (
id INT NOT NULL, -- Changed from AUTO_INCREMENT to explicitly set ID
category_id BIGINT, -- NULL means default/global threshold
vendor VARCHAR(100), -- NULL means applies to all vendors
critical_days INT NOT NULL DEFAULT 7,
reorder_days INT NOT NULL DEFAULT 14,
overstock_days INT NOT NULL DEFAULT 90,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE CASCADE,
UNIQUE KEY unique_category_vendor (category_id, vendor),
INDEX idx_thresholds_category_vendor (category_id, vendor)
);
-- Insert default thresholds with ID=1
INSERT INTO stock_thresholds (id, category_id, vendor, critical_days, reorder_days, overstock_days)
VALUES (1, NULL, NULL, 7, 14, 90)
ON DUPLICATE KEY UPDATE
critical_days = VALUES(critical_days),
reorder_days = VALUES(reorder_days),
overstock_days = VALUES(overstock_days);
-- Re-enable foreign key checks
SET FOREIGN_KEY_CHECKS = 1;