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表字段的限制。

redmine 自己定义字段mysql表结构的更多相关文章

  1. [转载]github在线更改mysql表结构工具gh-ost

    GitHub正式宣布以开源的方式发布gh-ost:GitHub的MySQL无触发器在线更改表定义工具! gh-ost是GitHub最近几个月开发出来的,目的是解决一个经常碰到的问题:不断变化的产品需求 ...

  2. 查看mysql表结构和表创建语句的方法(转)

    查看mysql表结构的方法有三种:1.desc tablename;例如:要查看jos_modules表结构的命令:desc jos_modules;查看结果:mysql> desc jos_m ...

  3. mysql:恢复mysql表结构

    mysql,frm格式恢复mysql表结构,以tuser.frm格式为例   新增数据库,如下,创建数据库名为ab   打开数据库,双击打开数据库   点右键新建表结构   新增表,里面只添加一个字段 ...

  4. MySQL表结构同步工具 mysql-schema-sync

    mysql-schema-sync 是一款使用go开发的.跨平台的.绿色无依赖的 MySQL 表结构自动同步工具.用于将线上(其他环境)数据库结构变化同步到测试(本地)环境! 可以解决多人开发,每人都 ...

  5. SQL SERVER 自动生成 MySQL 表结构及索引 的建表SQL

          SQL SERVER的表结构及索引转换为MySQL的表结构及索引,其实在很多第三方工具中有提供,比如navicat.sqlyog等,但是,在处理某些数据类型.默认值及索引转换的时候,总有些 ...

  6. 【转】查看mysql表结构和表创建语句的方法

    转自:http://blog.csdn.net/business122/article/details/7531291 查看mysql表结构的方法有三种: 1.desc tablename; 例如: ...

  7. Sqoop将MySQL表结构同步到hive(text、orc)

    Sqoop将MySQL表结构同步到hive sqoop create-hive-table --connect jdbc:mysql://localhost:3306/sqooptest --user ...

  8. Mysql表结构定义及相关语法

    mysql语法及相关命令1.每个sql命令都需要使用分号来完成2.可以将一个命令写成多行3.可以通过\c来取消本行命令4.可以通过\g.exit.ctrl+c或者quit来退出当前客户端5.可以通过使 ...

  9. mysql 表结构及基本操作

    说明在mysql语句中,sql语句总共分四种 a.DDL数据定义语句=>常用的ddl语句有(CREATE[创建],DROP[删除],ALTER[修改表结构]) b.DML数据操作语句=>常 ...

随机推荐

  1. Kubectl管理工具

    1.常用指令如下 运行应用程序 [root@manager ~]# kubectl run hello-world --replicas=3 --labels="app=example&qu ...

  2. 移动端px转rem的两种方法

    rem使用方法: rem ,root element,即相对于根元素的大小,浏览器默认字符大小为16px,此时1rem相当于16px.  方法1 设置font-size: body{font-size ...

  3. *LOJ#2134. 「NOI2015」小园丁与老司机

    $n \leq 5e4$个平面上的点,从原点出发,能从当前点向左.右.上.左上或右上到达该方向最近的给定点.问三个问:一.最多经过多少点:二.前一问的方案:三.其所有方案种非左右走的边至少要开几辆挖掘 ...

  4. android日期时间选择器

    android原生的日期时间控件,因为是原生的总有其满足不了我们需求的时候,Android 手机版本那么多,用户弹出来的控件五花八门.因为项目需要,在网上找了一 些demo看了看,感觉有些写的很好,很 ...

  5. python-re之中文匹配

    #coding=utf-8 import re import chardet#检测网页编码形式的模块 p = re.compile(r'\d+') print p.findall('one1two2t ...

  6. POJ 1239 Increasing Sequences [DP]

    题意:略. 思路:进行两次dp. 第一次dp从前向后,用dp[x]表示从第x位向前dp[x]位可构成一个数字,且与前面的数组符合题意要求.最后求的dp[n]即为最后一个数字的长度. 而题目还有要求,所 ...

  7. JavaScript 深克隆

    深克隆 function judgeType(arg){//判断js数据类型 return Object.prototype.toString.call(arg).slice(8,-1); } fun ...

  8. ASIHTTPRequest实现断点续传

    http://blog.csdn.net/daiyelang/article/category/1377418 ASIHTTPRequest可以实现断点续传.网上有一些介绍类似使用:   [reque ...

  9. struts2拦截器实现session超时返回登录页面(iframe下跳转到其父页面)

    需求:session超时时,返回登录页面,由于页面嵌套在iframe下,因此要跳转到登录页面的父页面,但是首页,登录页面等不需要进行跳转 实现: java文件:SessionIterceptor.ja ...

  10. Mac搭建python环境

    1 安装xcode 2 安装 brew ruby-e"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/mast ...