Redmine自己定义字段MySQL表结构

发表于:2018-3-28 10:34

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:llguanli    来源:博客园

  redmine能够创建自己定义字段,我经经常使用它来满足不同的管理需求。如今来解读一下。看看这些自己定义字段是怎样存在mysql表中的。
  表issues
  用来存放issue的标准字段。
mysql> describe issues;
+----------------------+--------------+------+-----+---------+----------------+
| Field                | Type         | Null | Key | Default | Extra          |
+----------------------+--------------+------+-----+---------+----------------+
| id                   | int(11)      | NO   | PRI | NULL    | auto_increment |
| tracker_id           | int(11)      | NO   | MUL | NULL    |                |
| project_id           | int(11)      | NO   | MUL | NULL    |                |
| subject              | varchar(255) | NO   |     |         |                |
| description          | text         | YES  |     | NULL    |                |
| due_date             | date         | YES  |     | NULL    |                |
| category_id          | int(11)      | YES  | MUL | NULL    |                |
| status_id            | int(11)      | NO   | MUL | NULL    |                |
| assigned_to_id       | int(11)      | YES  | MUL | NULL    |                |
| priority_id          | int(11)      | NO   | MUL | NULL    |                |
| fixed_version_id     | int(11)      | YES  | MUL | NULL    |                |
| author_id            | int(11)      | NO   | MUL | NULL    |                |
| lock_version         | int(11)      | NO   |     | 0       |                |
| created_on           | datetime     | YES  | MUL | NULL    |                |
| updated_on           | datetime     | YES  |     | NULL    |                |
| start_date           | date         | YES  |     | NULL    |                |
| done_ratio           | int(11)      | NO   |     | 0       |                |
| estimated_hours      | float        | YES  |     | NULL    |                |
| parent_id            | int(11)      | YES  |     | NULL    |                |
| root_id              | int(11)      | YES  | MUL | NULL    |                |
| lft                  | int(11)      | YES  |     | NULL    |                |
| rgt                  | int(11)      | YES  |     | NULL    |                |
| is_private           | tinyint(1)   | NO   |     | 0       |                |
| closed_on            | datetime     | YES  |     | NULL    |                |
| position             | int(11)      | NO   | MUL | NULL    |                |
| remaining_hours      | float        | YES  |     | NULL    |                |
| release_id           | int(11)      | YES  | MUL | NULL    |                |
| story_points         | float        | YES  |     | NULL    |                |
| release_relationship | varchar(255) | NO   | MUL | auto    |                |
+----------------------+--------------+------+-----+---------+----------------+
  表custom_fields
  该表字段都和创建自己定义字段的web页面看到的选择项非常像。
mysql> describe custom_fields;
+-----------------+--------------+------+-----+---------+----------------+
| Field           | Type         | Null | Key | Default | Extra          |
+-----------------+--------------+------+-----+---------+----------------+
| id              | int(11)      | NO   | PRI | NULL    | auto_increment |
| type            | varchar(30)  | NO   |     |         |                |
| name            | varchar(30)  | NO   |     |         |                |
| field_format    | varchar(30)  | NO   |     |         |                |
| possible_values | text         | YES  |     | NULL    |                |
| regexp          | varchar(255) | YES  |     |         |                |
| min_length      | int(11)      | YES  |     | NULL    |                |
| max_length      | int(11)      | YES  |     | NULL    |                |
| is_required     | tinyint(1)   | NO   |     | 0       |                |
| is_for_all      | tinyint(1)   | NO   |     | 0       |                |
| is_filter       | tinyint(1)   | NO   |     | 0       |                |
| position        | int(11)      | YES  |     | 1       |                |
| searchable      | tinyint(1)   | YES  |     | 0       |                |
| default_value   | text         | YES  |     | NULL    |                |
| editable        | tinyint(1)   | YES  |     | 1       |                |
| visible         | tinyint(1)   | NO   |     | 1       |                |
| multiple        | tinyint(1)   | YES  |     | 0       |                |
| format_store    | text         | YES  |     | NULL    |                |
| description     | text         | YES  |     | NULL    |                |
+-----------------+--------------+------+-----+---------+----------------+
  表custom_values
mysql> describe custom_values;
+-----------------+-------------+------+-----+---------+----------------+
| Field           | Type        | Null | Key | Default | Extra          |
+-----------------+-------------+------+-----+---------+----------------+
| id              | int(11)     | NO   | PRI | NULL    | auto_increment |
| customized_type | varchar(30) | NO   | MUL |         |                |
| customized_id   | int(11)     | NO   |     | 0       |                |
| custom_field_id | int(11)     | NO   | MUL | 0       |                |
| value           | text        | YES  |     | NULL    |                |
+-----------------+-------------+------+-----+---------+----------------+
  该表能够用custom_field_id字段和custom_fields表的id关联。
  而customized_id 能够和issues表的id相关联
  因此三个表issues, custom_fields和custom_values在一起表达了这么个关系。
  一个issue的标准字段来自issues表,扩展字段来自custom_fields表。而custom_values和前custom_fields表关联,一起表示一个issue的某个自己定义字段的值。
  而且。当表示issue的自己定义字段时,custom_fields.type的值是 'IssueCustomField' 而custom_values.customized_type的值是'Issue'.
  全部issue的自己定义字段值
  因此能够先将custom_fields表和custom_values表关联,获得例如以下结果:
mysql> select customized_id as issue_id,custom_field_id,type,name,default_value,value from custom_fields a inner join custom_values b on a.id =b.custom_field_id and a.type = 'IssueCustomField' and b.customized_type='Issue' limit 2;
+----------+-----------------+------------------+--------------+---------------+------------+
| issue_id | custom_field_id | type             | name         | default_value | value      |
+----------+-----------------+------------------+--------------+---------------+------------+
|     1771 |               7 | IssueCustomField | 发现日期     |               | 2014-06-01 |
|     1772 |               7 | IssueCustomField | 发现日期     |               | 2014-06-15 |
+----------+-----------------+------------------+--------------+---------------+------------+
2 rows in set (0.06 sec)
  通常这个表都会非常大。我的系统里面有22个自己定义字段。同一时候有500多个issue,每一个issue最多会有22个行表示其自己定义字段的值。
  因此全部issue的自己定义字段的值的累计行数超过1万行。
  由此能够看出redmine的设计是用记录行数来表示扩展字段的值。所以能够不受mysql表字段的限制。

上文内容不用于商业目的,如涉及知识产权问题,请权利人联系博为峰小编(021-64471599-8017),我们将立即处理。
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号