-- target-database: cmvr-project-dev -- Additive only. These optional documents do not participate in purchasing state transitions. CREATE TABLE IF NOT EXISTS purchase_document_group ( id bigint NOT NULL AUTO_INCREMENT PRIMARY KEY, target_type varchar(10) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, target_id bigint NOT NULL, document_kind varchar(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, document_no varchar(100) NOT NULL DEFAULT '', version int NOT NULL DEFAULT 0, update_by varchar(64) NOT NULL, update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, UNIQUE KEY uk_purchase_document_target (target_type,target_id,document_kind) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; CREATE TABLE IF NOT EXISTS purchase_document_attachment ( id char(36) CHARACTER SET ascii COLLATE ascii_bin NOT NULL PRIMARY KEY, group_id bigint NOT NULL, original_name varchar(180) NOT NULL, content_type varchar(100) CHARACTER SET ascii 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) NOT NULL, create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, deleted tinyint NOT NULL DEFAULT 0, deleted_by varchar(64) NULL, deleted_time datetime NULL, KEY idx_purchase_document_files (group_id,deleted,create_time), CONSTRAINT fk_purchase_document_group FOREIGN KEY (group_id) REFERENCES purchase_document_group(id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;