How to find 'active' snapshots that cause

2019-09-02 06:01发布

问题:

I’m getting the same error as Julien Lancelot answered re:

Failed to upgrade SonarQube from 4.5 to 5.0.1

ie

2015.02.18 14:56:26 INFO  web[DbMigration]  ==  PopulateProjectsUuidColumns: migrating ====================================
2015.02.18 14:56:43 ERROR web[o.s.s.d.m.DatabaseMigrator]  Fail to execute database migration: org.sonar.server.db.migrations.v50.PopulateProjectsUuidColum
nsMigration
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: java.lang.NullPointerException
### Cause: java.lang.NullPointerException
        at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26) ~[mybatis-3.2.7.jar:3.2.7]
        at org.apache.ibatis.session.defaults.DefaultSqlSession.select(DefaultSqlSession.java:130) ~[mybatis-3.2.7.jar:3.2.7]
        at org.apache.ibatis.session.defaults.DefaultSqlSession.select(DefaultSqlSession.java:122) ~[mybatis-3.2.7.jar:3.2.7]
        at org.sonar.core.persistence.DbSession.select(DbSession.java:125) ~[sonar-core-5.0.jar:na]
        at org.sonar.server.db.migrations.v50.PopulateProjectsUuidColumnsMigration.execute(PopulateProjectsUuidColumnsMigration.java:65) ~[sonar-server-5.0.jar:na]

Julian mentioned

With the help of the SQL query and the modified jar to add some debug, I've finally found from where the issue is coming : your project with id 39554 have 2 active snapshots (1234385 and 1234386). This use case is not managed as this should never happen.

How can I identify the mentioned ‘active’ snapshots and delete them so this step succeeds?

回答1:

Answered by Julian via email, here is the sql

SELECT snapshots.id, COUNT() FROM projects INNER JOIN snapshots ON snapshots.project_id=projects.id AND snapshots.islast=true GROUP BY snapshots.id HAVING COUNT() > 1