From: Sébastien Lesaint Date: Fri, 17 Jun 2016 15:04:35 +0000 (+0200) Subject: SONAR-7689 add column DUPLICATIONS_INDEX.ANALYSIS_UUID X-Git-Tag: 6.0-RC1~262 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6c9d9cba5c66207c9706988ece2a235df4ce1e52;p=sonarqube.git SONAR-7689 add column DUPLICATIONS_INDEX.ANALYSIS_UUID --- diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1239_add_analysis_uuid_to_duplications_index.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1239_add_analysis_uuid_to_duplications_index.rb new file mode 100644 index 00000000000..a3154d5155b --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1239_add_analysis_uuid_to_duplications_index.rb @@ -0,0 +1,29 @@ +# +# SonarQube, open source software quality management tool. +# Copyright (C) 2008-2014 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube 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. +# +# SonarQube 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. +# + +# +# SonarQube 6.0 +# +class AddAnalysisUuidToDuplicationsIndex < ActiveRecord::Migration + + def self.up + execute_java_migration('org.sonar.db.version.v60.AddAnalysisUuidColumnToDuplicationsIndex') + end +end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1240_populate_analysis_uuid_of_duplications_index.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1240_populate_analysis_uuid_of_duplications_index.rb new file mode 100644 index 00000000000..b760ef1c1a0 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1240_populate_analysis_uuid_of_duplications_index.rb @@ -0,0 +1,29 @@ +# +# SonarQube, open source software quality management tool. +# Copyright (C) 2008-2014 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube 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. +# +# SonarQube 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. +# + +# +# SonarQube 6.0 +# +class PopulateAnalysisUuidOfDuplicationsIndex < ActiveRecord::Migration + + def self.up + execute_java_migration('org.sonar.db.version.v60.PopulateAnalysisUuidOfDuplicationsIndex') + end +end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1241_delete_orphan_duplications_index_rows_without_analysis.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1241_delete_orphan_duplications_index_rows_without_analysis.rb new file mode 100644 index 00000000000..cf42ef85db7 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1241_delete_orphan_duplications_index_rows_without_analysis.rb @@ -0,0 +1,29 @@ +# +# SonarQube, open source software quality management tool. +# Copyright (C) 2008-2014 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube 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. +# +# SonarQube 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. +# + +# +# SonarQube 6.0 +# +class DeleteOrphanDuplicationsIndexRowsWithoutAnalysis < ActiveRecord::Migration + + def self.up + execute_java_migration('org.sonar.db.version.v60.DeleteOrphanDuplicationsIndexRowsWithoutAnalysis') + end +end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1242_make_analysis_uuid_not_null_on_duplications_index.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1242_make_analysis_uuid_not_null_on_duplications_index.rb new file mode 100644 index 00000000000..dfb335e57ba --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1242_make_analysis_uuid_not_null_on_duplications_index.rb @@ -0,0 +1,31 @@ +# +# SonarQube, open source software quality management tool. +# Copyright (C) 2008-2014 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube 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. +# +# SonarQube 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. +# + +# +# SonarQube 6.0 +# +class MakeAnalysisUuidNotNullOnDuplicationsIndex < ActiveRecord::Migration + + def self.up + execute_java_migration('org.sonar.db.version.v60.MakeAnalysisUuidNotNullOnDuplicationsIndex') + + add_index :duplications_index, [:analysis_uuid, :component_uuid], :name => 'duplication_analysis_component' + end +end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1243_drop_index_duplications_index_sid_from_duplications_index.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1243_drop_index_duplications_index_sid_from_duplications_index.rb new file mode 100644 index 00000000000..23ccd6c55d1 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1243_drop_index_duplications_index_sid_from_duplications_index.rb @@ -0,0 +1,33 @@ +# +# SonarQube, open source software quality management tool. +# Copyright (C) 2008-2014 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube 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. +# +# SonarQube 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. +# + +# +# SonarQube 6.0 +# +class DropIndexDuplicationsIndexSidFromDuplicationsIndex < ActiveRecord::Migration + + def self.up + begin + remove_index :duplications_index, :name => 'duplications_index_sid' + rescue + #ignore + end + end +end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1244_drop_snapshot_id_columns_from_duplications_index.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1244_drop_snapshot_id_columns_from_duplications_index.rb new file mode 100644 index 00000000000..07136fa7b71 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1244_drop_snapshot_id_columns_from_duplications_index.rb @@ -0,0 +1,29 @@ +# +# SonarQube, open source software quality management tool. +# Copyright (C) 2008-2014 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube 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. +# +# SonarQube 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. +# + +# +# SonarQube 6.0 +# +class DropSnapshotIdColumnsFromDuplicationsIndex < ActiveRecord::Migration + + def self.up + execute_java_migration('org.sonar.db.version.v60.DropSnapshotIdColumnsFromDuplicationsIndex') + end +end 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 7164ed2f1e4..bf564b92283 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_238; + public static final int LAST_VERSION = 1_244; /** * 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 cc29007d6b7..4f4d7cfef7b 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 @@ -84,6 +84,7 @@ import org.sonar.db.version.v55.FeedRulesTypes; import org.sonar.db.version.v56.FixLengthOfIssuesMessageOnOracle; import org.sonar.db.version.v56.FixTypeOfRuleTypeOnMysql; import org.sonar.db.version.v60.AddAnalysisUuidColumnToCeActivity; +import org.sonar.db.version.v60.AddAnalysisUuidColumnToDuplicationsIndex; import org.sonar.db.version.v60.AddComponentUuidColumnToDuplicationsIndex; import org.sonar.db.version.v60.AddComponentUuidColumnToMeasures; import org.sonar.db.version.v60.AddComponentUuidColumnsToSnapshots; @@ -93,6 +94,7 @@ import org.sonar.db.version.v60.AddUuidColumnsToResourceIndex; import org.sonar.db.version.v60.CleanOrphanRowsInProjects; import org.sonar.db.version.v60.CleanOrphanRowsInResourceIndex; import org.sonar.db.version.v60.CleanOrphanRowsInSnapshots; +import org.sonar.db.version.v60.DeleteOrphanDuplicationsIndexRowsWithoutAnalysis; import org.sonar.db.version.v60.DeleteOrphanDuplicationsIndexRowsWithoutComponent; import org.sonar.db.version.v60.DeleteOrphanMeasuresWithoutComponent; import org.sonar.db.version.v60.DropIdColumnsFromProjects; @@ -101,7 +103,9 @@ import org.sonar.db.version.v60.DropIdColumnsFromSnapshots; import org.sonar.db.version.v60.DropProjectIdColumnFromMeasures; import org.sonar.db.version.v60.DropRememberMeColumnsFromUsers; import org.sonar.db.version.v60.DropSnapshotIdColumnFromCeActivity; +import org.sonar.db.version.v60.DropSnapshotIdColumnsFromDuplicationsIndex; import org.sonar.db.version.v60.DropUnusedMeasuresColumns; +import org.sonar.db.version.v60.MakeAnalysisUuidNotNullOnDuplicationsIndex; import org.sonar.db.version.v60.MakeComponentUuidColumnsNotNullOnSnapshots; import org.sonar.db.version.v60.MakeComponentUuidNotNullOnDuplicationsIndex; import org.sonar.db.version.v60.MakeComponentUuidNotNullOnMeasures; @@ -109,6 +113,7 @@ import org.sonar.db.version.v60.MakeUuidColumnNotNullOnSnapshots; import org.sonar.db.version.v60.MakeUuidColumnsNotNullOnProjects; import org.sonar.db.version.v60.MakeUuidColumnsNotNullOnResourceIndex; import org.sonar.db.version.v60.PopulateAnalysisUuidColumnOnCeActivity; +import org.sonar.db.version.v60.PopulateAnalysisUuidOfDuplicationsIndex; import org.sonar.db.version.v60.PopulateComponentUuidColumnsOfSnapshots; import org.sonar.db.version.v60.PopulateComponentUuidOfDuplicationsIndex; import org.sonar.db.version.v60.PopulateComponentUuidOfMeasures; @@ -237,6 +242,13 @@ public class MigrationStepModule extends Module { AddComponentUuidColumnToDuplicationsIndex.class, PopulateComponentUuidOfDuplicationsIndex.class, DeleteOrphanDuplicationsIndexRowsWithoutComponent.class, - MakeComponentUuidNotNullOnDuplicationsIndex.class); + MakeComponentUuidNotNullOnDuplicationsIndex.class, + + // analysis_uuid in duplications_index + AddAnalysisUuidColumnToDuplicationsIndex.class, + PopulateAnalysisUuidOfDuplicationsIndex.class, + DeleteOrphanDuplicationsIndexRowsWithoutAnalysis.class, + MakeAnalysisUuidNotNullOnDuplicationsIndex.class, + DropSnapshotIdColumnsFromDuplicationsIndex.class); } } diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/AddAnalysisUuidColumnToDuplicationsIndex.java b/sonar-db/src/main/java/org/sonar/db/version/v60/AddAnalysisUuidColumnToDuplicationsIndex.java new file mode 100644 index 00000000000..c4c47ef3f6b --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/AddAnalysisUuidColumnToDuplicationsIndex.java @@ -0,0 +1,45 @@ +/* + * 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.AddColumnsBuilder; +import org.sonar.db.version.DdlChange; + +import static org.sonar.db.version.VarcharColumnDef.UUID_VARCHAR_SIZE; +import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; + +public class AddAnalysisUuidColumnToDuplicationsIndex extends DdlChange { + + private static final String TABLE_DUPLICATIONS_INDEX = "duplications_index"; + + public AddAnalysisUuidColumnToDuplicationsIndex(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new AddColumnsBuilder(getDatabase().getDialect(), TABLE_DUPLICATIONS_INDEX) + .addColumn(newVarcharColumnDefBuilder().setColumnName("analysis_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(true).build()) + .build()); + } + +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/DeleteOrphanDuplicationsIndexRowsWithoutAnalysis.java b/sonar-db/src/main/java/org/sonar/db/version/v60/DeleteOrphanDuplicationsIndexRowsWithoutAnalysis.java new file mode 100644 index 00000000000..ae7858ce55b --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/DeleteOrphanDuplicationsIndexRowsWithoutAnalysis.java @@ -0,0 +1,45 @@ +/* + * 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; + +public class DeleteOrphanDuplicationsIndexRowsWithoutAnalysis extends BaseDataChange { + + public DeleteOrphanDuplicationsIndexRowsWithoutAnalysis(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("SELECT distinct project_snapshot_id from duplications_index where analysis_uuid is null"); + massUpdate.update("DELETE from duplications_index WHERE project_snapshot_id=?"); + massUpdate.rowPluralName("no analysis duplication index entries"); + massUpdate.execute((row, update) -> { + update.setLong(1, row.getLong(1)); + return true; + }); + } + +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/DropSnapshotIdColumnsFromDuplicationsIndex.java b/sonar-db/src/main/java/org/sonar/db/version/v60/DropSnapshotIdColumnsFromDuplicationsIndex.java new file mode 100644 index 00000000000..ee2bca0b244 --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/DropSnapshotIdColumnsFromDuplicationsIndex.java @@ -0,0 +1,41 @@ +/* + * 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.DdlChange; +import org.sonar.db.version.DropColumnsBuilder; + +public class DropSnapshotIdColumnsFromDuplicationsIndex extends DdlChange { + + private static final String TABLE_DUPLICATIONS_INDEX = "duplications_index"; + + public DropSnapshotIdColumnsFromDuplicationsIndex(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute( + new DropColumnsBuilder(getDialect(), TABLE_DUPLICATIONS_INDEX, "project_snapshot_id", "snapshot_id").build()); + } + +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/MakeAnalysisUuidNotNullOnDuplicationsIndex.java b/sonar-db/src/main/java/org/sonar/db/version/v60/MakeAnalysisUuidNotNullOnDuplicationsIndex.java new file mode 100644 index 00000000000..2de7e9615fb --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/MakeAnalysisUuidNotNullOnDuplicationsIndex.java @@ -0,0 +1,45 @@ +/* + * 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.AlterColumnsBuilder; +import org.sonar.db.version.DdlChange; + +import static org.sonar.db.version.VarcharColumnDef.UUID_VARCHAR_SIZE; +import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; + +public class MakeAnalysisUuidNotNullOnDuplicationsIndex extends DdlChange { + + private static final String TABLE_DUPLICATIONS_INDEX = "duplications_index"; + + public MakeAnalysisUuidNotNullOnDuplicationsIndex(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new AlterColumnsBuilder(getDatabase().getDialect(), TABLE_DUPLICATIONS_INDEX) + .updateColumn(newVarcharColumnDefBuilder().setColumnName("analysis_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build()) + .build()); + } + +} diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateAnalysisUuidOfDuplicationsIndex.java b/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateAnalysisUuidOfDuplicationsIndex.java new file mode 100644 index 00000000000..e3df430ee9b --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateAnalysisUuidOfDuplicationsIndex.java @@ -0,0 +1,56 @@ +/* + * 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 PopulateAnalysisUuidOfDuplicationsIndex extends BaseDataChange { + + public PopulateAnalysisUuidOfDuplicationsIndex(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select("select distinct di.project_snapshot_id, s.uuid from duplications_index di" + + " inner join snapshots s on s.id=di.project_snapshot_id" + + " where di.analysis_uuid is null"); + massUpdate.update("UPDATE duplications_index SET analysis_uuid=? WHERE project_snapshot_id=? and analysis_uuid is null"); + massUpdate.rowPluralName("analysis uuid of duplications_index entries"); + massUpdate.execute(PopulateAnalysisUuidOfDuplicationsIndex::handle); + } + + public static boolean handle(Select.Row row, SqlStatement update) throws SQLException { + long projectSnapshotId = row.getLong(1); + String snapshotUuid = row.getString(2); + + update.setString(1, snapshotUuid); + update.setLong(2, projectSnapshotId); + + 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 531951a2b32..e279cddd5cc 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 @@ -445,6 +445,12 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1235'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1236'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1237'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1238'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1239'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1240'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1241'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1242'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1243'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1244'); 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; diff --git a/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl b/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl index dbb4112b21f..b4148886def 100644 --- a/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl +++ b/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl @@ -185,8 +185,7 @@ CREATE TABLE "PROJECT_LINKS" ( CREATE TABLE "DUPLICATIONS_INDEX" ( "ID" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "PROJECT_SNAPSHOT_ID" INTEGER NOT NULL, - "SNAPSHOT_ID" INTEGER NOT NULL, + "ANALYSIS_UUID" VARCHAR(50) NOT NULL, "COMPONENT_UUID" VARCHAR(50) NOT NULL, "HASH" VARCHAR(50) NOT NULL, "INDEX_IN_FILE" INTEGER NOT NULL, @@ -549,7 +548,7 @@ CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES" ("USER_ID"); CREATE INDEX "DUPLICATIONS_INDEX_HASH" ON "DUPLICATIONS_INDEX" ("HASH"); -CREATE INDEX "DUPLICATIONS_INDEX_SID" ON "DUPLICATIONS_INDEX" ("SNAPSHOT_ID"); +CREATE INDEX "DUPLICATION_ANALYSIS_COMPONENT" ON "DUPLICATIONS_INDEX" ("ANALYSIS_UUID", "COMPONENT_UUID"); CREATE INDEX "INDEX_GROUPS_USERS_ON_GROUP_ID" ON "GROUPS_USERS" ("GROUP_ID"); diff --git a/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java b/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java index bb890273891..da5b4c20ed2 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java @@ -29,6 +29,6 @@ public class MigrationStepModuleTest { public void verify_count_of_added_MigrationStep_types() { ComponentContainer container = new ComponentContainer(); new MigrationStepModule().configure(container); - assertThat(container.size()).isEqualTo(97); + assertThat(container.size()).isEqualTo(102); } }