cmvr-wms/sql/projectdev/20261019_product_editions.sql

51 lines
2.5 KiB
MySQL
Raw Permalink Normal View History

-- target-database: cmvr-project-dev
-- Additive only. Existing products, item IDs, BOMs, stock and costs are not rewritten.
CREATE TABLE IF NOT EXISTS production_product_series (
id bigint NOT NULL AUTO_INCREMENT PRIMARY KEY,
series_name varchar(160) NOT NULL,
version int NOT NULL DEFAULT 0,
create_by varchar(64) DEFAULT NULL,
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
update_by varchar(64) DEFAULT NULL,
update_time datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS production_product_edition (
product_id bigint NOT NULL PRIMARY KEY,
series_id bigint NOT NULL,
edition_tag varchar(64) NOT NULL,
source_product_id bigint DEFAULT NULL,
source_bom_id bigint DEFAULT NULL,
create_by varchar(64) DEFAULT NULL,
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
update_by varchar(64) DEFAULT NULL,
update_time datetime DEFAULT NULL,
UNIQUE KEY uk_product_edition_tag(series_id,edition_tag),
CONSTRAINT fk_product_edition_product FOREIGN KEY(product_id) REFERENCES production_product(id),
CONSTRAINT fk_product_edition_series FOREIGN KEY(series_id) REFERENCES production_product_series(id),
CONSTRAINT fk_product_edition_source FOREIGN KEY(source_product_id) REFERENCES production_product(id),
CONSTRAINT fk_product_edition_bom FOREIGN KEY(source_bom_id) REFERENCES bom_version(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS production_product_version_request (
request_key varchar(80) CHARACTER SET ascii COLLATE ascii_bin NOT NULL PRIMARY KEY,
owner_id bigint NOT NULL,
request_hash char(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
response_json longtext NOT NULL,
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS production_product_attachment (
id char(36) CHARACTER SET ascii COLLATE ascii_bin NOT NULL PRIMARY KEY,
product_id bigint NOT NULL,
original_name varchar(180) NOT NULL,
content_type varchar(100) NOT NULL,
byte_size int NOT NULL,
sha256 char(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
owner_id bigint NOT NULL,
create_by varchar(64) DEFAULT NULL,
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
deleted tinyint NOT NULL DEFAULT 0,
deleted_by varchar(64) DEFAULT NULL,
deleted_time datetime DEFAULT NULL,
KEY idx_product_attachment(product_id,deleted,create_time),
CONSTRAINT fk_product_attachment_product FOREIGN KEY(product_id) REFERENCES production_product(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;