шаг 4 завершен

This commit is contained in:
Alisa
2026-06-04 01:30:45 +03:00
parent 62ce8c4d01
commit 238831ad3a
26 changed files with 1703 additions and 70 deletions
+228
View File
@@ -7,11 +7,23 @@ SET FOREIGN_KEY_CHECKS = 0;
DROP TABLE IF EXISTS order_status_history;
DROP TABLE IF EXISTS order_items;
DROP TABLE IF EXISTS orders;
DROP TABLE IF EXISTS price_requests;
DROP TABLE IF EXISTS delivery_calculations;
DROP TABLE IF EXISTS promocode_targets;
DROP TABLE IF EXISTS promocodes;
DROP TABLE IF EXISTS product_search_terms;
DROP TABLE IF EXISTS product_events;
DROP TABLE IF EXISTS product_relations;
DROP TABLE IF EXISTS recommendation_rules;
DROP TABLE IF EXISTS product_badge_links;
DROP TABLE IF EXISTS product_badges;
DROP TABLE IF EXISTS product_segment_links;
DROP TABLE IF EXISTS product_segments;
DROP TABLE IF EXISTS product_images;
DROP TABLE IF EXISTS variant_attribute_values;
DROP TABLE IF EXISTS product_attribute_groups;
DROP TABLE IF EXISTS attribute_values;
DROP TABLE IF EXISTS attribute_groups;
DROP TABLE IF EXISTS product_variants;
DROP TABLE IF EXISTS popular_products;
DROP TABLE IF EXISTS promo_block_items;
@@ -111,12 +123,17 @@ CREATE TABLE product_variants (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
product_id BIGINT UNSIGNED NOT NULL,
name VARCHAR(190) NOT NULL,
code VARCHAR(100) NULL,
article VARCHAR(100) NULL,
unit ENUM('kg', 'g', 'l', 'ml', 'pcs', 'pack') NOT NULL DEFAULT 'kg',
package_quantity DECIMAL(10,3) NOT NULL DEFAULT 1.000,
step_quantity DECIMAL(10,3) NOT NULL DEFAULT 1.000,
price_per_unit DECIMAL(12,2) NULL,
package_price DECIMAL(12,2) NOT NULL,
old_package_price DECIMAL(12,2) NULL,
discount_type ENUM('none', 'manual_old_price', 'percent') NOT NULL DEFAULT 'none',
discount_percent DECIMAL(5,2) NULL,
volume_or_pieces DECIMAL(12,4) NULL,
min_order_quantity DECIMAL(10,3) NOT NULL DEFAULT 1.000,
stock_quantity DECIMAL(12,3) NULL,
is_default TINYINT(1) NOT NULL DEFAULT 0,
@@ -127,12 +144,79 @@ CREATE TABLE product_variants (
updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
KEY idx_variants_product (product_id),
KEY idx_variants_code (code),
KEY idx_variants_article (article),
KEY idx_variants_public (product_id, is_published, is_available, sort_order),
CONSTRAINT fk_variants_product
FOREIGN KEY (product_id) REFERENCES products(id)
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE attribute_groups (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(190) NOT NULL,
slug VARCHAR(190) NOT NULL,
display_type ENUM('select', 'radio', 'swatch') NOT NULL DEFAULT 'select',
is_filterable TINYINT(1) NOT NULL DEFAULT 1,
sort_order INT NOT NULL DEFAULT 100,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY uq_attribute_groups_slug (slug)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE attribute_values (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
group_id BIGINT UNSIGNED NOT NULL,
value VARCHAR(190) NOT NULL,
slug VARCHAR(190) NOT NULL,
sort_order INT NOT NULL DEFAULT 100,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY uq_attribute_value (group_id, slug),
KEY idx_attribute_values_group (group_id, sort_order),
CONSTRAINT fk_attribute_values_group
FOREIGN KEY (group_id) REFERENCES attribute_groups(id)
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE product_attribute_groups (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
product_id BIGINT UNSIGNED NOT NULL,
group_id BIGINT UNSIGNED NOT NULL,
sort_order INT NOT NULL DEFAULT 100,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY uq_product_attribute_group (product_id, group_id),
CONSTRAINT fk_product_attribute_groups_product
FOREIGN KEY (product_id) REFERENCES products(id)
ON DELETE CASCADE,
CONSTRAINT fk_product_attribute_groups_group
FOREIGN KEY (group_id) REFERENCES attribute_groups(id)
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE variant_attribute_values (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
variant_id BIGINT UNSIGNED NOT NULL,
group_id BIGINT UNSIGNED NOT NULL,
value_id BIGINT UNSIGNED NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY uq_variant_attribute (variant_id, group_id),
KEY idx_variant_attribute_value (value_id),
CONSTRAINT fk_variant_attribute_variant
FOREIGN KEY (variant_id) REFERENCES product_variants(id)
ON DELETE CASCADE,
CONSTRAINT fk_variant_attribute_group
FOREIGN KEY (group_id) REFERENCES attribute_groups(id)
ON DELETE CASCADE,
CONSTRAINT fk_variant_attribute_value
FOREIGN KEY (value_id) REFERENCES attribute_values(id)
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE product_images (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
product_id BIGINT UNSIGNED NOT NULL,
@@ -161,6 +245,111 @@ CREATE TABLE product_search_terms (
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE product_segments (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(190) NOT NULL,
slug VARCHAR(190) NOT NULL,
description TEXT NULL,
sort_order INT NOT NULL DEFAULT 100,
is_active TINYINT(1) NOT NULL DEFAULT 1,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY uq_product_segments_slug (slug),
KEY idx_product_segments_active (is_active, sort_order)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE product_segment_links (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
product_id BIGINT UNSIGNED NOT NULL,
segment_id BIGINT UNSIGNED NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY uq_product_segment_link (product_id, segment_id),
KEY idx_segment_links_segment (segment_id),
CONSTRAINT fk_segment_links_product
FOREIGN KEY (product_id) REFERENCES products(id)
ON DELETE CASCADE,
CONSTRAINT fk_segment_links_segment
FOREIGN KEY (segment_id) REFERENCES product_segments(id)
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE product_badges (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(190) NOT NULL,
slug VARCHAR(190) NOT NULL,
color VARCHAR(40) NULL,
sort_order INT NOT NULL DEFAULT 100,
is_active TINYINT(1) NOT NULL DEFAULT 1,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY uq_product_badges_slug (slug),
KEY idx_product_badges_active (is_active, sort_order)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE product_badge_links (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
product_id BIGINT UNSIGNED NOT NULL,
badge_id BIGINT UNSIGNED NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY uq_product_badge_link (product_id, badge_id),
KEY idx_badge_links_badge (badge_id),
CONSTRAINT fk_badge_links_product
FOREIGN KEY (product_id) REFERENCES products(id)
ON DELETE CASCADE,
CONSTRAINT fk_badge_links_badge
FOREIGN KEY (badge_id) REFERENCES product_badges(id)
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE recommendation_rules (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
title VARCHAR(190) NOT NULL,
source_type ENUM('home', 'category', 'product', 'cart', 'segment') NOT NULL DEFAULT 'product',
target_type ENUM('similar', 'bought_together', 'upsell', 'scenario', 'manual') NOT NULL DEFAULT 'similar',
segment_id BIGINT UNSIGNED NULL,
category_id BIGINT UNSIGNED NULL,
max_items TINYINT UNSIGNED NOT NULL DEFAULT 12,
is_active TINYINT(1) NOT NULL DEFAULT 1,
sort_order INT NOT NULL DEFAULT 100,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
KEY idx_recommendation_rules_active (is_active, source_type, target_type, sort_order),
KEY idx_recommendation_rules_segment (segment_id),
KEY idx_recommendation_rules_category (category_id),
CONSTRAINT fk_recommendation_rules_segment
FOREIGN KEY (segment_id) REFERENCES product_segments(id)
ON DELETE SET NULL,
CONSTRAINT fk_recommendation_rules_category
FOREIGN KEY (category_id) REFERENCES categories(id)
ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE product_relations (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
source_product_id BIGINT UNSIGNED NOT NULL,
target_product_id BIGINT UNSIGNED NOT NULL,
relation_type ENUM('bought_together', 'similar', 'upsell', 'scenario', 'manual') NOT NULL DEFAULT 'manual',
weight SMALLINT UNSIGNED NOT NULL DEFAULT 100,
is_active TINYINT(1) NOT NULL DEFAULT 1,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY uq_product_relation (source_product_id, target_product_id, relation_type),
KEY idx_product_relations_source (source_product_id, relation_type, is_active, weight),
KEY idx_product_relations_target (target_product_id),
CONSTRAINT fk_product_relations_source
FOREIGN KEY (source_product_id) REFERENCES products(id)
ON DELETE CASCADE,
CONSTRAINT fk_product_relations_target
FOREIGN KEY (target_product_id) REFERENCES products(id)
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE promocodes (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
code VARCHAR(80) NOT NULL,
@@ -218,6 +407,26 @@ CREATE TABLE delivery_calculations (
KEY idx_delivery_type_created (delivery_type, created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE price_requests (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
customer_name VARCHAR(120) NULL,
phone VARCHAR(40) NULL,
email VARCHAR(190) NULL,
company_name VARCHAR(190) NULL,
request_text MEDIUMTEXT NULL,
file_path VARCHAR(255) NULL,
status ENUM('new', 'in_progress', 'answered', 'archived') NOT NULL DEFAULT 'new',
admin_comment TEXT NULL,
client_ip VARCHAR(45) NULL,
user_agent VARCHAR(255) NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
KEY idx_price_requests_status (status, created_at),
KEY idx_price_requests_email (email),
KEY idx_price_requests_phone (phone)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE orders (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
order_number VARCHAR(40) NOT NULL,
@@ -254,6 +463,25 @@ CREATE TABLE orders (
ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE product_events (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
event_type ENUM('view', 'add_to_cart', 'order', 'compare', 'recommendation_click') NOT NULL,
product_id BIGINT UNSIGNED NOT NULL,
session_id VARCHAR(120) NULL,
order_id BIGINT UNSIGNED NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
KEY idx_product_events_product (product_id, event_type, created_at),
KEY idx_product_events_session (session_id, created_at),
KEY idx_product_events_order (order_id),
CONSTRAINT fk_product_events_product
FOREIGN KEY (product_id) REFERENCES products(id)
ON DELETE CASCADE,
CONSTRAINT fk_product_events_order
FOREIGN KEY (order_id) REFERENCES orders(id)
ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE order_items (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
order_id BIGINT UNSIGNED NOT NULL,