DB upgrade from 6.7.5-alpine to 7.9.4-community (and 7.9.5-community) fails on step #2506 "Migrate quality gate conditions using warning, period and no more supported operations"

I upgraded from docker container 5.6.6-alpine to 5.6.7-alpine, then to 6.7.5-alpine. I then started the upgrade to 7.9.4-community. It failed with the error:
2020.11.17 22:21:37 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 #2506 ‘Migrate quality gate conditions using warning, period and no more supported operations’ 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(Unknown Source)

I saw a Jira item which indicated that the fix for this is in 7.9.3. I then tried starting 7.9.5-community, and it attempts to migrate the DB again, but gives the same error.

This database was copied from my ‘production’ MSSQL database (running 5.6.6-alpine) and then immediately upgraded in another database instance using the upgrade path above. I saw the workaround in the jira ticket (SONAR-12663) about quality profiles that show “(outdated copy)” in the profile name, but I don’t see anything like it in our instance.

I missed a line in the output:

Caused by: java.lang.IllegalArgumentException: Duplicate key critical_violations

I’m not sure how to find the keys for this.

Hello @mehall,
Please run the below SQL query on your 6.7 database and attach the result,

select qgc.*, m.id, m.name, m.description
from quality_gate_conditions qgc
inner join metrics m on qgc.metric_id = m.id;