aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-migration
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2017-12-12 10:55:47 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2017-12-14 17:03:35 +0100
commitc70a0d972d892d61b7a0f2279402779cf15fa0ed (patch)
treed4eb5b06492c97f379906e077320cd42d2006682 /server/sonar-db-migration
parent2d2b4dcc3718bf994c2b5b72cbb6531da051ec4e (diff)
downloadsonarqube-c70a0d972d892d61b7a0f2279402779cf15fa0ed.tar.gz
sonarqube-c70a0d972d892d61b7a0f2279402779cf15fa0ed.zip
SONAR-10134 Make Make ORGANIZATIONS.DEFAULT_QUALITY_GATE_UUID not nullable
Diffstat (limited to 'server/sonar-db-migration')
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/DbVersion70.java1
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/SetDefaultQualityGateUuidAsNotNullableInOrganizations.java47
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/DbVersion70Test.java2
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/SetDefaultQualityGateUuidAsNotNullableInOrganizationsTest.java58
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v70/SetDefaultQualityGateUuidAsNotNullableInOrganizationsTest/organizations.sql19
5 files changed, 126 insertions, 1 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/DbVersion70.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/DbVersion70.java
index 1da53519c93..7d355c5753c 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/DbVersion70.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/DbVersion70.java
@@ -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
index 00000000000..8f2168c730e
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/SetDefaultQualityGateUuidAsNotNullableInOrganizations.java
@@ -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());
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/DbVersion70Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/DbVersion70Test.java
index 628ce06a0db..5fd33f8206a 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/DbVersion70Test.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/DbVersion70Test.java
@@ -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
index 00000000000..dbc3f6a4d13
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/SetDefaultQualityGateUuidAsNotNullableInOrganizationsTest.java
@@ -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
index 00000000000..161b7f8e71c
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v70/SetDefaultQualityGateUuidAsNotNullableInOrganizationsTest/organizations.sql
@@ -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");