]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19612 Remove deprecation notice on column
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>
Fri, 20 Oct 2023 14:21:34 +0000 (16:21 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 20 Oct 2023 20:02:41 +0000 (20:02 +0000)
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/CreateIndexBuilder.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/CreateUniqueIndexForScimGroupsUuid.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexForScmAccountOnScmAccountsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/CreateIndexOnExternalIdAndIdentityOnExternalGroupsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/CreateUniqueIndexForReportSchedulesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v101/CreateUniqueIndexForReportSubscriptionsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateUniqueConstraintOnIssuesImpacts.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateUniqueConstraintOnRulesDefaultImpacts.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/CreateIndexForRuleImpactChangesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/CreateUniqueIndexForGithubPermissionsMappingTable.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateIndexBuilderTest.java

index 6a37ec802b46b5314761d6bd24cb2d68ad5f1661..f9e405c14ff53e30fb878b6111cddeb0bc8d4175 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.server.platform.db.migration.sql;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Collectors;
+import javax.annotation.Nullable;
 import org.sonar.db.dialect.Dialect;
 import org.sonar.db.dialect.PostgreSql;
 import org.sonar.server.platform.db.migration.def.ColumnDef;
@@ -86,12 +87,10 @@ public class CreateIndexBuilder {
    * Add a column to the scope of index. Order of calls to this
    * method is important and is kept as-is when creating the index.
    *
-   * @deprecated use {@link CreateIndexBuilder#addColumn(String, boolean) instead}
    */
-  @Deprecated(since = "10.3")
   public CreateIndexBuilder addColumn(String column) {
     requireNonNull(column, COLUMN_CANNOT_BE_NULL);
-    columns.add(new NullableColumn(column, false));
+    columns.add(new NullableColumn(column, null));
     return this;
   }
 
@@ -104,10 +103,15 @@ public class CreateIndexBuilder {
   public List<String> build() {
     validateTableName(tableName);
     validateIndexName(indexName);
+    validateColumnsForUniqueIndex(unique, columns);
     checkArgument(!columns.isEmpty(), "at least one column must be specified");
     return singletonList(createSqlStatement());
   }
 
+  private static void validateColumnsForUniqueIndex(boolean unique, List<NullableColumn> columns) {
+    checkArgument(!unique || columns.stream().allMatch(c->c.isNullable() != null), "Nullability of column should be provided for unique indexes");
+  }
+
   /**
    *
    */
@@ -148,6 +152,6 @@ public class CreateIndexBuilder {
     return sql.toString();
   }
 
-  private record NullableColumn(String name, boolean isNullable) {
+  private record NullableColumn(String name, @Nullable Boolean isNullable) {
   }
 }
index e775f804d74d6eeb960c7480bec281de678b712f..58a90b605ba13588a035f2158698e42b0efb7f06 100644 (file)
@@ -53,7 +53,7 @@ public class CreateUniqueIndexForScimGroupsUuid extends DdlChange {
       context.execute(new CreateIndexBuilder(getDialect())
         .setTable(TABLE_NAME)
         .setName(INDEX_NAME)
-        .addColumn(COLUMN_NAME)
+        .addColumn(COLUMN_NAME, false)
         .setUnique(true)
         .build());
     }
index ff5f0eae03ebd1db9864cab5390d9297761418fd..8fc27f09ce4e08d5f4836807b32ed290164366d0 100644 (file)
@@ -51,7 +51,7 @@ class CreateIndexForScmAccountOnScmAccountsTable extends DdlChange {
       context.execute(new CreateIndexBuilder(getDialect())
         .setTable(SCM_ACCOUNTS_TABLE_NAME)
         .setName(INDEX_NAME)
-        .addColumn(SCM_ACCOUNT_COLUMN_NAME)
+        .addColumn(SCM_ACCOUNT_COLUMN_NAME, false)
         .setUnique(false)
         .build());
     }
index 8b69deea6756210dd020c86086a60ed158f8d43d..7a5dfe24c0dfa6ec1f5c96ab4eb46c981ea40cc6 100644 (file)
@@ -52,8 +52,8 @@ public class CreateIndexOnExternalIdAndIdentityOnExternalGroupsTable extends Ddl
       context.execute(new CreateIndexBuilder(getDialect())
         .setTable(TABLE_NAME)
         .setName(INDEX_NAME)
-        .addColumn(EXTERNAL_IDENTITY_PROVIDER_COLUMN_NAME)
-        .addColumn(EXTERNAL_GROUP_ID_COLUMN_NAME)
+        .addColumn(EXTERNAL_IDENTITY_PROVIDER_COLUMN_NAME, false)
+        .addColumn(EXTERNAL_GROUP_ID_COLUMN_NAME, false)
         .setUnique(true)
         .build());
     }
index e6af0edd465dbdc3f018c7f0feda00b34f8061bf..4dc43ff50c1ac02ca28e9c76889ae57f7224a61b 100644 (file)
@@ -57,8 +57,8 @@ public class CreateUniqueIndexForReportSchedulesTable extends DdlChange {
       context.execute(new CreateIndexBuilder(getDialect())
         .setTable(TABLE_NAME)
         .setName(INDEX_NAME)
-        .addColumn(COLUMN_NAME_PORTFOLIO)
-        .addColumn(COLUMN_NAME_BRANCH)
+        .addColumn(COLUMN_NAME_PORTFOLIO, true)
+        .addColumn(COLUMN_NAME_BRANCH, true)
         .setUnique(true)
         .build());
     }
index 945e6011a9e5f33ba97cabc9a9448e21dd36480a..53507bf50b83eae6019e0f79b81c2bd0debcb89e 100644 (file)
@@ -60,9 +60,9 @@ public class CreateUniqueIndexForReportSubscriptionsTable extends DdlChange {
       context.execute(new CreateIndexBuilder(getDialect())
         .setTable(TABLE_NAME)
         .setName(INDEX_NAME)
-        .addColumn(COLUMN_NAME_PORTFOLIO)
-        .addColumn(COLUMN_NAME_BRANCH)
-        .addColumn(COLUMN_NAME_USER)
+        .addColumn(COLUMN_NAME_PORTFOLIO, true)
+        .addColumn(COLUMN_NAME_BRANCH, true)
+        .addColumn(COLUMN_NAME_USER, false)
         .setUnique(true)
         .build());
     }
index ee0d8ff0e6971f7cd19c180f74829afc3c0a9902..fdf221f9b58745e059e27ebc8fda686a834116d9 100644 (file)
@@ -46,8 +46,8 @@ public class CreateUniqueConstraintOnIssuesImpacts extends DdlChange {
       context.execute(new CreateIndexBuilder(getDialect())
         .setTable(TABLE_NAME)
         .setName(INDEX_NAME)
-        .addColumn("issue_key")
-        .addColumn("software_quality")
+        .addColumn("issue_key", false)
+        .addColumn("software_quality", false)
         .setUnique(true)
         .build());
     }
index 659f837f236c98e71ca630e85c9c43275054446d..e851720f2f813373486f0c95f0c644c9c362a398 100644 (file)
@@ -46,8 +46,8 @@ public class CreateUniqueConstraintOnRulesDefaultImpacts extends DdlChange {
       context.execute(new CreateIndexBuilder(getDialect())
         .setTable(TABLE_NAME)
         .setName(INDEX_NAME)
-        .addColumn("rule_uuid")
-        .addColumn("software_quality")
+        .addColumn("rule_uuid", false)
+        .addColumn("software_quality", false)
         .setUnique(true)
         .build());
     }
index 7c87e4422ccf7a35e83425f0de7b97fff6e374f6..34bb3ce5eea0b32dbc480be88f975d02e971f765 100644 (file)
@@ -47,7 +47,7 @@ public class CreateIndexForRuleImpactChangesTable extends DdlChange {
       context.execute(new CreateIndexBuilder(getDialect())
         .setTable(TABLE_NAME)
         .setName(INDEX_NAME)
-        .addColumn("rule_change_uuid")
+        .addColumn("rule_change_uuid", false)
         .setUnique(false)
         .build());
     }
index 08927e73bcd5c28cac2c600e52f09195a4ca6679..9f10d439657f456c1878c09f5bb05717b4d05e3e 100644 (file)
@@ -52,8 +52,8 @@ public class CreateUniqueIndexForGithubPermissionsMappingTable extends DdlChange
       context.execute(new CreateIndexBuilder(getDialect())
         .setTable(GITHUB_PERMISSIONS_MAPPING_TABLE_NAME)
         .setName(INDEX_NAME)
-        .addColumn(GITHUB_ROLE_COLUMN)
-        .addColumn(SONARQUBE_PERMISSION_COLUMN)
+        .addColumn(GITHUB_ROLE_COLUMN, false)
+        .addColumn(SONARQUBE_PERMISSION_COLUMN, false)
         .setUnique(true)
         .build());
     }
index a04f538fd92edbe58f0ac26282456c221e3d834a..fbeb7be6e02d2387bb48749b25bd166c239cddea 100644 (file)
@@ -155,6 +155,20 @@ public class CreateIndexBuilderTest {
       .hasMessage("Index name can't be null");
   }
 
+  @Test
+  public void build_shouldThrowException_whenUniqueAndColumnNullabilityIsNotProvided() {
+    assertThatThrownBy(() -> {
+      new CreateIndexBuilder(new H2())
+        .setTable("issues")
+        .setName("name")
+        .addColumn("columnName")
+        .setUnique(true)
+        .build();
+    })
+      .isInstanceOf(IllegalArgumentException.class)
+      .hasMessage("Nullability of column should be provided for unique indexes");
+  }
+
   @Test
   public void throw_IAE_if_columns_are_missing() {
     assertThatThrownBy(() -> {