diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-07-01 15:07:23 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-07-04 10:25:06 +0200 |
commit | 1cc993f6dae7a22df577faa7101d06dc6c594974 (patch) | |
tree | f3b2cc8b3a1f45f29dae4bfd0c1c284dde31dcb5 /sonar-db/src/main | |
parent | c2e857e42a85a723a08cd1344930c62f6bce5972 (diff) | |
download | sonarqube-1cc993f6dae7a22df577faa7101d06dc6c594974.tar.gz sonarqube-1cc993f6dae7a22df577faa7101d06dc6c594974.zip |
SONAR-7780 Fix migration of PROJECTS.UUID_PATH
Diffstat (limited to 'sonar-db/src/main')
5 files changed, 57 insertions, 4 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java b/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java index 591785e9c37..1dea1492e65 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java +++ b/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java @@ -30,7 +30,7 @@ import org.sonar.db.MyBatis; public class DatabaseVersion { - public static final int LAST_VERSION = 1_267; + public static final int LAST_VERSION = 1_268; /** * The minimum supported version which can be upgraded. Lower diff --git a/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java b/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java index 833b345701a..7047aed0917 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java +++ b/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java @@ -115,6 +115,7 @@ import org.sonar.db.version.v60.DropSnapshotIdColumnFromCeActivity; import org.sonar.db.version.v60.DropSnapshotIdColumnFromEvents; import org.sonar.db.version.v60.DropSnapshotIdColumnsFromDuplicationsIndex; import org.sonar.db.version.v60.DropUnusedMeasuresColumns; +import org.sonar.db.version.v60.FixProjectUuidOfDevelopers; import org.sonar.db.version.v60.MakeAnalysisUuidNotNullOnDuplicationsIndex; import org.sonar.db.version.v60.MakeAnalysisUuidNotNullOnEvents; import org.sonar.db.version.v60.MakeAnalysisUuidNotNullOnMeasures; @@ -287,6 +288,7 @@ public class MigrationStepModule extends Module { MakeAnalysisUuidNotNullOnEvents.class, DropSnapshotIdColumnFromEvents.class, + FixProjectUuidOfDevelopers.class, // PROJECTS.UUID_PATH AddUuidPathColumnToProjects.class, PopulateUuidPathColumnOnProjects.class, diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/FixProjectUuidOfDevelopers.java b/sonar-db/src/main/java/org/sonar/db/version/v60/FixProjectUuidOfDevelopers.java new file mode 100644 index 00000000000..3e042c03f3a --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/FixProjectUuidOfDevelopers.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.version.v60; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.version.BaseDataChange; +import org.sonar.db.version.MassUpdate; +import org.sonar.db.version.Select; +import org.sonar.db.version.SqlStatement; + +public class FixProjectUuidOfDevelopers extends BaseDataChange { + + public FixProjectUuidOfDevelopers(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("select distinct developer_uuid from projects where qualifier = 'DEV_PRJ'"); + massUpdate.update("update projects set project_uuid = developer_uuid where developer_uuid = ? and qualifier = 'DEV_PRJ'"); + massUpdate.rowPluralName("developers in project"); + massUpdate.execute((row, update) -> handleComponent(row, update)); + } + + private boolean handleComponent(Select.Row row, SqlStatement update) throws SQLException { + String developerUuid = row.getString(1); + update.setString(1, developerUuid); + + return true; + } +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateUuidPathColumnOnProjects.java b/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateUuidPathColumnOnProjects.java index 71e7aa77a76..a8361e0d9c2 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateUuidPathColumnOnProjects.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateUuidPathColumnOnProjects.java @@ -60,7 +60,7 @@ public class PopulateUuidPathColumnOnProjects extends BaseDataChange { handleRoot(rootUuid, context); } - handleOrphans(context); + handleOrphans(context); } private void handleRoot(String rootComponentUuid, Context context) throws SQLException { @@ -91,7 +91,7 @@ public class PopulateUuidPathColumnOnProjects extends BaseDataChange { massUpdate.execute((row, update, updateIndex) -> { String uuid = row.getString(1); String rootUuid = row.getString(2); - String path = uuid.equals(rootUuid) ? ROOT_PATH : (rootUuid + PATH_SEPARATOR); + String path = uuid.equals(rootUuid) ? ROOT_PATH : (PATH_SEPARATOR + rootUuid + PATH_SEPARATOR); update.setString(1, path); update.setString(2, uuid); return true; @@ -119,7 +119,7 @@ public class PopulateUuidPathColumnOnProjects extends BaseDataChange { List<String> componentUuidPath = Arrays.stream(snapshot.snapshotPath) .mapToObj(snapshotId -> relations.snapshotsById.get(snapshotId).componentUuid) .collect(toCollection(() -> new ArrayList<>(snapshot.snapshotPath.length))); - update.setString(1, PATH_JOINER.join(componentUuidPath) + PATH_SEPARATOR); + update.setString(1, PATH_SEPARATOR + PATH_JOINER.join(componentUuidPath) + PATH_SEPARATOR); update.setString(2, componentUuid); return true; } diff --git a/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql b/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql index 8ef6e3b5307..0c7445b65db 100644 --- a/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql +++ b/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql @@ -474,6 +474,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1264'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1265'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1266'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1267'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1268'); INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, USER_LOCAL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT) VALUES (1, 'admin', 'Administrator', '', 'admin', 'sonarqube', true, 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '1418215735482', '1418215735482'); ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2; |