]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10965 Update Organizations#subscription not nullable
authorEric Hartmann <hartmann.eric@gmail.com>
Wed, 11 Jul 2018 09:56:03 +0000 (11:56 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 24 Jul 2018 07:31:49 +0000 (09:31 +0200)
Origami SMTP/inbox.ser [new file with mode: 0644]
server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
server/sonar-db-dao/src/main/java/org/sonar/db/organization/OrganizationDto.java
server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/user/GroupDaoTest.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v73/DbVersion73.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v73/SetSubscriptionOnOrganizationsNotNullable.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v73/DbVersion73Test.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v73/SetSubscriptionOnOrganizationsNotNullableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v73/SetSubscriptionOnOrganizationsNotNullableTest/organizations.sql [new file with mode: 0644]

diff --git a/Origami SMTP/inbox.ser b/Origami SMTP/inbox.ser
new file mode 100644 (file)
index 0000000..ae60bdf
Binary files /dev/null and b/Origami SMTP/inbox.ser differ
index 2285d106cca8f233a4a817bec3740a225b6504d9..b27bcb0117958cb95286f5ff8262ba54fb696c0d 100644 (file)
@@ -11,7 +11,7 @@ CREATE TABLE "ORGANIZATIONS" (
   "DEFAULT_GROUP_ID" INTEGER,
   "DEFAULT_QUALITY_GATE_UUID" VARCHAR(40) NOT NULL,
   "NEW_PROJECT_PRIVATE" BOOLEAN NOT NULL,
-  "SUBSCRIPTION" VARCHAR(40),
+  "SUBSCRIPTION" VARCHAR(40) NOT NULL,
   "CREATED_AT" BIGINT NOT NULL,
   "UPDATED_AT" BIGINT NOT NULL,
 
index 0df6a7cf819b82847133a2e9f72aa05cd1941137..1cfd7eeda66ce010f3034bd018247bbad6271b85 100644 (file)
@@ -48,7 +48,7 @@ public class OrganizationDto {
   private String key;
   /** Name, can't be null */
   private String name;
-  /** description can be null */
+  /** description can't be null */
   private String description;
   /** url can be null */
   private String url;
@@ -140,8 +140,7 @@ public class OrganizationDto {
   }
 
   public Subscription getSubscription() {
-    // TODO directly return subscription when column will be NOT NULLABLE (SONAR-10965)
-    return subscription == null ? Subscription.FREE : subscription;
+    return subscription;
   }
 
   public OrganizationDto setSubscription(Subscription subscription) {
index 385065ae96ae65156669b9f9618f5a9bbb5b02b6..9fa6d40161db17044cda73792bdc0739f11342d9 100644 (file)
@@ -83,6 +83,7 @@ public class OrganizationDaoTest {
     .setUrl("the url 1")
     .setAvatarUrl("the avatar url 1")
     .setGuarded(false)
+    .setSubscription(FREE)
     .setDefaultQualityGateUuid("1");
   private static final OrganizationDto ORGANIZATION_DTO_2 = new OrganizationDto()
     .setUuid("uuid 2")
@@ -92,6 +93,7 @@ public class OrganizationDaoTest {
     .setUrl("the url 2")
     .setAvatarUrl("the avatar url 2")
     .setGuarded(true)
+    .setSubscription(FREE)
     .setDefaultQualityGateUuid("1");
   private static final String PERMISSION_1 = "foo";
   private static final String PERMISSION_2 = "bar";
@@ -1315,6 +1317,7 @@ public class OrganizationDaoTest {
       .setDescription(organizationDto.getDescription())
       .setUrl(organizationDto.getUrl())
       .setDefaultQualityGateUuid(organizationDto.getDefaultQualityGateUuid())
+      .setSubscription(organizationDto.getSubscription())
       .setAvatarUrl(organizationDto.getAvatarUrl());
   }
 
index 661ed0a23b82e42c36d72820b6a95d4a51a98053..2606337e9ab6fd35aebff8ad543a3ced5d793439 100644 (file)
@@ -35,6 +35,7 @@ import static java.util.Arrays.asList;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
+import static org.sonar.db.organization.OrganizationDto.Subscription.SONARQUBE;
 import static org.sonar.db.user.GroupTesting.newGroupDto;
 
 public class GroupDaoTest {
@@ -45,6 +46,7 @@ public class GroupDaoTest {
     .setKey("an-org")
     .setName("An Org")
     .setDefaultQualityGateUuid("1")
+    .setSubscription(SONARQUBE)
     .setUuid("abcde");
 
   private System2 system2 = mock(System2.class);
index cf6e30fbe44bce7b0477277030abb9e38c436dec..dc159604ae3fc00cd10e88acd4a601da69003100 100644 (file)
@@ -38,6 +38,7 @@ public class DbVersion73 implements DbVersion {
       .add(2208, "Add rules.security_standards", AddSecurityStandardsToRules.class)
       .add(2209, "Fix missing quality profiles on organizations", FixMissingQualityProfilesOnOrganizations.class)
       .add(2210, "Add 'securityhotspotadmin' permission to templates characteristics already having 'issueadmin'", PopulateHotspotAdminPermissionOnTemplatesCharacteristics.class)
+      .add(2211, "Set SUBSCRIPTION not nullable in ORGANIZATIONS", SetSubscriptionOnOrganizationsNotNullable.class)
     ;
   }
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v73/SetSubscriptionOnOrganizationsNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v73/SetSubscriptionOnOrganizationsNotNullable.java
new file mode 100644 (file)
index 0000000..200a4e4
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info 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.server.platform.db.migration.version.v73;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.SupportsBlueGreen;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+@SupportsBlueGreen
+public class SetSubscriptionOnOrganizationsNotNullable extends DdlChange {
+
+  public SetSubscriptionOnOrganizationsNotNullable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AlterColumnsBuilder(getDialect(), "organizations")
+      .updateColumn(newVarcharColumnDefBuilder()
+        .setColumnName("subscription")
+        .setLimit(40)
+        .setIsNullable(false)
+        .build())
+      .build());
+  }
+}
index 3b3f4486ecdd9cbd67610839d3c57dc9a9e13487..056e97d85cfff518f2fcd6c79c4a27a90df0dff3 100644 (file)
@@ -35,6 +35,6 @@ public class DbVersion73Test {
 
   @Test
   public void verify_migration_count() {
-    verifyMigrationCount(underTest, 11);
+    verifyMigrationCount(underTest, 12);
   }
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v73/SetSubscriptionOnOrganizationsNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v73/SetSubscriptionOnOrganizationsNotNullableTest.java
new file mode 100644 (file)
index 0000000..ad3a147
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info 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.server.platform.db.migration.version.v73;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+import static java.sql.Types.VARCHAR;
+
+public class SetSubscriptionOnOrganizationsNotNullableTest {
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(SetSubscriptionOnOrganizationsNotNullableTest.class, "organizations.sql");
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private SetSubscriptionOnOrganizationsNotNullable underTest = new SetSubscriptionOnOrganizationsNotNullable(db.database());
+
+  @Test
+  public void column_is_added_to_table() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDefinition("organizations", "subscription", VARCHAR, 40, false);
+  }
+
+  @Test
+  public void migration_is_reentrant() throws SQLException {
+    underTest.execute();
+
+    underTest.execute();
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v73/SetSubscriptionOnOrganizationsNotNullableTest/organizations.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v73/SetSubscriptionOnOrganizationsNotNullableTest/organizations.sql
new file mode 100644 (file)
index 0000000..5e61511
--- /dev/null
@@ -0,0 +1,19 @@
+CREATE TABLE "ORGANIZATIONS" (
+  "UUID" VARCHAR(40) NOT NULL,
+  "KEE" VARCHAR(32) NOT NULL,
+  "NAME" VARCHAR(64) NOT NULL,
+  "DESCRIPTION" VARCHAR(256),
+  "URL" VARCHAR(256),
+  "AVATAR_URL" VARCHAR(256),
+  "GUARDED" BOOLEAN NOT NULL,
+  "DEFAULT_PERM_TEMPLATE_PROJECT" VARCHAR(40),
+  "DEFAULT_PERM_TEMPLATE_VIEW" VARCHAR(40),
+  "DEFAULT_GROUP_ID" INTEGER,
+  "DEFAULT_QUALITY_GATE_UUID" VARCHAR(40) NOT NULL,
+  "NEW_PROJECT_PRIVATE" BOOLEAN NOT NULL,
+  "CREATED_AT" BIGINT NOT NULL,
+  "UPDATED_AT" BIGINT NOT NULL,
+  "SUBSCRIPTION" VARCHAR(40),
+  CONSTRAINT "PK_ORGANIZATIONS" PRIMARY KEY ("UUID")
+);
+CREATE UNIQUE INDEX "ORGANIZATION_KEY" ON "ORGANIZATIONS" ("KEE");