问题
I'm in the process of migrating a bugzilla installation over to redmine.
In bugzilla bugs were always logged against the version of software which caused the issue to be raised.
Since redmine supports roadmaps I'd like to do a few things to migrate. The first part I'd like to do is to move all the current version settings over to a new custom 'source version' field.
I've tried making a new custom field called 'source version' and manually altering a few bug reports to use that field. Some limited testing suggests that each value specified for that field gets a new entry in the custom_values
table. The following shows three bugs and two of those had the same custom version value of 1.2060:
--------------
SELECT * FROM custom_values WHERE custom_field_id=4
--------------
+------+-----------------+---------------+-----------------+--------+
| id | customized_type | customized_id | custom_field_id | value |
+------+-----------------+---------------+-----------------+--------+
| 4821 | Issue | 765 | 4 | 1.1098 |
| 4822 | Issue | 802 | 4 | 1.2060 |
| 4823 | Issue | 801 | 4 | 1.2060 |
+------+-----------------+---------------+-----------------+--------+
...where custom_field_id relates to the new 'source version' field I added.
So I think to populate the table I need to create a new entry for every issue which I need to copy from the current version.
If it helps, the versions table has the following structure:
--------------
SHOW COLUMNS FROM versions
--------------
+-----------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| project_id | int(11) | NO | MUL | 0 | |
| name | varchar(255) | NO | | | |
| description | varchar(255) | YES | | | |
| effective_date | date | YES | | NULL | |
| created_on | datetime | YES | | NULL | |
| updated_on | datetime | YES | | NULL | |
| wiki_page_title | varchar(255) | YES | | NULL | |
| status | varchar(255) | YES | | open | |
| sharing | varchar(255) | NO | MUL | none | |
+-----------------+--------------+------+-----+---------+----------------+
...and the issues table has the following structure:
--------------
SHOW COLUMNS FROM issues
--------------
+------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| tracker_id | int(11) | NO | MUL | 0 | |
| project_id | int(11) | NO | MUL | 0 | |
| 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 | 0 | |
| assigned_to_id | int(11) | YES | MUL | NULL | |
| priority_id | int(11) | NO | MUL | 0 | |
| fixed_version_id | int(11) | YES | MUL | NULL | |
| author_id | int(11) | NO | MUL | 0 | |
| 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 | |
+------------------+--------------+------+-----+---------+----------------+
The question is, what magical SQL query do I need to do to copy the versions over to the new fields and clean up? I've never been much of an SQL whizz so any help would be gratefully received!
Edit - I tried the following:
INSERT INTO custom_values
(Issue, issues.id, 4, versions.name)
SELECT * FROM issues INNER JOIN versions ON issues.fixed_version_id=versions.id;
...but it gives me an error:
--------------
INSERT INTO custom_values (Issue, issues.id, 4, versions.name) SELECT * FROM issues INNER JOIN versions ON issues.fixed_version_id=versions.id
--------------
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '4, versions.name) SELECT * FROM issues INNER JOIN versions ON issues.fixed_version_id=ve' at line 1
回答1:
Your query
INSERT INTO custom_values
(Issue, issues.id, 4, versions.name)
SELECT * FROM issues INNER JOIN versions ON issues.fixed_version_id=versions.id;
should be modified to this
INSERT INTO custom_values
(customized_type, customized_id, custom_field_id, value)
SELECT 'Issue', issues.id, 4, versions.name
FROM issues INNER JOIN versions ON issues.fixed_version_id=versions.id;
in order to be valid SQL.
But I'd backup the db anyway... :-)
来源:https://stackoverflow.com/questions/11511331/how-can-i-migrate-versions-from-bugzilla-into-a-new-custom-source-version-fiel