Add categories table and update/optimize import script
This commit is contained in:
@@ -78,4 +78,23 @@ CREATE TABLE IF NOT EXISTS purchase_orders (
|
||||
INDEX idx_vendor (vendor),
|
||||
INDEX idx_status (status),
|
||||
UNIQUE KEY unique_po_product (po_id, product_id)
|
||||
);
|
||||
|
||||
-- Create categories table
|
||||
CREATE TABLE IF NOT EXISTS categories (
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(100) NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE KEY unique_name (name)
|
||||
);
|
||||
|
||||
-- Create product_categories junction table
|
||||
CREATE TABLE IF NOT EXISTS product_categories (
|
||||
product_id BIGINT NOT NULL,
|
||||
category_id BIGINT NOT NULL,
|
||||
PRIMARY KEY (product_id, category_id),
|
||||
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)
|
||||
);
|
||||
Reference in New Issue
Block a user