-- Suffix management (后缀管理): directory tree, province groups, suffixes, -- per-directory custom columns (with value flag), cell values, anchors, template files. CREATE TABLE suffix_dirs ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, parent_id BIGINT UNSIGNED NULL, name VARCHAR(190) NOT NULL, sort_order INT NOT NULL DEFAULT 0, created_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), CONSTRAINT fk_suffix_dirs_parent FOREIGN KEY(parent_id) REFERENCES suffix_dirs(id) ON DELETE CASCADE ) ENGINE=InnoDB; INSERT INTO suffix_dirs(parent_id,name,sort_order) VALUES(NULL,'按信息价的目录',0); CREATE TABLE suffix_groups ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(190) NOT NULL UNIQUE, sort_order INT NOT NULL DEFAULT 0, created_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ) ENGINE=InnoDB; CREATE TABLE suffixes ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, group_id BIGINT UNSIGNED NOT NULL, name VARCHAR(64) NOT NULL DEFAULT '', sort_order INT NOT NULL DEFAULT 0, created_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), CONSTRAINT fk_suffixes_group FOREIGN KEY(group_id) REFERENCES suffix_groups(id) ON DELETE CASCADE ) ENGINE=InnoDB; CREATE TABLE suffix_columns ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, dir_id BIGINT UNSIGNED NOT NULL, name VARCHAR(190) NOT NULL, is_value BOOLEAN NOT NULL DEFAULT FALSE, sort_order INT NOT NULL DEFAULT 0, width INT NOT NULL DEFAULT 0, created_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), CONSTRAINT fk_suffix_columns_dir FOREIGN KEY(dir_id) REFERENCES suffix_dirs(id) ON DELETE CASCADE ) ENGINE=InnoDB; CREATE TABLE suffix_cells ( dir_id BIGINT UNSIGNED NOT NULL, suffix_id BIGINT UNSIGNED NOT NULL, column_id BIGINT UNSIGNED NOT NULL, value TEXT NOT NULL, updated_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY(dir_id,suffix_id,column_id), CONSTRAINT fk_suffix_cells_dir FOREIGN KEY(dir_id) REFERENCES suffix_dirs(id) ON DELETE CASCADE, CONSTRAINT fk_suffix_cells_suffix FOREIGN KEY(suffix_id) REFERENCES suffixes(id) ON DELETE CASCADE, CONSTRAINT fk_suffix_cells_column FOREIGN KEY(column_id) REFERENCES suffix_columns(id) ON DELETE CASCADE ) ENGINE=InnoDB; CREATE TABLE suffix_dir_anchors ( dir_id BIGINT UNSIGNED NOT NULL, suffix_id BIGINT UNSIGNED NOT NULL, PRIMARY KEY(dir_id,suffix_id), CONSTRAINT fk_suffix_anchors_dir FOREIGN KEY(dir_id) REFERENCES suffix_dirs(id) ON DELETE CASCADE, CONSTRAINT fk_suffix_anchors_suffix FOREIGN KEY(suffix_id) REFERENCES suffixes(id) ON DELETE CASCADE ) ENGINE=InnoDB; CREATE TABLE suffix_files ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, suffix_id BIGINT UNSIGNED NOT NULL, file_name VARCHAR(255) NOT NULL, file_size BIGINT UNSIGNED NOT NULL, sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, rel_path VARCHAR(500) NOT NULL, created_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), CONSTRAINT fk_suffix_files_suffix FOREIGN KEY(suffix_id) REFERENCES suffixes(id) ON DELETE CASCADE ) ENGINE=InnoDB;