Product import fixes, more category import fixes
This commit is contained in:
@@ -4,13 +4,15 @@ SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- Create tables
|
||||
CREATE TABLE products (
|
||||
product_id BIGINT NOT NULL,
|
||||
pid BIGINT NOT NULL,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
description TEXT,
|
||||
SKU VARCHAR(50) NOT NULL,
|
||||
created_at TIMESTAMP NULL,
|
||||
first_received TIMESTAMP NULL,
|
||||
stock_quantity INT DEFAULT 0,
|
||||
preorder_count INT DEFAULT 0,
|
||||
notions_inv_count INT DEFAULT 0,
|
||||
price DECIMAL(10, 3) NOT NULL,
|
||||
regular_price DECIMAL(10, 3) NOT NULL,
|
||||
cost_price DECIMAL(10, 3),
|
||||
@@ -49,7 +51,7 @@ CREATE TABLE products (
|
||||
baskets INT UNSIGNED DEFAULT 0,
|
||||
notifies INT UNSIGNED DEFAULT 0,
|
||||
date_last_sold DATE,
|
||||
PRIMARY KEY (product_id),
|
||||
PRIMARY KEY (pid),
|
||||
UNIQUE KEY unique_sku (SKU),
|
||||
INDEX idx_vendor (vendor),
|
||||
INDEX idx_brand (brand),
|
||||
@@ -60,7 +62,7 @@ CREATE TABLE products (
|
||||
|
||||
-- Create categories table with hierarchy support
|
||||
CREATE TABLE categories (
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
cat_id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(100) NOT NULL,
|
||||
type SMALLINT NOT NULL COMMENT '10=section, 11=category, 12=subcategory, 13=subsubcategory, 1=company, 2=line, 3=subline, 40=artist',
|
||||
parent_id BIGINT,
|
||||
@@ -68,8 +70,7 @@ CREATE TABLE categories (
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
status VARCHAR(20) DEFAULT 'active',
|
||||
UNIQUE KEY unique_category (id),
|
||||
FOREIGN KEY (parent_id) REFERENCES categories(id),
|
||||
FOREIGN KEY (parent_id) REFERENCES categories(cat_id),
|
||||
INDEX idx_parent (parent_id),
|
||||
INDEX idx_type (type),
|
||||
INDEX idx_status (status),
|
||||
@@ -90,20 +91,20 @@ CREATE TABLE vendor_details (
|
||||
|
||||
-- Create product_categories junction table
|
||||
CREATE TABLE 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)
|
||||
cat_id BIGINT NOT NULL,
|
||||
pid BIGINT NOT NULL,
|
||||
PRIMARY KEY (pid, cat_id),
|
||||
FOREIGN KEY (pid) REFERENCES products(pid) ON DELETE CASCADE,
|
||||
FOREIGN KEY (cat_id) REFERENCES categories(cat_id) ON DELETE CASCADE,
|
||||
INDEX idx_category (cat_id),
|
||||
INDEX idx_product (pid)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
-- Create orders table with its indexes
|
||||
CREATE TABLE orders (
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
order_number VARCHAR(50) NOT NULL,
|
||||
product_id BIGINT NOT NULL,
|
||||
pid BIGINT NOT NULL,
|
||||
SKU VARCHAR(50) NOT NULL,
|
||||
date DATE NOT NULL,
|
||||
price DECIMAL(10, 3) NOT NULL,
|
||||
@@ -120,15 +121,15 @@ CREATE TABLE orders (
|
||||
shipping_address TEXT,
|
||||
billing_address TEXT,
|
||||
canceled BOOLEAN DEFAULT false,
|
||||
FOREIGN KEY (product_id) REFERENCES products(product_id),
|
||||
FOREIGN KEY (pid) REFERENCES products(pid),
|
||||
FOREIGN KEY (SKU) REFERENCES products(SKU),
|
||||
INDEX idx_order_number (order_number),
|
||||
INDEX idx_customer (customer),
|
||||
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)
|
||||
INDEX idx_orders_metrics (pid, date, canceled, quantity, price),
|
||||
INDEX idx_orders_product_date (pid, date),
|
||||
UNIQUE KEY unique_order_product (order_number, pid)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
-- Create purchase_orders table with its indexes
|
||||
@@ -138,7 +139,7 @@ CREATE TABLE purchase_orders (
|
||||
vendor VARCHAR(100) NOT NULL,
|
||||
date DATE NOT NULL,
|
||||
expected_date DATE,
|
||||
product_id BIGINT NOT NULL,
|
||||
pid BIGINT NOT NULL,
|
||||
sku VARCHAR(50) NOT NULL,
|
||||
cost_price DECIMAL(10, 3) NOT NULL,
|
||||
status VARCHAR(20) DEFAULT 'pending' COMMENT 'canceled,created,electronically_ready_send,ordered,preordered,electronically_sent,receiving_started,closed',
|
||||
@@ -147,15 +148,15 @@ CREATE TABLE purchase_orders (
|
||||
received INT DEFAULT 0,
|
||||
received_date DATE,
|
||||
received_by INT,
|
||||
FOREIGN KEY (product_id) REFERENCES products(product_id),
|
||||
FOREIGN KEY (pid) REFERENCES products(pid),
|
||||
FOREIGN KEY (sku) REFERENCES products(SKU),
|
||||
INDEX idx_po_id (po_id),
|
||||
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)
|
||||
INDEX idx_purchase_orders_metrics (pid, date, status, ordered, received),
|
||||
INDEX idx_po_product_date (pid, date),
|
||||
INDEX idx_po_product_status (pid, status),
|
||||
UNIQUE KEY unique_po_product (po_id, pid)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
|
||||
Reference in New Issue
Block a user