Upgrade 6.7.6 -> 7.9.1 - Quality Gate DB error

Hello community!

old version: 6.7.6 (build 38781) CE
new version: 7.9.1.27448 CE
environment: docker container with external MSSQL database

I called the /setup page and got following failure message from startup logs:

2019.07.11 14:40:48 INFO web[DbMigrations] #1951 ‘Drop unique index on QUALITY_GATES.NAME’…
2019.07.11 14:40:48 ERROR web[DbMigrations] #1951 ‘Drop unique index on QUALITY_GATES.NAME’: failure | time=10ms
2019.07.11 14:40:49 ERROR web[DbMigrations] Executed DB migrations: failure | time=11ms
2019.07.11 14:40:49 ERROR web[o.s.s.p.d.m.DatabaseMigrationImpl] DB migration failed | time=142ms
2019.07.11 14:40:49 ERROR web[o.s.s.p.d.m.DatabaseMigrationImpl] DB migration ended with an exception
org.sonar.server.platform.db.migration.step.MigrationStepExecutionException: Execution of migration step #1951 ‘Drop unique index on QUALITY_GATES.NAME’ failed
at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:79)
at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:67)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:52)
at org.sonar.server.platform.db.migration.engine.MigrationEngineImpl.execute(MigrationEngineImpl.java:68)
at org.sonar.server.platform.db.migration.DatabaseMigrationImpl.doUpgradeDb(DatabaseMigrationImpl.java:105)
at org.sonar.server.platform.db.migration.DatabaseMigrationImpl.doDatabaseMigration(DatabaseMigrationImpl.java:80)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalStateException: Fail to execute DROP INDEX uniq_quality_gates ON quality_gates
at org.sonar.server.platform.db.migration.step.DdlChange$Context.execute(DdlChange.java:97)
at org.sonar.server.platform.db.migration.step.DdlChange$Context.execute(DdlChange.java:77)
at org.sonar.server.platform.db.migration.step.DdlChange$Context.execute(DdlChange.java:117)
at org.sonar.server.platform.db.migration.version.v70.DropUniqueIndexOnQualityGatesName.execute(DropUniqueIndexOnQualityGatesName.java:35)
at org.sonar.server.platform.db.migration.step.DdlChange.execute(DdlChange.java:45)
at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:75)
… 9 common frames omitted
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot drop the index ‘quality_gates.uniq_quality_gates’, because it does not exist or you do not have permission.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:262)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1621)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:868)
at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:768)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7194)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2935)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:248)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:223)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.execute(SQLServerStatement.java:744)
at org.apache.commons.dbcp2.DelegatingStatement.execute(DelegatingStatement.java:175)
at org.apache.commons.dbcp2.DelegatingStatement.execute(DelegatingStatement.java:175)
at org.sonar.server.platform.db.migration.step.DdlChange$Context.execute(DdlChange.java:82)
… 14 common frames omitted

Adjustment to docker container: only added a custom root CA certificate (private PKI) and additional plugins (from official website):

sonar-csharp-plugin-7.10.0.7896.jar
sonar-java-plugin-5.9.2.16552.jar
sonar-ldap-plugin-2.2.0.608.jar
sonar-findbugs-plugin-3.6.0.jar
sonar-javascript-plugin-5.0.0.6962.jar
sonar-scm-svn-plugin-1.3.jar

For the update I deleted the plugin folder because I saw the most are already included now.

DB admin already confirmed that deletion is allowed from permission side. I also found an index called quality_gates$uniq_quality_gates and renamed it but no success…

An idea came into my mind that I maybe just re-create the INDEX manually but I don’t have much experience with the command for that. :frowning:

Any suggestions? :slight_smile:

Just out of curiousity, what version of MSSQL?

For what it’s worth, when it comes to dropping a database index the required permission for the database user defined in sonar.jdbc.username is ALTER permissions on the table. If your database user has anything less than db_owner permissions, make sure to check.

Weird. That is the index SonarQube wants to drop. I would not suggest renaming it to get around the issue. SonarQube doesn’t go check to see whether or not the index exists before trying to delete it, it needs to be the one deleting it before proceeding.

Before doing that, you might consider trying to drop the index while logged in as the SonarQube database user and see if you still get an error (DROP INDEX uniq_quality_gates ON quality_gates;

All told, since you manually manipulated the index to be on the safe side you should restore your database from a backup and attempt the migration again after checking out any potential permissions issues.