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)
因此全部issue的自己定义字段的值的累计行数超过1万行。
由此能够看出redmine的设计是用记录行数来表示扩展字段的值。所以能够不受mysql表字段的限制。