From 50d0c1cabba9c9f30779ca122d4d8e69b8e1e8b8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Mon, 11 Jul 2016 11:50:52 +0200 Subject: [PATCH] SONAR-7786 merge PROJECTS table clean migrations and do them earlier --- ...1221_clean_some_data_in_table_projects.rb} | 3 +- ...b => 1222_add_uuid_columns_to_projects.rb} | 0 ...1223_populate_uuid_columns_of_projects.rb} | 0 ... => 1224_clean_orphan_rows_in_projects.rb} | 0 ...drop_index_projects_uuid_from_projects.rb} | 0 ...make_uuid_columns_not_null_on_projects.rb} | 0 ...eate_index_projects_uuid_from_projects.rb} | 0 ...p_index_projects_root_id_from_projects.rb} | 0 ... => 1229_drop_id_columns_from_projects.rb} | 0 ...b => 1230_add_uuid_column_to_snapshots.rb} | 0 ...1231_populate_uuid_column_on_snapshots.rb} | 0 ...make_uuid_column_not_null_on_snapshots.rb} | 0 ..._add_unique_index_on_uuid_of_snapshots.rb} | 0 ...dd_analysis_uuid_column_to_ce_activity.rb} | 0 ...te_analysis_uuid_column_on_ce_activity.rb} | 0 ...op_snapshot_id_column_from_ce_activity.rb} | 0 ...nd_analysis_uuid_to_duplications_index.rb} | 0 ...nd_analysis_uuid_of_duplications_index.rb} | 0 ...dex_rows_without_component_or_analysis.rb} | 0 ...is_uuid_not_null_on_duplications_index.rb} | 0 .../1269_clean_usurper_root_components.rb | 29 ------- .../v60/CleanUsurperRootComponents.java | 17 ++-- .../FixProjectUuidOfDeveloperProjects.java | 11 ++- .../v60/CleanUsurperRootComponentsTest.java | 83 ++++++++++--------- ...FixProjectUuidOfDeveloperProjectsTest.java | 20 +++-- .../complete_schema.sql | 38 ++++----- ...progress_projects.sql => projects_5.6.sql} | 9 +- 27 files changed, 92 insertions(+), 118 deletions(-) rename server/sonar-web/src/main/webapp/WEB-INF/db/migrate/{1255_fix_project_uuid_of_developer_projects.rb => 1221_clean_some_data_in_table_projects.rb} (87%) rename server/sonar-web/src/main/webapp/WEB-INF/db/migrate/{1221_add_uuid_columns_to_projects.rb => 1222_add_uuid_columns_to_projects.rb} (100%) rename server/sonar-web/src/main/webapp/WEB-INF/db/migrate/{1222_populate_uuid_columns_of_projects.rb => 1223_populate_uuid_columns_of_projects.rb} (100%) rename server/sonar-web/src/main/webapp/WEB-INF/db/migrate/{1223_clean_orphan_rows_in_projects.rb => 1224_clean_orphan_rows_in_projects.rb} (100%) rename server/sonar-web/src/main/webapp/WEB-INF/db/migrate/{1224_drop_index_projects_uuid_from_projects.rb => 1225_drop_index_projects_uuid_from_projects.rb} (100%) rename server/sonar-web/src/main/webapp/WEB-INF/db/migrate/{1225_make_uuid_columns_not_null_on_projects.rb => 1226_make_uuid_columns_not_null_on_projects.rb} (100%) rename server/sonar-web/src/main/webapp/WEB-INF/db/migrate/{1226_recreate_index_projects_uuid_from_projects.rb => 1227_recreate_index_projects_uuid_from_projects.rb} (100%) rename server/sonar-web/src/main/webapp/WEB-INF/db/migrate/{1227_drop_index_projects_root_id_from_projects.rb => 1228_drop_index_projects_root_id_from_projects.rb} (100%) rename server/sonar-web/src/main/webapp/WEB-INF/db/migrate/{1228_drop_id_columns_from_projects.rb => 1229_drop_id_columns_from_projects.rb} (100%) rename server/sonar-web/src/main/webapp/WEB-INF/db/migrate/{1229_add_uuid_column_to_snapshots.rb => 1230_add_uuid_column_to_snapshots.rb} (100%) rename server/sonar-web/src/main/webapp/WEB-INF/db/migrate/{1230_populate_uuid_column_on_snapshots.rb => 1231_populate_uuid_column_on_snapshots.rb} (100%) rename server/sonar-web/src/main/webapp/WEB-INF/db/migrate/{1231_make_uuid_column_not_null_on_snapshots.rb => 1232_make_uuid_column_not_null_on_snapshots.rb} (100%) rename server/sonar-web/src/main/webapp/WEB-INF/db/migrate/{1232_add_unique_index_on_uuid_of_snapshots.rb => 1233_add_unique_index_on_uuid_of_snapshots.rb} (100%) rename server/sonar-web/src/main/webapp/WEB-INF/db/migrate/{1233_add_analysis_uuid_column_to_ce_activity.rb => 1234_add_analysis_uuid_column_to_ce_activity.rb} (100%) rename server/sonar-web/src/main/webapp/WEB-INF/db/migrate/{1234_populate_analysis_uuid_column_on_ce_activity.rb => 1235_populate_analysis_uuid_column_on_ce_activity.rb} (100%) rename server/sonar-web/src/main/webapp/WEB-INF/db/migrate/{1235_drop_snapshot_id_column_from_ce_activity.rb => 1236_drop_snapshot_id_column_from_ce_activity.rb} (100%) rename server/sonar-web/src/main/webapp/WEB-INF/db/migrate/{1236_add_component_uuid_and_analysis_uuid_to_duplications_index.rb => 1237_add_component_uuid_and_analysis_uuid_to_duplications_index.rb} (100%) rename server/sonar-web/src/main/webapp/WEB-INF/db/migrate/{1237_populate_component_uuid_and_analysis_uuid_of_duplications_index.rb => 1238_populate_component_uuid_and_analysis_uuid_of_duplications_index.rb} (100%) rename server/sonar-web/src/main/webapp/WEB-INF/db/migrate/{1238_delete_orphan_duplications_index_rows_without_component_or_analysis.rb => 1239_delete_orphan_duplications_index_rows_without_component_or_analysis.rb} (100%) rename server/sonar-web/src/main/webapp/WEB-INF/db/migrate/{1239_make_component_uuid_and_analysis_uuid_not_null_on_duplications_index.rb => 1240_make_component_uuid_and_analysis_uuid_not_null_on_duplications_index.rb} (100%) delete mode 100644 server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1269_clean_usurper_root_components.rb rename sonar-db/src/test/resources/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjectsTest/{in_progress_projects.sql => projects_5.6.sql} (80%) diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1255_fix_project_uuid_of_developer_projects.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1221_clean_some_data_in_table_projects.rb similarity index 87% rename from server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1255_fix_project_uuid_of_developer_projects.rb rename to server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1221_clean_some_data_in_table_projects.rb index 38cf8c1a960..092e14726fb 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1255_fix_project_uuid_of_developer_projects.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1221_clean_some_data_in_table_projects.rb @@ -21,9 +21,10 @@ # # SonarQube 6.0 # -class FixProjectUuidOfDeveloperProjects < ActiveRecord::Migration +class CleanSomeDataInTableProjects < ActiveRecord::Migration def self.up execute_java_migration('org.sonar.db.version.v60.FixProjectUuidOfDeveloperProjects') + execute_java_migration('org.sonar.db.version.v60.CleanUsurperRootComponents') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1221_add_uuid_columns_to_projects.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1222_add_uuid_columns_to_projects.rb similarity index 100% rename from server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1221_add_uuid_columns_to_projects.rb rename to server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1222_add_uuid_columns_to_projects.rb diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1222_populate_uuid_columns_of_projects.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1223_populate_uuid_columns_of_projects.rb similarity index 100% rename from server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1222_populate_uuid_columns_of_projects.rb rename to server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1223_populate_uuid_columns_of_projects.rb diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1223_clean_orphan_rows_in_projects.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1224_clean_orphan_rows_in_projects.rb similarity index 100% rename from server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1223_clean_orphan_rows_in_projects.rb rename to server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1224_clean_orphan_rows_in_projects.rb diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1224_drop_index_projects_uuid_from_projects.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1225_drop_index_projects_uuid_from_projects.rb similarity index 100% rename from server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1224_drop_index_projects_uuid_from_projects.rb rename to server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1225_drop_index_projects_uuid_from_projects.rb diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1225_make_uuid_columns_not_null_on_projects.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1226_make_uuid_columns_not_null_on_projects.rb similarity index 100% rename from server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1225_make_uuid_columns_not_null_on_projects.rb rename to server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1226_make_uuid_columns_not_null_on_projects.rb diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1226_recreate_index_projects_uuid_from_projects.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1227_recreate_index_projects_uuid_from_projects.rb similarity index 100% rename from server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1226_recreate_index_projects_uuid_from_projects.rb rename to server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1227_recreate_index_projects_uuid_from_projects.rb diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1227_drop_index_projects_root_id_from_projects.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1228_drop_index_projects_root_id_from_projects.rb similarity index 100% rename from server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1227_drop_index_projects_root_id_from_projects.rb rename to server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1228_drop_index_projects_root_id_from_projects.rb diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1228_drop_id_columns_from_projects.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1229_drop_id_columns_from_projects.rb similarity index 100% rename from server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1228_drop_id_columns_from_projects.rb rename to server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1229_drop_id_columns_from_projects.rb diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1229_add_uuid_column_to_snapshots.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1230_add_uuid_column_to_snapshots.rb similarity index 100% rename from server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1229_add_uuid_column_to_snapshots.rb rename to server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1230_add_uuid_column_to_snapshots.rb diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1230_populate_uuid_column_on_snapshots.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1231_populate_uuid_column_on_snapshots.rb similarity index 100% rename from server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1230_populate_uuid_column_on_snapshots.rb rename to server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1231_populate_uuid_column_on_snapshots.rb diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1231_make_uuid_column_not_null_on_snapshots.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1232_make_uuid_column_not_null_on_snapshots.rb similarity index 100% rename from server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1231_make_uuid_column_not_null_on_snapshots.rb rename to server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1232_make_uuid_column_not_null_on_snapshots.rb diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1232_add_unique_index_on_uuid_of_snapshots.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1233_add_unique_index_on_uuid_of_snapshots.rb similarity index 100% rename from server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1232_add_unique_index_on_uuid_of_snapshots.rb rename to server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1233_add_unique_index_on_uuid_of_snapshots.rb diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1233_add_analysis_uuid_column_to_ce_activity.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1234_add_analysis_uuid_column_to_ce_activity.rb similarity index 100% rename from server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1233_add_analysis_uuid_column_to_ce_activity.rb rename to server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1234_add_analysis_uuid_column_to_ce_activity.rb diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1234_populate_analysis_uuid_column_on_ce_activity.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1235_populate_analysis_uuid_column_on_ce_activity.rb similarity index 100% rename from server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1234_populate_analysis_uuid_column_on_ce_activity.rb rename to server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1235_populate_analysis_uuid_column_on_ce_activity.rb diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1235_drop_snapshot_id_column_from_ce_activity.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1236_drop_snapshot_id_column_from_ce_activity.rb similarity index 100% rename from server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1235_drop_snapshot_id_column_from_ce_activity.rb rename to server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1236_drop_snapshot_id_column_from_ce_activity.rb diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1236_add_component_uuid_and_analysis_uuid_to_duplications_index.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1237_add_component_uuid_and_analysis_uuid_to_duplications_index.rb similarity index 100% rename from server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1236_add_component_uuid_and_analysis_uuid_to_duplications_index.rb rename to server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1237_add_component_uuid_and_analysis_uuid_to_duplications_index.rb diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1237_populate_component_uuid_and_analysis_uuid_of_duplications_index.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1238_populate_component_uuid_and_analysis_uuid_of_duplications_index.rb similarity index 100% rename from server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1237_populate_component_uuid_and_analysis_uuid_of_duplications_index.rb rename to server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1238_populate_component_uuid_and_analysis_uuid_of_duplications_index.rb diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1238_delete_orphan_duplications_index_rows_without_component_or_analysis.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1239_delete_orphan_duplications_index_rows_without_component_or_analysis.rb similarity index 100% rename from server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1238_delete_orphan_duplications_index_rows_without_component_or_analysis.rb rename to server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1239_delete_orphan_duplications_index_rows_without_component_or_analysis.rb diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1239_make_component_uuid_and_analysis_uuid_not_null_on_duplications_index.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1240_make_component_uuid_and_analysis_uuid_not_null_on_duplications_index.rb similarity index 100% rename from server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1239_make_component_uuid_and_analysis_uuid_not_null_on_duplications_index.rb rename to server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1240_make_component_uuid_and_analysis_uuid_not_null_on_duplications_index.rb diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1269_clean_usurper_root_components.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1269_clean_usurper_root_components.rb deleted file mode 100644 index f77ee059214..00000000000 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1269_clean_usurper_root_components.rb +++ /dev/null @@ -1,29 +0,0 @@ -# -# 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 CleanUsurperRootComponents < ActiveRecord::Migration - - def self.up - execute_java_migration('org.sonar.db.version.v60.CleanUsurperRootComponents') - end -end diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/CleanUsurperRootComponents.java b/sonar-db/src/main/java/org/sonar/db/version/v60/CleanUsurperRootComponents.java index 742168e9945..b300d047f21 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v60/CleanUsurperRootComponents.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/CleanUsurperRootComponents.java @@ -73,7 +73,7 @@ public class CleanUsurperRootComponents extends BaseDataChange { " p.scope = 'PRJ'" + " and p.qualifier in ('TRK', 'VW', 'DEV')" + " )"); - massUpdate.update("delete from duplications_index where component_uuid=?"); + massUpdate.update("delete from duplications_index where snapshot_id in (select id from snapshots where component_uuid=?)"); massUpdate.update("delete from project_measures where component_uuid=?"); massUpdate.update("delete from ce_activity where component_uuid=?"); massUpdate.update("delete from events where component_uuid=?"); @@ -122,7 +122,7 @@ public class CleanUsurperRootComponents extends BaseDataChange { private void cleanSnapshotWithIncorrectRoot(Context context) throws SQLException { MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select("select" + - " sn.uuid,sn.id" + + " sn.id" + " from " + " projects p, snapshots sn" + " where" + @@ -131,22 +131,19 @@ public class CleanUsurperRootComponents extends BaseDataChange { " p.scope = 'PRJ'" + " and p.qualifier in ('TRK', 'VW', 'DEV')" + " )"); - massUpdate.update("DELETE from duplications_index WHERE analysis_uuid=?"); - massUpdate.update("DELETE from project_measures WHERE analysis_uuid=?"); - massUpdate.update("DELETE from ce_activity WHERE analysis_uuid=?"); - massUpdate.update("DELETE from events WHERE analysis_uuid=?"); + massUpdate.update("DELETE from ce_activity WHERE snapshot_id=?"); + massUpdate.update("DELETE from events WHERE snapshot_id=?"); + massUpdate.update("DELETE from project_measures WHERE snapshot_id=?"); + massUpdate.update("DELETE from duplications_index WHERE project_snapshot_id=?"); massUpdate.update("DELETE from snapshots WHERE id=?"); massUpdate.rowPluralName("snapshots with incorrect root"); massUpdate.execute((row, update, updateIndex) -> { - String analysisUuid = row.getString(1); - long snapshotId = row.getLong(2); + long snapshotId = row.getLong(1); switch (updateIndex) { case 0: case 1: case 2: case 3: - update.setString(1, analysisUuid); - return true; case 4: update.setLong(1, snapshotId); return true; diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjects.java b/sonar-db/src/main/java/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjects.java index 2952a9fa5ff..334e66d796e 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjects.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjects.java @@ -35,15 +35,18 @@ public class FixProjectUuidOfDeveloperProjects extends BaseDataChange { @Override public void execute(Context context) throws SQLException { MassUpdate massUpdate = context.prepareMassUpdate(); - massUpdate.select("select distinct developer_uuid from projects where qualifier = 'DEV_PRJ' and project_uuid != developer_uuid"); - massUpdate.update("update projects set project_uuid = developer_uuid where developer_uuid = ? and qualifier = 'DEV_PRJ' and project_uuid != developer_uuid"); - massUpdate.rowPluralName("developers in project"); + massUpdate.select("select distinct p.person_id,d.uuid from projects p, projects d where p.qualifier = 'DEV_PRJ' and p.project_uuid != d.uuid and d.id = p.person_id"); + massUpdate.update("update projects set project_uuid = ? where person_id = ? and qualifier = 'DEV_PRJ' and project_uuid != ?"); + massUpdate.rowPluralName("developers with incorrect project_uuid"); massUpdate.execute(FixProjectUuidOfDeveloperProjects::handleComponent); } private static boolean handleComponent(Select.Row row, SqlStatement update) throws SQLException { - String developerUuid = row.getString(1); + long personId = row.getLong(1); + String developerUuid = row.getString(2); update.setString(1, developerUuid); + update.setLong(2, personId); + update.setString(3, developerUuid); return true; } diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/CleanUsurperRootComponentsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/CleanUsurperRootComponentsTest.java index 6e54187085f..4a22d6a2f8a 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/v60/CleanUsurperRootComponentsTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/CleanUsurperRootComponentsTest.java @@ -62,7 +62,7 @@ public class CleanUsurperRootComponentsTest { insertComponent("sc3", "qu3"), insertComponent("sc4", "qu4") }; - String[] snapshotUuids = { + Long[] snapshotIds = { insertSnapshot(componentUuids[0], "sc1", "qu1"), insertSnapshot(componentUuids[1], "sc2", "quW"), insertSnapshot(componentUuids[2], "scX", "qu3"), @@ -71,10 +71,10 @@ public class CleanUsurperRootComponentsTest { underTest.execute(); - assertSnapshot(snapshotUuids[0], "sc1", "qu1"); - assertSnapshot(snapshotUuids[1], "sc2", "qu2"); - assertSnapshot(snapshotUuids[2], "sc3", "qu3"); - assertSnapshot(snapshotUuids[3], "sc4", "qu4"); + assertSnapshot(snapshotIds[0], "sc1", "qu1"); + assertSnapshot(snapshotIds[1], "sc2", "qu2"); + assertSnapshot(snapshotIds[2], "sc3", "qu3"); + assertSnapshot(snapshotIds[3], "sc4", "qu4"); } @Test @@ -101,13 +101,13 @@ public class CleanUsurperRootComponentsTest { long usurperId = 12L; String usurperUuid = "usurper_uuid"; insertComponent(Scopes.PROJECT, Qualifiers.MODULE, usurperId, usurperUuid, usurperUuid); - insertDuplicationsIndex(usurperUuid); - insertProjectMeasures(usurperUuid, dontCare()); - insertCeActivity(usurperUuid, dontCare()); - insertEvent(usurperUuid, dontCare()); + Long snapshotId = insertSnapshot(usurperUuid, usurperUuid); + insertDuplicationsIndex(snapshotId); + insertProjectMeasures(usurperUuid, dontCareLong()); + insertCeActivity(usurperUuid, dontCareLong()); + insertEvent(usurperUuid, dontCareLong()); insertSnapshot(usurperUuid, dontCare()); insertSnapshot(dontCare(), usurperUuid); - insertSnapshot(usurperUuid, usurperUuid); insertProjectLinks(usurperUuid); insertIssue(usurperUuid, null); insertIssue(null, usurperUuid); @@ -142,7 +142,7 @@ public class CleanUsurperRootComponentsTest { insertComponent(Scopes.PROJECT, "DEV"), insertComponent(Scopes.PROJECT, "DEV_PRJ"), }; - String[] snapshotUuids = { + Long[] snapshotIds = { insertSnapshot(dontCare(), componentUuids[0]), insertSnapshot(dontCare(), componentUuids[1]), insertSnapshot(dontCare(), componentUuids[2]), @@ -156,16 +156,16 @@ public class CleanUsurperRootComponentsTest { underTest.execute(); - assertUuidsInTableProjects("snapshots", snapshotUuids[0], snapshotUuids[4], snapshotUuids[7]); + assertIdsInTableProjects("snapshots", snapshotIds[0], snapshotIds[4], snapshotIds[7]); } @Test public void execute_deletes_children_tables_of_snapshots_when_root_of_snapshot_is_not_root() throws SQLException { String componentUuid = insertComponent(Scopes.FILE, Scopes.FILE); - String snapshotUuid = insertSnapshot(dontCare(), componentUuid); - insertProjectMeasures(dontCare(), snapshotUuid); - insertCeActivity(componentUuid, snapshotUuid); - insertEvent(componentUuid, snapshotUuid); + Long snapshotId = insertSnapshot(dontCare(), componentUuid); + insertProjectMeasures(dontCare(), snapshotId); + insertCeActivity(componentUuid, snapshotId); + insertEvent(componentUuid, snapshotId); underTest.execute(); @@ -174,11 +174,11 @@ public class CleanUsurperRootComponentsTest { .forEach(s -> assertThat(db.countRowsOfTable(s)).describedAs("table " + s).isEqualTo(0)); } - private void insertDuplicationsIndex(String componentUuid) { + private void insertDuplicationsIndex(Long snapshotId) { db.executeInsert( "duplications_index", - "COMPONENT_UUID", componentUuid, - "ANALYSIS_UUID", dontCare(), + "PROJECT_SNAPSHOT_ID", valueOf(dontCareLong()), + "SNAPSHOT_ID", valueOf(snapshotId), "HASH", dontCare(), "INDEX_IN_FILE", valueOf(0), "START_LINE", valueOf(0), @@ -186,22 +186,22 @@ public class CleanUsurperRootComponentsTest { db.commit(); } - private void insertProjectMeasures(String componentUuid, String analysisUuid) { + private void insertProjectMeasures(String componentUuid, Long snapshotId) { db.executeInsert( "project_measures", "METRIC_ID", valueOf(123L), "COMPONENT_UUID", componentUuid, - "ANALYSIS_UUID", analysisUuid); + "SNAPSHOT_ID", valueOf(snapshotId)); db.commit(); } - private void insertCeActivity(String componentUuid, String analysisUuid) { + private void insertCeActivity(String componentUuid, Long snapshotId) { db.executeInsert( "ce_activity", "UUID", dontCare(), "TASK_TYPE", dontCare(), "COMPONENT_UUID", componentUuid, - "ANALYSIS_UUID", analysisUuid, + "SNAPSHOT_ID", valueOf(snapshotId), "STATUS", dontCare(), "IS_LAST", "true", "IS_LAST_KEY", dontCare(), @@ -211,25 +211,25 @@ public class CleanUsurperRootComponentsTest { db.commit(); } - private void insertEvent(String componentUuid, String analysisUuid) { + private void insertEvent(String componentUuid, Long snapshotId) { db.executeInsert( "events", - "ANALYSIS_UUID", analysisUuid, + "SNAPSHOT_ID", valueOf(snapshotId), "COMPONENT_UUID", componentUuid, "CREATED_AT", valueOf(122L), "EVENT_DATE", valueOf(123L)); db.commit(); } - private String insertSnapshot(String componentUuid, String rootComponentUuid) { - String uuid = "uuid_" + idGenerator++; + private Long insertSnapshot(String componentUuid, String rootComponentUuid) { + Long id = idGenerator++; db.executeInsert( "snapshots", - "UUID", uuid, + "ID", valueOf(id), "COMPONENT_UUID", componentUuid, "ROOT_COMPONENT_UUID", rootComponentUuid); db.commit(); - return uuid; + return id; } private void insertProjectLinks(String componentUuid) { @@ -311,39 +311,42 @@ public class CleanUsurperRootComponentsTest { "projects", "ID", valueOf(id), "UUID", uuid, - "ROOT_UUID", dontCare(), "PROJECT_UUID", projectUuid, - "UUID_PATH", dontCare(), "SCOPE", scope, "QUALIFIER", qualifier); db.commit(); return uuid; } - private String insertSnapshot(String componentUuid, String scope, String qualifier) { + private Long insertSnapshot(String componentUuid, String scope, String qualifier) { long id = idGenerator++; - String uuid = "uuid_" + id; db.executeInsert( "snapshots", - "ID", valueOf(id), - "UUID", uuid, + "id", valueOf(id), "component_uuid", componentUuid, "root_component_uuid", dontCare(), "scope", scope, "qualifier", qualifier); db.commit(); - return uuid; + return id; } - private void assertSnapshot(String snapshotUuid, String scope, String qualifier) { - List> rows = db.select("select SCOPE, QUALIFIER from snapshots where UUID='" + snapshotUuid + "'"); + private void assertSnapshot(Long snapshotId, String scope, String qualifier) { + List> rows = db.select("select SCOPE, QUALIFIER from snapshots where ID=" + snapshotId); assertThat(rows).hasSize(1); Map row = rows.get(0); assertThat(row.get("SCOPE")).isEqualTo(scope); assertThat(row.get("QUALIFIER")).isEqualTo(qualifier); } + private void assertIdsInTableProjects(String tableName, Long... expected) { + assertThat(db.select("select id from " + tableName) + .stream() + .map(stringObjectMap -> (Long) stringObjectMap.entrySet().iterator().next().getValue())) + .containsOnly(expected); + } + private void assertUuidsInTableProjects(String tableName, String... expected) { assertThat(db.select("select uuid from " + tableName) .stream() @@ -356,4 +359,8 @@ public class CleanUsurperRootComponentsTest { private String dontCare() { return "DC_" + dontCareGenerator++; } + + private Long dontCareLong() { + return dontCareGenerator++; + } } diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjectsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjectsTest.java index ea09dcc0838..bdb58a3ba3f 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjectsTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjectsTest.java @@ -27,6 +27,7 @@ import org.junit.Test; import org.sonar.api.utils.System2; import org.sonar.db.DbTester; +import static java.lang.String.valueOf; import static org.assertj.core.api.Assertions.assertThat; public class FixProjectUuidOfDeveloperProjectsTest { @@ -40,7 +41,7 @@ public class FixProjectUuidOfDeveloperProjectsTest { @Rule public DbTester db = DbTester.createForSchema(System2.INSTANCE, FixProjectUuidOfDeveloperProjectsTest.class, - "in_progress_projects.sql"); + "projects_5.6.sql"); private FixProjectUuidOfDeveloperProjects underTest = new FixProjectUuidOfDeveloperProjects(db.database()); @@ -84,9 +85,9 @@ public class FixProjectUuidOfDeveloperProjectsTest { insert(PROJECT_UUID, "TRK", null, PROJECT_UUID); insert(FILE_UUID, "FIL", null, PROJECT_UUID); // developer - insert(DEVELOPER_UUID, "DEV", DEVELOPER_UUID, DEVELOPER_UUID); - insert(DEV1_IN_PROJECT_UUID, "DEV_PRJ", DEVELOPER_UUID, /* not correct */PROJECT_UUID); - insert(DEV2_IN_PROJECT_UUID, "DEV_PRJ", DEVELOPER_UUID, /* not correct */PROJECT_UUID); + Long personId = insert(DEVELOPER_UUID, "DEV", null, DEVELOPER_UUID); + insert(DEV1_IN_PROJECT_UUID, "DEV_PRJ", personId, /* not correct */PROJECT_UUID); + insert(DEV2_IN_PROJECT_UUID, "DEV_PRJ", personId, /* not correct */PROJECT_UUID); db.commit(); } @@ -95,14 +96,17 @@ public class FixProjectUuidOfDeveloperProjectsTest { assertThat(rows.get("projectUuid")).isEqualTo(expectedProjectUuid); } - private String insert(String uuid, String qualifier, @Nullable String developerUuid, String projectUuid) { + private Long insert(String uuid, String qualifier, @Nullable Long personId, String projectUuid) { db.executeInsert( TABLE_PROJECTS, "UUID", uuid, - "DEVELOPER_UUID", developerUuid, + "PERSON_ID", personId == null ? null : valueOf(personId), "PROJECT_UUID", projectUuid, - "ROOT_UUID", "NOT_USED", "QUALIFIER", qualifier); - return uuid; + db.commit(); + return db.select("select ID from projects where UUID='" + uuid + "'").stream() + .findFirst() + .map(f -> (Long) f.get("ID")) + .orElseThrow(() -> new IllegalStateException("NO ID??")); } } diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v60/CleanUsurperRootComponentsTest/complete_schema.sql b/sonar-db/src/test/resources/org/sonar/db/version/v60/CleanUsurperRootComponentsTest/complete_schema.sql index 3706047e5ab..299da292538 100644 --- a/sonar-db/src/test/resources/org/sonar/db/version/v60/CleanUsurperRootComponentsTest/complete_schema.sql +++ b/sonar-db/src/test/resources/org/sonar/db/version/v60/CleanUsurperRootComponentsTest/complete_schema.sql @@ -21,9 +21,7 @@ CREATE TABLE "RULES_PROFILES" ( "RULES_UPDATED_AT" VARCHAR(100), "IS_DEFAULT" BOOLEAN NOT NULL DEFAULT FALSE, "CREATED_AT" TIMESTAMP, - "UPDATED_AT" TIMESTAMP, - "LAST_USED" BIGINT, - "USER_UPDATED_AT" BIGINT + "UPDATED_AT" TIMESTAMP ); CREATE TABLE "PROJECT_QPROFILES" ( @@ -56,7 +54,6 @@ CREATE TABLE "GROUPS" ( CREATE TABLE "SNAPSHOTS" ( "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "UUID" VARCHAR(50) NOT NULL, "CREATED_AT" BIGINT, "BUILD_DATE" BIGINT, "COMPONENT_UUID" VARCHAR(50) NOT NULL, @@ -141,8 +138,8 @@ CREATE TABLE "WIDGET_PROPERTIES" ( CREATE TABLE "EVENTS" ( "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "NAME" VARCHAR(400), - "ANALYSIS_UUID" VARCHAR(50) NOT NULL, "COMPONENT_UUID" VARCHAR(50), + "SNAPSHOT_ID" INTEGER, "CATEGORY" VARCHAR(50), "EVENT_DATE" BIGINT NOT NULL, "CREATED_AT" BIGINT NOT NULL, @@ -187,8 +184,8 @@ CREATE TABLE "PROJECT_LINKS" ( CREATE TABLE "DUPLICATIONS_INDEX" ( "ID" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "ANALYSIS_UUID" VARCHAR(50) NOT NULL, - "COMPONENT_UUID" VARCHAR(50) NOT NULL, + "PROJECT_SNAPSHOT_ID" INTEGER NOT NULL, + "SNAPSHOT_ID" INTEGER NOT NULL, "HASH" VARCHAR(50) NOT NULL, "INDEX_IN_FILE" INTEGER NOT NULL, "START_LINE" INTEGER NOT NULL, @@ -200,7 +197,6 @@ CREATE TABLE "PROJECT_MEASURES" ( "VALUE" DOUBLE, "METRIC_ID" INTEGER NOT NULL, "COMPONENT_UUID" VARCHAR(50) NOT NULL, - "ANALYSIS_UUID" VARCHAR(50) NOT NULL, "SNAPSHOT_ID" INTEGER, "TEXT_VALUE" VARCHAR(4000), "ALERT_STATUS" VARCHAR(5), @@ -218,9 +214,8 @@ CREATE TABLE "PROJECT_MEASURES" ( CREATE TABLE "PROJECTS" ( "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "KEE" VARCHAR(400), - "UUID" VARCHAR(50) NOT NULL, - "UUID_PATH" VARCHAR(4000) NOT NULL, - "ROOT_UUID" VARCHAR(50) NOT NULL, + "ROOT_ID" INTEGER, + "UUID" VARCHAR(50), "PROJECT_UUID" VARCHAR(50), "MODULE_UUID" VARCHAR(50), "MODULE_UUID_PATH" VARCHAR(4000), @@ -232,9 +227,9 @@ CREATE TABLE "PROJECTS" ( "DEPRECATED_KEE" VARCHAR(400), "PATH" VARCHAR(2000), "LANGUAGE" VARCHAR(20), - "COPY_COMPONENT_UUID" VARCHAR(50), + "COPY_RESOURCE_ID" INTEGER, "LONG_NAME" VARCHAR(2000), - "DEVELOPER_UUID" VARCHAR(50), + "PERSON_ID" INTEGER, "CREATED_AT" TIMESTAMP, "AUTHORIZATION_UPDATED_AT" BIGINT ); @@ -478,7 +473,6 @@ CREATE TABLE "PERM_TEMPLATES_GROUPS" ( CREATE TABLE "ACTIVITIES" ( "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "LOG_KEY" VARCHAR(250), - "PROFILE_KEY" VARCHAR(255) NOT NULL, "CREATED_AT" TIMESTAMP, "USER_LOGIN" VARCHAR(255), "LOG_TYPE" VARCHAR(250), @@ -518,7 +512,7 @@ CREATE TABLE "CE_ACTIVITY" ( "UUID" VARCHAR(40) NOT NULL, "TASK_TYPE" VARCHAR(15) NOT NULL, "COMPONENT_UUID" VARCHAR(40) NULL, - "ANALYSIS_UUID" VARCHAR(50) NULL, + "SNAPSHOT_ID" INTEGER NULL, "STATUS" VARCHAR(15) NOT NULL, "IS_LAST" BOOLEAN NOT NULL, "IS_LAST_KEY" VARCHAR(55) NOT NULL, @@ -553,7 +547,7 @@ CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES" ("USER_ID"); CREATE INDEX "DUPLICATIONS_INDEX_HASH" ON "DUPLICATIONS_INDEX" ("HASH"); -CREATE INDEX "DUPLICATION_ANALYSIS_COMPONENT" ON "DUPLICATIONS_INDEX" ("ANALYSIS_UUID", "COMPONENT_UUID"); +CREATE INDEX "DUPLICATIONS_INDEX_SID" ON "DUPLICATIONS_INDEX" ("SNAPSHOT_ID"); CREATE INDEX "INDEX_GROUPS_USERS_ON_GROUP_ID" ON "GROUPS_USERS" ("GROUP_ID"); @@ -565,11 +559,9 @@ CREATE INDEX "MEASURES_SID_METRIC" ON "PROJECT_MEASURES" ("SNAPSHOT_ID", "METRIC CREATE INDEX "MEASURES_PERSON" ON "PROJECT_MEASURES" ("PERSON_ID"); -CREATE INDEX "MEASURES_COMPONENT_UUID" ON "PROJECT_MEASURES" ("COMPONENT_UUID"); - CREATE UNIQUE INDEX "METRICS_UNIQUE_NAME" ON "METRICS" ("NAME"); -CREATE INDEX "EVENTS_ANALYSIS" ON "EVENTS" ("ANALYSIS_UUID"); +CREATE INDEX "EVENTS_SNAPSHOT_ID" ON "EVENTS" ("SNAPSHOT_ID"); CREATE INDEX "EVENTS_COMPONENT_UUID" ON "EVENTS" ("COMPONENT_UUID"); @@ -585,10 +577,6 @@ CREATE INDEX "SNAPSHOTS_PARENT" ON "SNAPSHOTS" ("PARENT_SNAPSHOT_ID"); CREATE INDEX "SNAPSHOT_COMPONENT" ON "SNAPSHOTS" ("COMPONENT_UUID"); -CREATE UNIQUE INDEX "ANALYSES_UUID" ON "SNAPSHOTS" ("UUID"); - -CREATE INDEX "SNAPSHOTS_ROOT_COMPONENT" ON "SNAPSHOTS" ("ROOT_COMPONENT_UUID"); - CREATE INDEX "RULES_PARAMETERS_RULE_ID" ON "RULES_PARAMETERS" ("RULE_ID"); CREATE INDEX "ACTIVE_DASHBOARDS_DASHBOARDID" ON "ACTIVE_DASHBOARDS" ("DASHBOARD_ID"); @@ -605,7 +593,7 @@ CREATE INDEX "MANUAL_MEASURES_COMPONENT_UUID" ON "MANUAL_MEASURES" ("COMPONENT_U CREATE UNIQUE INDEX "PROJECTS_KEE" ON "PROJECTS" ("KEE"); -CREATE INDEX "PROJECTS_ROOT_UUID" ON "PROJECTS" ("ROOT_UUID"); +CREATE INDEX "PROJECTS_ROOT_ID" ON "PROJECTS" ("ROOT_ID"); CREATE UNIQUE INDEX "PROJECTS_UUID" ON "PROJECTS" ("UUID"); @@ -653,6 +641,8 @@ CREATE UNIQUE INDEX "USERS_LOGIN" ON "USERS" ("LOGIN"); CREATE INDEX "USERS_UPDATED_AT" ON "USERS" ("UPDATED_AT"); +CREATE INDEX "SNAPSHOTS_ROOT_COMPONENT" ON "SNAPSHOTS" ("ROOT_COMPONENT_UUID"); + CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES" ("GROUP_ID", "RESOURCE_ID", "ROLE"); CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES" ("PLUGIN_NAME", "PLUGIN_RULE_KEY"); diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjectsTest/in_progress_projects.sql b/sonar-db/src/test/resources/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjectsTest/projects_5.6.sql similarity index 80% rename from sonar-db/src/test/resources/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjectsTest/in_progress_projects.sql rename to sonar-db/src/test/resources/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjectsTest/projects_5.6.sql index 760728a8dc3..d051017969b 100644 --- a/sonar-db/src/test/resources/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjectsTest/in_progress_projects.sql +++ b/sonar-db/src/test/resources/org/sonar/db/version/v60/FixProjectUuidOfDeveloperProjectsTest/projects_5.6.sql @@ -1,8 +1,8 @@ CREATE TABLE "PROJECTS" ( "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "KEE" VARCHAR(400), - "UUID" VARCHAR(50) NOT NULL, - "ROOT_UUID" VARCHAR(50) NOT NULL, + "ROOT_ID" INTEGER, + "UUID" VARCHAR(50), "PROJECT_UUID" VARCHAR(50), "MODULE_UUID" VARCHAR(50), "MODULE_UUID_PATH" VARCHAR(4000), @@ -14,9 +14,10 @@ CREATE TABLE "PROJECTS" ( "DEPRECATED_KEE" VARCHAR(400), "PATH" VARCHAR(2000), "LANGUAGE" VARCHAR(20), - "COPY_COMPONENT_UUID" VARCHAR(50), + "COPY_RESOURCE_ID" INTEGER, "LONG_NAME" VARCHAR(2000), - "DEVELOPER_UUID" VARCHAR(50), + "PERSON_ID" INTEGER, "CREATED_AT" TIMESTAMP, "AUTHORIZATION_UPDATED_AT" BIGINT ); + -- 2.39.5