]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10134 Make Make ORGANIZATIONS.DEFAULT_QUALITY_GATE_UUID not nullable
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 12 Dec 2017 09:55:47 +0000 (10:55 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 14 Dec 2017 16:03:35 +0000 (17:03 +0100)
server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/DbVersion70.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/SetDefaultQualityGateUuidAsNotNullableInOrganizations.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/DbVersion70Test.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/SetDefaultQualityGateUuidAsNotNullableInOrganizationsTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v70/SetDefaultQualityGateUuidAsNotNullableInOrganizationsTest/organizations.sql [new file with mode: 0644]

index a70eeaa3e1e79419f61fd90accd6fc7ba527385f..3b335d6ccd6e8a04d37729c444b685ba1992f9ba 100644 (file)
@@ -10,7 +10,7 @@ CREATE TABLE "ORGANIZATIONS" (
   "DEFAULT_PERM_TEMPLATE_PROJECT" VARCHAR(40),
   "DEFAULT_PERM_TEMPLATE_VIEW" VARCHAR(40),
   "DEFAULT_GROUP_ID" INTEGER,
-  "DEFAULT_QUALITY_GATE_UUID" VARCHAR(40), // TODO : NOT NULL
+  "DEFAULT_QUALITY_GATE_UUID" VARCHAR(40) NOT NULL,
   "NEW_PROJECT_PRIVATE" BOOLEAN NOT NULL,
   "CREATED_AT" BIGINT NOT NULL,
   "UPDATED_AT" BIGINT NOT NULL
index 1da53519c939b13e09afebaf2d475ec46e3c447f..7d355c5753c7cdaa9cbdef88536cb064eb8d98a0 100644 (file)
@@ -48,6 +48,7 @@ public class DbVersion70 implements DbVersion {
       .add(1918, "Populate default quality gate on organization", PopulateDefaultQualityGate.class)
       .add(1919, "Associate existing quality gates to default organization", AssociateQualityGatesToDefaultOrganization.class)
       .add(1920, "Delete 'sonar.qualitygate' setting at global level", DeleteGlobalSonarQualityGateSetting.class)
+      .add(1921, "Make ORGANIZATIONS.DEFAULT_QUALITY_GATE_UUID not nullable", SetDefaultQualityGateUuidAsNotNullableInOrganizations.class)
     ;
   }
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/SetDefaultQualityGateUuidAsNotNullableInOrganizations.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/SetDefaultQualityGateUuidAsNotNullableInOrganizations.java
new file mode 100644 (file)
index 0000000..8f2168c
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.v70;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+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;
+
+public class SetDefaultQualityGateUuidAsNotNullableInOrganizations extends DdlChange {
+
+  public SetDefaultQualityGateUuidAsNotNullableInOrganizations(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AlterColumnsBuilder(getDialect(), "organizations")
+      .updateColumn(newVarcharColumnDefBuilder()
+        .setColumnName("default_quality_gate_uuid")
+        .setIsNullable(false)
+        .setLimit(VarcharColumnDef.UUID_SIZE)
+        .build())
+      .build());
+  }
+}
index 628ce06a0dbc77fd6d068803288777973d52aae1..5fd33f8206a31f86c0c8bc6834ee1851ce7bc8a4 100644 (file)
@@ -35,7 +35,7 @@ public class DbVersion70Test {
 
   @Test
   public void verify_migration_count() {
-    verifyMigrationCount(underTest, 21);
+    verifyMigrationCount(underTest, 22);
   }
 
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/SetDefaultQualityGateUuidAsNotNullableInOrganizationsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/SetDefaultQualityGateUuidAsNotNullableInOrganizationsTest.java
new file mode 100644 (file)
index 0000000..dbc3f6a
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.v70;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static java.sql.Types.VARCHAR;
+
+public class SetDefaultQualityGateUuidAsNotNullableInOrganizationsTest {
+
+  @Rule
+  public final CoreDbTester dbTester = CoreDbTester.createForSchema(SetDefaultQualityGateUuidAsNotNullableInOrganizationsTest.class, "organizations.sql");
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private DdlChange underTest = new SetDefaultQualityGateUuidAsNotNullableInOrganizations(dbTester.database());
+
+  @Test
+  public void default_quality_gate_uuid_is_set_as_not_nullable() throws SQLException {
+    underTest.execute();
+
+    dbTester.assertColumnDefinition("organizations", "default_quality_gate_uuid", VARCHAR, 40, false);
+  }
+
+  @Test
+  public void migration_is_reentrant() throws SQLException {
+    underTest.execute();
+    dbTester.assertColumnDefinition("organizations", "default_quality_gate_uuid", VARCHAR, 40, false);
+
+    underTest.execute();
+    dbTester.assertColumnDefinition("organizations", "default_quality_gate_uuid", VARCHAR, 40, false);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v70/SetDefaultQualityGateUuidAsNotNullableInOrganizationsTest/organizations.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v70/SetDefaultQualityGateUuidAsNotNullableInOrganizationsTest/organizations.sql
new file mode 100644 (file)
index 0000000..161b7f8
--- /dev/null
@@ -0,0 +1,19 @@
+CREATE TABLE "ORGANIZATIONS" (
+  "UUID" VARCHAR(40) NOT NULL PRIMARY KEY,
+  "KEE" VARCHAR(32) NOT NULL,
+  "NAME" VARCHAR(64) NOT NULL,
+  "DESCRIPTION" VARCHAR(256),
+  "URL" VARCHAR(256),
+  "AVATAR_URL" VARCHAR(256),
+  "GUARDED" BOOLEAN NOT NULL,
+  "USER_ID" INTEGER,
+  "DEFAULT_PERM_TEMPLATE_PROJECT" VARCHAR(40),
+  "DEFAULT_PERM_TEMPLATE_VIEW" VARCHAR(40),
+  "DEFAULT_GROUP_ID" INTEGER,
+  "DEFAULT_QUALITY_GATE_UUID" VARCHAR(40),
+  "NEW_PROJECT_PRIVATE" BOOLEAN NOT NULL,
+  "CREATED_AT" BIGINT NOT NULL,
+  "UPDATED_AT" BIGINT NOT NULL
+);
+CREATE UNIQUE INDEX "PK_ORGANIZATIONS" ON "ORGANIZATIONS" ("UUID");
+CREATE UNIQUE INDEX "ORGANIZATION_KEY" ON "ORGANIZATIONS" ("KEE");