]> source.dussan.org Git - sonarqube.git/commitdiff
Fix for migration 2502
authorMichal Duda <michal.duda@sonarsource.com>
Mon, 14 Jan 2019 09:13:13 +0000 (10:13 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 16 Jan 2019 08:43:13 +0000 (09:43 +0100)
server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v76/MigrateModuleProperties.java

index abd132f330a3b812e35551bf0ffffffe8c75fd61..40ab818d93a3b3005d1a27ccab327f5bc505c86e 100644 (file)
       count(1)
     from projects p
     where
-      p.enabled = true
-      and p.project_uuid = #{projectUuid}
+      p.enabled=${_true}
+      and p.project_uuid = #{projectUuid,jdbcType=VARCHAR}
       and p.qualifier = 'BRC'
   </select>
 
index ae64c7f0d11c47a5a07c0d64440175a1fcea9874..cbcce2a5294553b2e6e09bbe7d94f532a3d6231a 100644 (file)
@@ -225,7 +225,7 @@ public class ComponentDaoTest {
     assertThat(underTest.selectByKeyAndBranch(dbSession, "unknown", "my_branch")).isNotPresent();
     assertThat(underTest.selectByKeyAndBranch(dbSession, file.getKey(), "unknown")).isNotPresent();
   }
-  
+
   @DataProvider
   public static Object[][] branchBranchTypes() {
     return new Object[][] {
@@ -444,6 +444,20 @@ public class ComponentDaoTest {
     underTest.selectComponentsByQualifiers(dbSession, Collections.emptySet());
   }
 
+  @Test
+  public void count_enabled_modules_by_project_uuid() {
+    ComponentDto project = db.components().insertPrivateProject();
+    ComponentDto module = db.components().insertComponent(newModuleDto(project));
+    db.components().insertComponent(newModuleDto(module));
+    ComponentDto subModule2 = newModuleDto(module);
+    subModule2.setEnabled(false);
+    db.components().insertComponent(subModule2);
+
+    int result = underTest.countEnabledModulesByProjectUuid(dbSession, project.uuid());
+
+    assertThat(result).isEqualTo(2);
+  }
+
   @Test
   public void find_sub_projects_by_component_keys() {
     ComponentDto project = db.components().insertPrivateProject();
@@ -547,8 +561,7 @@ public class ComponentDaoTest {
         module.uuid(),
         subModule.uuid(),
         directory.uuid(),
-        file.uuid()
-      );
+        file.uuid());
   }
 
   @Test
index 107edf24e604defd4c36d13f736a5ef7bdaf0f68..79fa960913c2e1e31dd0ebe06b9aa23cfd78c6c3 100644 (file)
@@ -53,12 +53,12 @@ public class MigrateModuleProperties extends DataChange {
     AtomicReference<Integer> currentProjectId = new AtomicReference<>();
     AtomicReference<String> currentModuleUuid = new AtomicReference<>();
 
-    context.prepareSelect("select prop.prop_key, prop.text_value, prop.clob_value, mod.name, mod.uuid, root.id as project_id, root.name as project_name " +
+    context.prepareSelect("select prop.prop_key, prop.text_value, prop.clob_value, module1.name, module1.uuid, root.id as project_id, root.name as project_name " +
       "from properties prop " +
-      "left join projects mod on mod.id = prop.resource_id " +
-      "left join projects root on root.uuid = mod.project_uuid " +
-      "where mod.qualifier = 'BRC' and prop.user_id is null " +
-      "order by root.uuid, mod.uuid, prop.prop_key")
+      "left join projects module1 on module1.id = prop.resource_id " +
+      "left join projects root on root.uuid = module1.project_uuid " +
+      "where module1.qualifier = 'BRC' and prop.user_id is null " +
+      "order by root.uuid, module1.uuid, prop.prop_key")
       .scroll(row -> {
         String propertyKey = row.getString(1);
         String propertyTextValue = row.getString(2);
@@ -114,8 +114,8 @@ public class MigrateModuleProperties extends DataChange {
     MassUpdate massUpdate = context.prepareMassUpdate().rowPluralName("module level properties");
     massUpdate.select("select prop.id as property_id " +
       "from properties prop " +
-      "left join projects mod on mod.id = prop.resource_id " +
-      "where mod.qualifier = 'BRC'");
+      "left join projects module1 on module1.id = prop.resource_id " +
+      "where module1.qualifier = 'BRC'");
     massUpdate.update("delete from properties where id=?");
     massUpdate.execute((row, update) -> {
       update.setInt(1, row.getInt(1));