Files
yhy-mager/backend/migrations/000017_suffix_management.up.sql
lianjianwei2024 ac4b4a1c06 feat: suffix naming rules, extension consistency, column widths, compact layout
- suffix rows are named by the suffix at creation (prompt); names are
  immutable afterwards; duplicates auto-suffix -1/-2 (global)
- new-group dialog takes group name + first suffix name; backend creates
  group and its first workspace row in one transaction
- upload validation: file extension must match the row's suffix
  (whole-row consistency), enforced client- and server-side
- column sort dialog gains per-column width inputs (persisted via
  PATCH /columns/:id, table renders fixed widths, 0 = auto)
- compact layout: denser tables/bars, viewport-height shell with
  independent scrollbars, cleanup step in e2e flow
2026-10-30 16:17:17 +08:00

70 lines
3.1 KiB
SQL

-- 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;