Skip to content

Commit 447a530

Browse files
committed
feat(schema): 添加表和字段注释支持
- 为所有数据库迁移文件添加表和字段注释 - 支持 SQLite、MySQL 和 PostgreSQL 数据库 - 更新 README 文档中的表结构说明 - 为 groups、tags、files 等表添加详细字段注释 - 增加 description 字段并添加相应注释 - 优化组关系表和文件组关联表的注释信息
1 parent b2428f0 commit 447a530

File tree

16 files changed

+226
-136
lines changed
  • docs
  • migrations_mysql
    • 2024-10-01-193345_FileClassification
    • 2025-10-20-000000_update_group_hierarchy
    • 2025-11-02-000000_add_description_fields
  • migrations_postgres
    • 2024-10-01-193345_FileClassification
    • 2025-10-20-000000_update_group_hierarchy
    • 2025-11-02-000000_add_description_fields
  • migrations_sqlite
    • 2024-10-01-193345_FileClassification
    • 2025-10-20-000000_update_group_hierarchy
    • 2025-11-02-000000_add_description_fields
  • migrations
    • 2024-10-01-193345_FileClassification
    • 2025-10-20-000000_update_group_hierarchy
    • 2025-11-02-000000_add_description_fields

16 files changed

+226
-136
lines changed

.file_classification_env

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# File Classification 系统配置文件
22
# 数据库配置
3+
#DATABASE_URL=mysql://root:mypassword@localhost:3306/file_classification
4+
#DATABASE_TYPE=mysql
5+
36
DATABASE_URL=file_classification.db
47
DATABASE_TYPE=sqlite
58

9+
#DATABASE_URL=mysql://root:@localhost:3306/file_classification
10+
#DATABASE_TYPE=mysql
11+
612
# Web API 配置
713
BIND_ADDRESS=127.0.0.1
814
BIND_PORT=8082

docs/README.md

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,54 +45,62 @@ The system uses the following 6 core tables to store data:
4545
### Table Structure Details
4646

4747
```sql
48+
-- Files table
4849
CREATE TABLE IF NOT EXISTS files (
49-
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
50-
type TEXT NOT NULL, -- File type
51-
path TEXT NOT NULL, -- File storage location
52-
reference_count INTEGER NOT NULL DEFAULT 0, -- Reference count
53-
group_id INTEGER NOT NULL, -- Default file group ID
50+
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, -- File ID
51+
type TEXT NOT NULL, -- File type
52+
path TEXT NOT NULL, -- File storage location
53+
reference_count INTEGER NOT NULL DEFAULT 0, -- Reference count
54+
group_id INTEGER NOT NULL, -- Default file group ID
5455
FOREIGN KEY (group_id) REFERENCES groups(id)
5556
);
5657

58+
-- Groups table
5759
CREATE TABLE IF NOT EXISTS groups (
58-
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
59-
name TEXT NOT NULL UNIQUE, -- Group name
60-
reference_count INTEGER NOT NULL DEFAULT 0, -- Reference count
61-
is_primary BOOLEAN NOT NULL DEFAULT false, -- Whether it's a primary group, false for no, true for yes
62-
click_count INTEGER NOT NULL DEFAULT 0, -- Click count
63-
share_count INTEGER NOT NULL DEFAULT 0, -- Share count
64-
create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Creation time
65-
modify_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Modification time
66-
parent_id INTEGER REFERENCES groups(id) -- Parent group ID for hierarchical structure
60+
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, -- Group ID
61+
name TEXT NOT NULL UNIQUE, -- Group name
62+
reference_count INTEGER NOT NULL DEFAULT 0, -- Reference count
63+
is_primary BOOLEAN NOT NULL DEFAULT false, -- Whether it's a primary group
64+
click_count INTEGER NOT NULL DEFAULT 0, -- Click count
65+
share_count INTEGER NOT NULL DEFAULT 0, -- Share count
66+
create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Creation time
67+
modify_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Modification time
68+
parent_id INTEGER REFERENCES groups(id), -- Parent group ID for hierarchical structure
69+
description TEXT -- Group description
6770
);
6871

72+
-- File-Group associations table
6973
CREATE TABLE IF NOT EXISTS file_groups (
70-
file_id INTEGER NOT NULL,
71-
group_id INTEGER NOT NULL,
72-
relation_type INTEGER NOT NULL DEFAULT 1, -- Relationship type: 1 for primary group relationship
74+
file_id INTEGER NOT NULL, -- File ID
75+
group_id INTEGER NOT NULL, -- Group ID
76+
relation_type INTEGER NOT NULL DEFAULT 1, -- Relationship type: 1 for primary group relationship
7377
PRIMARY KEY (file_id, group_id),
7478
FOREIGN KEY (file_id) REFERENCES files(id),
7579
FOREIGN KEY (group_id) REFERENCES groups(id)
7680
);
7781

82+
-- Tags table
7883
CREATE TABLE IF NOT EXISTS tags (
79-
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
80-
reference_count INTEGER NOT NULL DEFAULT 0, -- Reference count
81-
name TEXT NOT NULL UNIQUE -- Tag name, unique
84+
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, -- Tag ID
85+
reference_count INTEGER NOT NULL DEFAULT 0, -- Reference count
86+
name TEXT NOT NULL UNIQUE, -- Tag name, unique
87+
description TEXT -- Tag description
8288
);
8389

90+
-- Group-Tag associations table
8491
CREATE TABLE IF NOT EXISTS group_tags (
85-
group_id INTEGER NOT NULL,
86-
tag_id INTEGER NOT NULL,
92+
group_id INTEGER NOT NULL, -- Group ID
93+
tag_id INTEGER NOT NULL, -- Tag ID
8794
PRIMARY KEY (group_id, tag_id),
8895
FOREIGN KEY (group_id) REFERENCES groups(id),
8996
FOREIGN KEY (tag_id) REFERENCES tags(id)
9097
);
9198

99+
-- Group relations table
92100
CREATE TABLE IF NOT EXISTS group_relations (
93-
first_group_id INTEGER NOT NULL,
94-
second_group_id INTEGER NOT NULL,
95-
relation_type INTEGER NOT NULL DEFAULT 1, -- Relationship type: 1 for parent-child relationship
101+
first_group_id INTEGER NOT NULL, -- First group ID
102+
second_group_id INTEGER NOT NULL, -- Second group ID
103+
relation_type INTEGER NOT NULL DEFAULT 1, -- Relationship type: 1 for parent-child relationship
96104
PRIMARY KEY (first_group_id, second_group_id, relation_type),
97105
FOREIGN KEY (first_group_id) REFERENCES groups(id),
98106
FOREIGN KEY (second_group_id) REFERENCES groups(id)

docs/README_cn.md

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,54 +45,62 @@ FileClassificationSolutions 是一个基于 Rust 语言开发的创新文件分
4545
### 表结构详情
4646

4747
```sql
48+
-- 文件表
4849
CREATE TABLE IF NOT EXISTS files (
49-
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
50-
type TEXT NOT NULL, -- 文件类型
51-
path TEXT NOT NULL, -- 文件存储位置
52-
reference_count INTEGER NOT NULL DEFAULT 0, -- 引用计数
53-
group_id INTEGER NOT NULL, -- 默认的文件组ID
50+
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, -- 文件ID
51+
type TEXT NOT NULL, -- 文件类型
52+
path TEXT NOT NULL, -- 文件存储位置
53+
reference_count INTEGER NOT NULL DEFAULT 0, -- 引用计数
54+
group_id INTEGER NOT NULL, -- 默认的文件组ID
5455
FOREIGN KEY (group_id) REFERENCES groups(id)
5556
);
5657

58+
-- 组表
5759
CREATE TABLE IF NOT EXISTS groups (
58-
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
59-
name TEXT NOT NULL UNIQUE, -- 文件组名
60-
reference_count INTEGER NOT NULL DEFAULT 0, -- 引用计数
61-
is_primary BOOLEAN NOT NULL DEFAULT false, -- 是否为主文件组,false表示否,true表示是 主文件组代表文件元数据
62-
click_count INTEGER NOT NULL DEFAULT 0, -- 点击次数
63-
share_count INTEGER NOT NULL DEFAULT 0, -- 分享次数
64-
create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间
65-
modify_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 修改时间
66-
parent_id INTEGER REFERENCES groups(id) -- 父组ID,用于层级结构
60+
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, -- 组ID
61+
name TEXT NOT NULL UNIQUE, -- 文件组名
62+
reference_count INTEGER NOT NULL DEFAULT 0, -- 引用计数
63+
is_primary BOOLEAN NOT NULL DEFAULT false, -- 是否为主文件组
64+
click_count INTEGER NOT NULL DEFAULT 0, -- 点击次数
65+
share_count INTEGER NOT NULL DEFAULT 0, -- 分享次数
66+
create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间
67+
modify_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 修改时间
68+
parent_id INTEGER REFERENCES groups(id), -- 父组ID,用于层级结构
69+
description TEXT -- 组描述
6770
);
6871

72+
-- 文件组关联表
6973
CREATE TABLE IF NOT EXISTS file_groups (
70-
file_id INTEGER NOT NULL,
71-
group_id INTEGER NOT NULL,
72-
relation_type INTEGER NOT NULL DEFAULT 1, -- 关系类型:1表示主组关系
74+
file_id INTEGER NOT NULL, -- 文件ID
75+
group_id INTEGER NOT NULL, -- 组ID
76+
relation_type INTEGER NOT NULL DEFAULT 1, -- 关系类型:1表示主组关系
7377
PRIMARY KEY (file_id, group_id),
7478
FOREIGN KEY (file_id) REFERENCES files(id),
7579
FOREIGN KEY (group_id) REFERENCES groups(id)
7680
);
7781

82+
-- 标签表
7883
CREATE TABLE IF NOT EXISTS tags (
79-
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
80-
reference_count INTEGER NOT NULL DEFAULT 0, -- 引用计数
81-
name TEXT NOT NULL UNIQUE -- 标签名称,唯一
84+
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, -- 标签ID
85+
reference_count INTEGER NOT NULL DEFAULT 0, -- 引用计数
86+
name TEXT NOT NULL UNIQUE, -- 标签名称,唯一
87+
description TEXT -- 标签描述
8288
);
8389

90+
-- 组标签关联表
8491
CREATE TABLE IF NOT EXISTS group_tags (
85-
group_id INTEGER NOT NULL,
86-
tag_id INTEGER NOT NULL,
92+
group_id INTEGER NOT NULL, -- 组ID
93+
tag_id INTEGER NOT NULL, -- 标签ID
8794
PRIMARY KEY (group_id, tag_id),
8895
FOREIGN KEY (group_id) REFERENCES groups(id),
8996
FOREIGN KEY (tag_id) REFERENCES tags(id)
9097
);
9198

99+
-- 组关系表
92100
CREATE TABLE IF NOT EXISTS group_relations (
93-
first_group_id INTEGER NOT NULL,
94-
second_group_id INTEGER NOT NULL,
95-
relation_type INTEGER NOT NULL DEFAULT 1, -- 关系类型:1表示父子关系
101+
first_group_id INTEGER NOT NULL, -- 第一个组ID
102+
second_group_id INTEGER NOT NULL, -- 第二个组ID
103+
relation_type INTEGER NOT NULL DEFAULT 1, -- 关系类型:1表示父子关系
96104
PRIMARY KEY (first_group_id, second_group_id, relation_type),
97105
FOREIGN KEY (first_group_id) REFERENCES groups(id),
98106
FOREIGN KEY (second_group_id) REFERENCES groups(id)

init.sql

Lines changed: 0 additions & 52 deletions
This file was deleted.

migrations/2024-10-01-193345_FileClassification/up.sql

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,27 @@ CREATE TABLE IF NOT EXISTS `groups` (
99
create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
1010
modify_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
1111
);
12+
-- 表和字段注释 (仅在支持的数据库中有效)
13+
-- COMMENT ON TABLE `groups` IS '组信息表';
14+
-- COMMENT ON COLUMN `groups`.id IS '组ID';
15+
-- COMMENT ON COLUMN `groups`.name IS '组名称';
16+
-- COMMENT ON COLUMN `groups`.reference_count IS '引用计数';
17+
-- COMMENT ON COLUMN `groups`.is_primary IS '是否为主组';
18+
-- COMMENT ON COLUMN `groups`.click_count IS '点击次数';
19+
-- COMMENT ON COLUMN `groups`.share_count IS '分享次数';
20+
-- COMMENT ON COLUMN `groups`.create_time IS '创建时间';
21+
-- COMMENT ON COLUMN `groups`.modify_time IS '修改时间';
1222

1323
CREATE TABLE IF NOT EXISTS `tags` (
1424
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
1525
reference_count INTEGER NOT NULL DEFAULT 0,
1626
name TEXT NOT NULL UNIQUE
1727
);
28+
-- 表和字段注释 (仅在支持的数据库中有效)
29+
-- COMMENT ON TABLE `tags` IS '标签信息表';
30+
-- COMMENT ON COLUMN `tags`.id IS '标签ID';
31+
-- COMMENT ON COLUMN `tags`.reference_count IS '引用计数';
32+
-- COMMENT ON COLUMN `tags`.name IS '标签名称';
1833

1934
CREATE TABLE IF NOT EXISTS `files` (
2035
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
@@ -24,6 +39,13 @@ CREATE TABLE IF NOT EXISTS `files` (
2439
group_id INTEGER NOT NULL,
2540
FOREIGN KEY (group_id) REFERENCES `groups`(id)
2641
);
42+
-- 表和字段注释 (仅在支持的数据库中有效)
43+
-- COMMENT ON TABLE `files` IS '文件信息表';
44+
-- COMMENT ON COLUMN `files`.id IS '文件ID';
45+
-- COMMENT ON COLUMN `files`.type IS '文件类型';
46+
-- COMMENT ON COLUMN `files`.path IS '文件路径';
47+
-- COMMENT ON COLUMN `files`.reference_count IS '引用计数';
48+
-- COMMENT ON COLUMN `files`.group_id IS '主组ID';
2749

2850
CREATE TABLE IF NOT EXISTS `file_groups` (
2951
file_id INTEGER NOT NULL,
@@ -32,6 +54,10 @@ CREATE TABLE IF NOT EXISTS `file_groups` (
3254
FOREIGN KEY (file_id) REFERENCES `files`(id),
3355
FOREIGN KEY (group_id) REFERENCES `groups`(id)
3456
);
57+
-- 表和字段注释 (仅在支持的数据库中有效)
58+
-- COMMENT ON TABLE `file_groups` IS '文件组关联表';
59+
-- COMMENT ON COLUMN `file_groups`.file_id IS '文件ID';
60+
-- COMMENT ON COLUMN `file_groups`.group_id IS '组ID';
3561

3662
CREATE TABLE IF NOT EXISTS `group_tags` (
3763
group_id INTEGER NOT NULL,
@@ -40,3 +66,7 @@ CREATE TABLE IF NOT EXISTS `group_tags` (
4066
FOREIGN KEY (group_id) REFERENCES `groups`(id),
4167
FOREIGN KEY (tag_id) REFERENCES `tags`(id)
4268
);
69+
-- 表和字段注释 (仅在支持的数据库中有效)
70+
-- COMMENT ON TABLE `group_tags` IS '组标签关联表';
71+
-- COMMENT ON COLUMN `group_tags`.group_id IS '组ID';
72+
-- COMMENT ON COLUMN `group_tags`.tag_id IS '标签ID';

migrations/2025-10-20-000000_update_group_hierarchy/up.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@ CREATE TABLE `group_relations` (
77
FOREIGN KEY (first_group_id) REFERENCES `groups`(id),
88
FOREIGN KEY (second_group_id) REFERENCES `groups`(id)
99
);
10+
-- 表和字段注释 (仅在支持的数据库中有效)
11+
-- COMMENT ON TABLE `group_relations` IS '组关系表';
12+
-- COMMENT ON COLUMN `group_relations`.first_group_id IS '第一个组ID';
13+
-- COMMENT ON COLUMN `group_relations`.second_group_id IS '第二个组ID';
14+
-- COMMENT ON COLUMN `group_relations`.relation_type IS '关系类型';
1015

1116
-- 扩展组表结构
1217
ALTER TABLE `groups` ADD COLUMN parent_id INTEGER REFERENCES `groups`(id);
18+
-- COMMENT ON COLUMN `groups`.parent_id IS '父组ID';
1319

1420
-- 扩展文件组关系表
1521
ALTER TABLE `file_groups` ADD COLUMN relation_type INTEGER NOT NULL DEFAULT 1;
22+
-- COMMENT ON COLUMN `file_groups`.relation_type IS '关系类型';
1623

1724
-- 创建查询优化索引
1825
CREATE INDEX idx_group_relations_first ON `group_relations`(first_group_id);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
-- 为files表添加description字段
22
ALTER TABLE `files` ADD COLUMN description TEXT;
3+
-- COMMENT ON COLUMN `files`.description IS '文件描述';
34

45
-- 为groups表添加description字段
56
ALTER TABLE `groups` ADD COLUMN description TEXT;
7+
-- COMMENT ON COLUMN `groups`.description IS '组描述';
68

79
-- 为tags表添加description字段
810
ALTER TABLE `tags` ADD COLUMN description TEXT;
11+
-- COMMENT ON COLUMN `tags`.description IS '标签描述';

0 commit comments

Comments
 (0)