Upgrade Fails: Problem upgrading with script, Violation of unique constraint on upgrade_33.sql
Symptoms
Upgrading from Fisheye/Crucible version 1.6.X to 2.X fails with an error similar to the following:
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.cenqua.crucible.hibernate.DBControlFactoryImpl]:
Constructor threw exception; nested exception is com.cenqua.crucible.hibernate.CruDBException:
Problem upgrading with script /data/apps/fecru-2.0.0/sql/HSQL/upgrade/upgrade_33.sql: SQL script error on line 54:
"insert into cru_inline_comment (select distinct(cru_comment), cru_frx_id from cru_revision_comment where cru_line_range is not null);"
(Violation of unique constraint SYS_PK_649: duplicate value(s) for column(s) CRU_COMMENT_ID),
please contact http://www.atlassian.com/support/
Cause
Corruptions in the database, duplicate entries, prevent the upgrade script from completing successfully.
Resolution
- Connect to the HSQL DB using this connection procedure.
- Run the following SQL queries:
select comment from revision_comment where linerange is null group by comment having count(comment) > 1;
- The result will be an ID number, for example:
22
- The result will be an ID number, for example:
select * from revision_comment where comment=22;
- The result will will be the offending data, for example:
12 | 2008-12-02 | 17:35:21 | (null) | 126 | 582 | 22 |
19 | 2008-12-08 | 12:06:23 | (null) | 126 | 1040 | 22 |
3. Either run the following SQL command (don't forget to commit the change):
delete from revision_comment where rc_id = 19;
commit;
OR
Create the SQL script and apply it directly from the command line:
patch.sql
delete from revision_comment where rc_id = 19;
commit;
- Go to
Administration > Backup
and create a backup of the db in your crucible 1.6.6. - Shutdown the Fisheye/Crucible server.
- Go to the
FISHEYE_HOME/lib
directory and run the following command, replacingFISHEYE_HOME
andFISHEYE_INST
with the fully qualified path:
java -Xms512m -Xmx512m -jar FISHEYE_HOME/lib/hsqldb-1.8.0.10.jar --inlineRC "URL=jdbc:hsqldb:file:FISHEYE_INST/var/data/crudb/crucible;shutdown=true,USER=sa,PASSWORD=" patch.sql
4. The above command should result in output similar to the following:
x rows updated (where x is some number > 0)