SonarQube
  1. SonarQube
  2. SONAR-2743

Renaming a project in Sonar without losing the history

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Duplicate
    • Affects Version/s: 2.7
    • Fix Version/s: None
    • Component/s: Administration
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Hello,

      I am creatin a request for improvement as per the mailing list. The description follows.

      I just looked at a way to rename a project in Sonar and found the following SONAR-1725 closed issue.

      I have got a use case for it:
      We have a project (let's name it "foo" with version trunk) with a long Sonar history already which gives the project "foo" in Sonar UI.
      .....
      Now, I'd like to rename the "foo" project into "foo trunk" in Sonar UI without losing the history. If I use -Dsonar.branch=trunk Sonar will see it as a brand new project which is not what I want.
      Do you know if there is a way to do this?

      Freddy Mallet answered this:
      "Indeed there isn't currently any way to cover this use case. Feel free to create a JIRA ticket in order to make it possible with the Sonar Maven plugin to override the default Maven project name with the 'sonar.projectName' property."

      I think also that providing a way to rename the project in the Sonar UI before renaming the project in the pom.xml could be a runner. I leave it to you to decide what works best.

        Issue Links

          Activity

          Hide
          Michael Rumpf added a comment -

          This is important in case you need to change the "groupId:ArtifactId:branch" key.
          When you need to do that you should be able to make sure that the new Sonar analysis gets associated to the "old" Sonar project correctly, that means without showing any existing violations as new for example.
          See http://old.nabble.com/How-to-rename-a-Sonar-project--td32973893.html

          Show
          Michael Rumpf added a comment - This is important in case you need to change the "groupId:ArtifactId:branch" key. When you need to do that you should be able to make sure that the new Sonar analysis gets associated to the "old" Sonar project correctly, that means without showing any existing violations as new for example. See http://old.nabble.com/How-to-rename-a-Sonar-project--td32973893.html
          Hide
          Michael Rumpf added a comment -

          1. We were able to revert to an old VMWare snapshot before the renaming started (by loosing some snapshots)
          2. Then we stopped Jenkins to not run any builds (to stop new snapshots from appearing while we are fixing things)
          3. We made sure that the groupId:artifactId:branch name in our pom.xml files are correct so that new builds are associated to the renamed projects and do not create new Sonar projects
          4. Then we renamed all entries in the projects table like this:

          -- create a temporary table for the mapping
          create table mig_prj (old_kee varchar(400), new_kee varchar(400)) ENGINE=InnoDB;
          
          insert into mig_prj values( "com.company.ams.prj1:prj1:1.6.0", "com.company.ams.prj1:prj1:prj1-1.6.0");
          
          insert into mig_prj values( "com.company.ams.prj1:prj1:1.7.0", "com.company.ams.prj1:prj1:prj1-1.7.0");
          insert into mig_prj values( "com.company.ams.prj1:prj1:trunk", "com.company.ams.prj1:prj1:prj1-trunk");
          
          
          insert into mig_prj values( "com.company.ams.prj2:prj2:1.0.0", "com.company.ams.prj2:prj2:prj2-1.0.0");
          insert into mig_prj values( "com.company.ams.prj2:prj2:1.1.0", "com.company.ams.prj2:prj2:prj2-1.1.0");
          
          insert into mig_prj values( "com.company.ams.prj2:prj2:trunk", "com.company.ams.prj2:prj2:prj2-trunk");
          
          insert into mig_prj values( "com.company.ams.prj3:prj3:trunk", "com.company.ams.prj3:prj3:prj3-trunk");
          
          
          insert into mig_prj values( "com.company.ams.prj4:prj4:2.20.8", "com.company.ams.prj4:prj4:prj4-2.20.8");
          insert into mig_prj values( "com.company.ams.prj4:prj4:trunk", "com.company.ams.prj4:prj4:prj4-trunk");
          
          
          insert into mig_prj values( "com.company.ams.prj5:prj5:1.6.0", "com.company.ams.prj5:prj5:prj5-1.6.0");
          insert into mig_prj values( "com.company.ams.prj5:prj5:trunk", "com.company.ams.prj5:prj5:prj5-trunk");
          
          
          insert into mig_prj values( "com.company.ams.prj6:prj6:11.2.58", "com.company.ams.prj6:prj6:prj6-11.2.58");
          insert into mig_prj values( "com.company.ams.prj6:prj6:trunk", "com.company.ams.prj6:prj6:prj6-trunk");
          
          
          insert into mig_prj values( "com.company.ams.prj7:prj7-comp1:trunk", "com.company.ams.prj7:prj7-comp1:prj7-comp1-trunk");
          insert into mig_prj values( "com.company.ams.prj7:prj7-comp2:4.0.0", "com.company.ams.prj7:prj7-comp2:prj7-comp2-4.0.0");
          
          insert into mig_prj values( "com.company.ams.prj7:prj7-comp2:trunk", "com.company.ams.prj7:prj7-comp2:prj7-comp2-trunk");
          insert into mig_prj values( "com.company.ams.prj7:prj7-comp3:trunk", "com.company.ams.prj7:prj7-comp3:prj7-comp3-trunk");
          
          insert into mig_prj values( "com.company.ams.prj7:prj7-comp4:trunk", "com.company.ams.prj7:prj7-comp4:prj7-comp4-trunk");
          insert into mig_prj values( "com.company.ams.prj7:prj7-comp5:trunk", "com.company.ams.prj7:prj7-comp5:prj7-comp5-trunk");
          
          
          insert into mig_prj values( "com.company.ams.commons:prj8:4.0.25", "com.company.ams.commons:prj8:prj8-4.0.25");
          insert into mig_prj values( "com.company.ams.commons:prj8:trunk", "com.company.ams.commons:prj8:prj8-trunk");
          
          
          insert into mig_prj values( "com.company.ams.prj9:ktfakt:trunk", "com.company.ams.prj9:prj9-ktfakt:prj9-ktfakt-trunk");
          
          insert into mig_prj values( "com.company.ams.prj10:prj10:2.8.0", "com.company.ams.prj10:prj10:prj10-2.8.0");
          
          insert into mig_prj values( "com.company.ams.prj10:prj10:trunk", "com.company.ams.prj10:prj10:prj10-trunk");
          
          insert into mig_prj values( "com.company.ams.prj11:prj11-comp6:1.4.0", "com.company.ams.prj11:prj11-comp6:prj11-comp6-1.4.0");
          
          insert into mig_prj values( "com.company.ams.prj11:prj11-comp6:1.4.1", "com.company.ams.prj11:prj11-comp6:prj11-comp6-1.4.1");
          insert into mig_prj values( "com.company.ams.prj11:prj11-comp6:1.6.0", "com.company.ams.prj11:prj11-comp6:prj11-comp6-1.6.0");
          
          insert into mig_prj values( "com.company.ams.prj11:prj11-comp6:trunk", "com.company.ams.prj11:prj11-comp6:prj11-comp6-trunk");
          
          insert into mig_prj values( "com.company.ams.prj11:prj11-rcp:1.4.0", "com.company.ams.prj11:prj11:prj11-1.4.0");
          
          insert into mig_prj values( "com.company.ams.prj11:prj11-rcp:1.4.1", "com.company.ams.prj11:prj11:prj11-1.4.1");
          insert into mig_prj values( "com.company.ams.prj11:prj11-rcp:1.6.0", "com.company.ams.prj11:prj11:prj11-1.6.0");
          
          insert into mig_prj values( "com.company.ams.prj11:prj11-rcp:trunk", "com.company.ams.prj11:prj11:prj11-trunk");
          
          insert into mig_prj values( "com.company.ams.prj12:prj12:trunk", "com.company.ams.prj12:prj12:prj12-trunk");
          
          
          insert into mig_prj values( "com.company.ams.prj13:prj13:11.2.159", "com.company.ams.prj13:prj13:prj13-11.2.159");
          insert into mig_prj values( "com.company.ams.prj13:prj13:trunk", "com.company.ams.prj13:prj13:prj13-trunk");
          
          
          insert into mig_prj values( "com.company.ams.prj14:prj14:2.1.6", "com.company.ams.prj14:prj14:prj14-2.1.6");
          insert into mig_prj values( "com.company.ams.prj14:prj14:2.2.0", "com.company.ams.prj14:prj14:prj14-2.2.0");
          
          insert into mig_prj values( "com.company.ams.prj14:prj14:trunk", "com.company.ams.prj14:prj14:prj14-trunk");
          
          insert into mig_prj values( "com.company.ams.prj15:prj15:1.10.0", "com.company.ams.prj15:prj15:prj15-1.10.0");
          
          insert into mig_prj values( "com.company.ams.prj15:prj15:1.10.1", "com.company.ams.prj15:prj15:prj15-1.10.1");
          insert into mig_prj values( "com.company.ams.prj15:prj15:trunk", "com.company.ams.prj15:prj15:prj15-trunk");
          
          
          insert into mig_prj values( "com.company.ams.prj16:prj16:16.0.0", "com.company.ams.prj16:prj16:prj16-16.0.0");
          insert into mig_prj values( "com.company.ams.prj16:prj16:trunk", "com.company.ams.prj16:prj16:prj16-trunk");
          
          
          insert into mig_prj values( "com.company.ams.prj17:prj17:1.1.2", "com.company.ams.prj17:prj17:prj17-1.1.2");
          insert into mig_prj values( "com.company.ams.prj17:prj17:1.1.3", "com.company.ams.prj17:prj17:prj17-1.1.3");
          
          insert into mig_prj values( "com.company.ams.prj17:prj17:trunk", "com.company.ams.prj17:prj17:prj17-trunk");
          
          insert into mig_prj values( "com.company.ams.prj18-comp7:prj18:2.14.0", "com.company.ams.prj18:prj18:prj18-2.14.0");
          
          insert into mig_prj values( "com.company.ams.prj18-comp7:prj18:2.14.1", "com.company.ams.prj18:prj18:prj18-2.14.1");
          insert into mig_prj values( "com.company.ams.prj18-comp7:prj18:trunk", "com.company.ams.prj18:prj18:prj18-trunk");
          
          
          insert into mig_prj values( "com.company.ams.prj19:prj19:trunk", "com.company.ams.prj19:prj19:prj19-trunk");
          
          insert into mig_prj values( "com.company.ams.prj20:prj20:trunk", "com.company.ams.prj20:prj20:prj20-trunk");
          
          
          -- make a backup of the table
          create table projects_bak select * from projects;
          
          -- update the entries
          UPDATE projects p, mig_prj m 
            SET kee = IF(LENGTH(p.kee) - LENGTH(REPLACE(p.kee, ':', '')) = 3, concat(m.new_kee, ':', SUBSTRING_INDEX(p.kee, ':', -1) ), m.new_kee) 
          
            WHERE p.kee like concat(m.old_kee, '%');
          
          -- check the result (no old entries should be visible anymore)
          select distinct IF(LENGTH(p.kee) - LENGTH(REPLACE(p.kee, ':', '')) = 3, SUBSTRING_INDEX(p.kee, ':', 3), p.kee) 
          
            FROM projects p, mig_prj m 
            WHERE p.kee not like 'com.company.ams.prj21:%' and p.kee not like 'com.company.prj22:%' and p.qualifier not like 'LIB'
            ORDER BY p.kee 
            LIMIT 0, 50000;
          

          So actually the rename operation is quite easy and should be added as a future enhancement so that messing around with SQL is not necessary.

          Show
          Michael Rumpf added a comment - 1. We were able to revert to an old VMWare snapshot before the renaming started (by loosing some snapshots) 2. Then we stopped Jenkins to not run any builds (to stop new snapshots from appearing while we are fixing things) 3. We made sure that the groupId:artifactId:branch name in our pom.xml files are correct so that new builds are associated to the renamed projects and do not create new Sonar projects 4. Then we renamed all entries in the projects table like this: -- create a temporary table for the mapping create table mig_prj (old_kee varchar(400), new_kee varchar(400)) ENGINE=InnoDB; insert into mig_prj values( "com.company.ams.prj1:prj1:1.6.0" , "com.company.ams.prj1:prj1:prj1-1.6.0" ); insert into mig_prj values( "com.company.ams.prj1:prj1:1.7.0" , "com.company.ams.prj1:prj1:prj1-1.7.0" ); insert into mig_prj values( "com.company.ams.prj1:prj1:trunk" , "com.company.ams.prj1:prj1:prj1-trunk" ); insert into mig_prj values( "com.company.ams.prj2:prj2:1.0.0" , "com.company.ams.prj2:prj2:prj2-1.0.0" ); insert into mig_prj values( "com.company.ams.prj2:prj2:1.1.0" , "com.company.ams.prj2:prj2:prj2-1.1.0" ); insert into mig_prj values( "com.company.ams.prj2:prj2:trunk" , "com.company.ams.prj2:prj2:prj2-trunk" ); insert into mig_prj values( "com.company.ams.prj3:prj3:trunk" , "com.company.ams.prj3:prj3:prj3-trunk" ); insert into mig_prj values( "com.company.ams.prj4:prj4:2.20.8" , "com.company.ams.prj4:prj4:prj4-2.20.8" ); insert into mig_prj values( "com.company.ams.prj4:prj4:trunk" , "com.company.ams.prj4:prj4:prj4-trunk" ); insert into mig_prj values( "com.company.ams.prj5:prj5:1.6.0" , "com.company.ams.prj5:prj5:prj5-1.6.0" ); insert into mig_prj values( "com.company.ams.prj5:prj5:trunk" , "com.company.ams.prj5:prj5:prj5-trunk" ); insert into mig_prj values( "com.company.ams.prj6:prj6:11.2.58" , "com.company.ams.prj6:prj6:prj6-11.2.58" ); insert into mig_prj values( "com.company.ams.prj6:prj6:trunk" , "com.company.ams.prj6:prj6:prj6-trunk" ); insert into mig_prj values( "com.company.ams.prj7:prj7-comp1:trunk" , "com.company.ams.prj7:prj7-comp1:prj7-comp1-trunk" ); insert into mig_prj values( "com.company.ams.prj7:prj7-comp2:4.0.0" , "com.company.ams.prj7:prj7-comp2:prj7-comp2-4.0.0" ); insert into mig_prj values( "com.company.ams.prj7:prj7-comp2:trunk" , "com.company.ams.prj7:prj7-comp2:prj7-comp2-trunk" ); insert into mig_prj values( "com.company.ams.prj7:prj7-comp3:trunk" , "com.company.ams.prj7:prj7-comp3:prj7-comp3-trunk" ); insert into mig_prj values( "com.company.ams.prj7:prj7-comp4:trunk" , "com.company.ams.prj7:prj7-comp4:prj7-comp4-trunk" ); insert into mig_prj values( "com.company.ams.prj7:prj7-comp5:trunk" , "com.company.ams.prj7:prj7-comp5:prj7-comp5-trunk" ); insert into mig_prj values( "com.company.ams.commons:prj8:4.0.25" , "com.company.ams.commons:prj8:prj8-4.0.25" ); insert into mig_prj values( "com.company.ams.commons:prj8:trunk" , "com.company.ams.commons:prj8:prj8-trunk" ); insert into mig_prj values( "com.company.ams.prj9:ktfakt:trunk" , "com.company.ams.prj9:prj9-ktfakt:prj9-ktfakt-trunk" ); insert into mig_prj values( "com.company.ams.prj10:prj10:2.8.0" , "com.company.ams.prj10:prj10:prj10-2.8.0" ); insert into mig_prj values( "com.company.ams.prj10:prj10:trunk" , "com.company.ams.prj10:prj10:prj10-trunk" ); insert into mig_prj values( "com.company.ams.prj11:prj11-comp6:1.4.0" , "com.company.ams.prj11:prj11-comp6:prj11-comp6-1.4.0" ); insert into mig_prj values( "com.company.ams.prj11:prj11-comp6:1.4.1" , "com.company.ams.prj11:prj11-comp6:prj11-comp6-1.4.1" ); insert into mig_prj values( "com.company.ams.prj11:prj11-comp6:1.6.0" , "com.company.ams.prj11:prj11-comp6:prj11-comp6-1.6.0" ); insert into mig_prj values( "com.company.ams.prj11:prj11-comp6:trunk" , "com.company.ams.prj11:prj11-comp6:prj11-comp6-trunk" ); insert into mig_prj values( "com.company.ams.prj11:prj11-rcp:1.4.0" , "com.company.ams.prj11:prj11:prj11-1.4.0" ); insert into mig_prj values( "com.company.ams.prj11:prj11-rcp:1.4.1" , "com.company.ams.prj11:prj11:prj11-1.4.1" ); insert into mig_prj values( "com.company.ams.prj11:prj11-rcp:1.6.0" , "com.company.ams.prj11:prj11:prj11-1.6.0" ); insert into mig_prj values( "com.company.ams.prj11:prj11-rcp:trunk" , "com.company.ams.prj11:prj11:prj11-trunk" ); insert into mig_prj values( "com.company.ams.prj12:prj12:trunk" , "com.company.ams.prj12:prj12:prj12-trunk" ); insert into mig_prj values( "com.company.ams.prj13:prj13:11.2.159" , "com.company.ams.prj13:prj13:prj13-11.2.159" ); insert into mig_prj values( "com.company.ams.prj13:prj13:trunk" , "com.company.ams.prj13:prj13:prj13-trunk" ); insert into mig_prj values( "com.company.ams.prj14:prj14:2.1.6" , "com.company.ams.prj14:prj14:prj14-2.1.6" ); insert into mig_prj values( "com.company.ams.prj14:prj14:2.2.0" , "com.company.ams.prj14:prj14:prj14-2.2.0" ); insert into mig_prj values( "com.company.ams.prj14:prj14:trunk" , "com.company.ams.prj14:prj14:prj14-trunk" ); insert into mig_prj values( "com.company.ams.prj15:prj15:1.10.0" , "com.company.ams.prj15:prj15:prj15-1.10.0" ); insert into mig_prj values( "com.company.ams.prj15:prj15:1.10.1" , "com.company.ams.prj15:prj15:prj15-1.10.1" ); insert into mig_prj values( "com.company.ams.prj15:prj15:trunk" , "com.company.ams.prj15:prj15:prj15-trunk" ); insert into mig_prj values( "com.company.ams.prj16:prj16:16.0.0" , "com.company.ams.prj16:prj16:prj16-16.0.0" ); insert into mig_prj values( "com.company.ams.prj16:prj16:trunk" , "com.company.ams.prj16:prj16:prj16-trunk" ); insert into mig_prj values( "com.company.ams.prj17:prj17:1.1.2" , "com.company.ams.prj17:prj17:prj17-1.1.2" ); insert into mig_prj values( "com.company.ams.prj17:prj17:1.1.3" , "com.company.ams.prj17:prj17:prj17-1.1.3" ); insert into mig_prj values( "com.company.ams.prj17:prj17:trunk" , "com.company.ams.prj17:prj17:prj17-trunk" ); insert into mig_prj values( "com.company.ams.prj18-comp7:prj18:2.14.0" , "com.company.ams.prj18:prj18:prj18-2.14.0" ); insert into mig_prj values( "com.company.ams.prj18-comp7:prj18:2.14.1" , "com.company.ams.prj18:prj18:prj18-2.14.1" ); insert into mig_prj values( "com.company.ams.prj18-comp7:prj18:trunk" , "com.company.ams.prj18:prj18:prj18-trunk" ); insert into mig_prj values( "com.company.ams.prj19:prj19:trunk" , "com.company.ams.prj19:prj19:prj19-trunk" ); insert into mig_prj values( "com.company.ams.prj20:prj20:trunk" , "com.company.ams.prj20:prj20:prj20-trunk" ); -- make a backup of the table create table projects_bak select * from projects; -- update the entries UPDATE projects p, mig_prj m SET kee = IF(LENGTH(p.kee) - LENGTH(REPLACE(p.kee, ':', '')) = 3, concat(m.new_kee, ':', SUBSTRING_INDEX(p.kee, ':', -1) ), m.new_kee) WHERE p.kee like concat(m.old_kee, '%'); -- check the result (no old entries should be visible anymore) select distinct IF(LENGTH(p.kee) - LENGTH(REPLACE(p.kee, ':', '')) = 3, SUBSTRING_INDEX(p.kee, ':', 3), p.kee) FROM projects p, mig_prj m WHERE p.kee not like 'com.company.ams.prj21:%' and p.kee not like 'com.company.prj22:%' and p.qualifier not like 'LIB' ORDER BY p.kee LIMIT 0, 50000; So actually the rename operation is quite easy and should be added as a future enhancement so that messing around with SQL is not necessary.
          Hide
          Robert Batusek added a comment -

          Very similar, if not duplicate of http://jira.codehaus.org/browse/SONAR-1608

          Show
          Robert Batusek added a comment - Very similar, if not duplicate of http://jira.codehaus.org/browse/SONAR-1608
          Hide
          Freddy Mallet added a comment -

          Indeed, this ticket duplicates SONAR-1608

          Show
          Freddy Mallet added a comment - Indeed, this ticket duplicates SONAR-1608

            People

            • Assignee:
              Unassigned
              Reporter:
              Jean-Noel Rouvignac
            • Votes:
              2 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: