]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9328 make MANUAL_MEASURE.COMPONENT_UUID not nullable 2131/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 31 May 2017 14:33:46 +0000 (16:33 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 1 Jun 2017 13:20:08 +0000 (15:20 +0200)
12 files changed:
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/v65/DbVersion65.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DropIndexManualMeasuresComponentUuid.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/MakeManualMeasuresComponentUuidNotNullable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/RecreateIndexManualMeasuresComponentUuid.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DropIndexManualMeasuresComponentUuidTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/MakeManualMeasuresComponentUuidNotNullableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/RecreateIndexManualMeasuresComponentUuidTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/DropIndexManualMeasuresComponentUuidTest/manual_measures.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/MakeManualMeasuresComponentUuidNotNullableTest/manual_measures.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/RecreateIndexManualMeasuresComponentUuidTest/manual_measures.sql [new file with mode: 0644]

index 2e487af0391243ae4bfd53f9c067fb4b0019e575..47fb0608e382ccd7d1e34a881d345c8f22fc8a7c 100644 (file)
@@ -323,7 +323,7 @@ CREATE INDEX "PROJECTS_QUALIFIER" ON "PROJECTS" ("QUALIFIER");
 CREATE TABLE "MANUAL_MEASURES" (
   "ID" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
   "METRIC_ID" INTEGER NOT NULL,
-  "COMPONENT_UUID" VARCHAR(50),
+  "COMPONENT_UUID" VARCHAR(50) NOT NULL,
   "VALUE" DOUBLE,
   "TEXT_VALUE" VARCHAR(4000),
   "USER_LOGIN" VARCHAR(255),
index b75a7d1eceea4e4b55641b50d6931bf05793a554..601b8c10a566d6d5e69ef982a2cf5151ae4573a5 100644 (file)
@@ -37,6 +37,10 @@ public class DbVersion65 implements DbVersion {
       .add(1707, "Ensure ISSUE.PROJECT_UUID is consistent", EnsureIssueProjectUuidConsistencyOnIssues.class)
       .add(1708, "Clean orphans from PROJECT_LINKS", CleanOrphanRowsInProjectLinks.class)
       .add(1709, "Clean orphans from SETTINGS", CleanOrphanRowsInProperties.class)
-      .add(1710, "Clean orphans from MANUAL_MEASURES", CleanOrphanRowsInManualMeasures.class);
+      .add(1710, "Clean orphans from MANUAL_MEASURES", CleanOrphanRowsInManualMeasures.class)
+      .add(1711, "Drop index MANUAL_MEASURES.COMPONENT_UUID", DropIndexManualMeasuresComponentUuid.class)
+      .add(1712, "Make MANUAL_MEASURES.COMPONENT_UUID not nullable", MakeManualMeasuresComponentUuidNotNullable.class)
+      .add(1713, "Recreate index MANUAL_MEASURES.COMPONENT_UUID", RecreateIndexManualMeasuresComponentUuid.class)
+    ;
   }
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DropIndexManualMeasuresComponentUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DropIndexManualMeasuresComponentUuid.java
new file mode 100644 (file)
index 0000000..7fda3fd
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * 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.v65;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropIndexManualMeasuresComponentUuid extends DdlChange {
+
+  public DropIndexManualMeasuresComponentUuid(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new DropIndexBuilder(getDialect())
+      .setTable("manual_measures")
+      .setName("manual_measures_component_uuid")
+      .build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/MakeManualMeasuresComponentUuidNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/MakeManualMeasuresComponentUuidNotNullable.java
new file mode 100644 (file)
index 0000000..243bd96
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * 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.v65;
+
+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 MakeManualMeasuresComponentUuidNotNullable extends DdlChange {
+
+  public MakeManualMeasuresComponentUuidNotNullable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(DdlChange.Context context) throws SQLException {
+    context.execute(new AlterColumnsBuilder(getDialect(), "manual_measures")
+      .updateColumn(newVarcharColumnDefBuilder()
+        .setColumnName("component_uuid")
+        .setLimit(VarcharColumnDef.UUID_VARCHAR_SIZE)
+        .setIsNullable(false)
+        .build())
+      .build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/RecreateIndexManualMeasuresComponentUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/RecreateIndexManualMeasuresComponentUuid.java
new file mode 100644 (file)
index 0000000..aedfd45
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * 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.v65;
+
+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.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class RecreateIndexManualMeasuresComponentUuid extends DdlChange {
+
+  public RecreateIndexManualMeasuresComponentUuid(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new CreateIndexBuilder(getDialect())
+      .setTable("manual_measures")
+      .setName("manual_measures_component_uuid")
+      .setUnique(false)
+      .addColumn(newVarcharColumnDefBuilder()
+        .setColumnName("component_uuid")
+        .setLimit(VarcharColumnDef.UUID_VARCHAR_SIZE)
+        .setIsNullable(false)
+        .build())
+      .build());
+  }
+}
index 1b5327a0b6874e06b23ef081916ebdca734acf1f..eafd9346c20b88bff153a9acb2ba78f5b4699485 100644 (file)
@@ -35,6 +35,6 @@ public class DbVersion65Test {
 
   @Test
   public void verify_migration_count() {
-    verifyMigrationCount(underTest, 11);
+    verifyMigrationCount(underTest, 14);
   }
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DropIndexManualMeasuresComponentUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DropIndexManualMeasuresComponentUuidTest.java
new file mode 100644 (file)
index 0000000..c37a423
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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.v65;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class DropIndexManualMeasuresComponentUuidTest {
+  private static final String TABLE_MANUAL_MEASURES = "manual_measures";
+  private static final String INDEX_MANUAL_MEASURES_COMPONENT_UUID = "manual_measures_component_uuid";
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(DropIndexManualMeasuresComponentUuidTest.class, "manual_measures.sql");
+
+  private DropIndexManualMeasuresComponentUuid underTest = new DropIndexManualMeasuresComponentUuid(db.database());
+
+  @Test
+  public void execute_drops_index_EVENTS_COMPONENT_UUID() throws SQLException {
+    db.assertIndex(TABLE_MANUAL_MEASURES, INDEX_MANUAL_MEASURES_COMPONENT_UUID, "component_uuid");
+
+    underTest.execute();
+
+    db.assertIndexDoesNotExist(TABLE_MANUAL_MEASURES, INDEX_MANUAL_MEASURES_COMPONENT_UUID);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/MakeManualMeasuresComponentUuidNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/MakeManualMeasuresComponentUuidNotNullableTest.java
new file mode 100644 (file)
index 0000000..c2028c9
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * 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.v65;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.Random;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
+
+public class MakeManualMeasuresComponentUuidNotNullableTest {
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(MakeManualMeasuresComponentUuidNotNullableTest.class, "manual_measures.sql");
+
+  private final Random random = new Random();
+  private MakeManualMeasuresComponentUuidNotNullable underTest = new MakeManualMeasuresComponentUuidNotNullable(db.database());
+
+  @Test
+  public void execute_makes_column_component_uuid_not_nullable_on_empty_table() throws SQLException {
+    underTest.execute();
+
+    verifyColumn();
+  }
+
+  @Test
+  public void execute_makes_column_component_uuid_not_nullable_on_populated_table() throws SQLException {
+    insertManualMeasure();
+    insertManualMeasure();
+    insertManualMeasure();
+
+    underTest.execute();
+
+    verifyColumn();
+  }
+
+  private void verifyColumn() {
+    db.assertColumnDefinition("manual_measures", "component_uuid", Types.VARCHAR, 50, false);
+  }
+
+  private void insertManualMeasure() {
+    db.executeInsert(
+      "manual_measures",
+      "METRIC_ID", random.nextInt(),
+      "COMPONENT_UUID", randomAlphabetic(5));
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/RecreateIndexManualMeasuresComponentUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/RecreateIndexManualMeasuresComponentUuidTest.java
new file mode 100644 (file)
index 0000000..d19998d
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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.v65;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class RecreateIndexManualMeasuresComponentUuidTest {
+  private static final String TABLE_MANUAL_MEASURES = "manual_measures";
+  private static final String INDEX_MANUAL_MEASURES_COMPONENT_UUID = "manual_measures_component_uuid";
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(RecreateIndexManualMeasuresComponentUuidTest.class, "manual_measures.sql");
+
+  private RecreateIndexManualMeasuresComponentUuid underTest = new RecreateIndexManualMeasuresComponentUuid(db.database());
+
+  @Test
+  public void execute_adds_index_EVENTS_COMPONENT_UUID() throws SQLException {
+    db.assertIndexDoesNotExist(TABLE_MANUAL_MEASURES, INDEX_MANUAL_MEASURES_COMPONENT_UUID);
+
+    underTest.execute();
+
+    db.assertIndex(TABLE_MANUAL_MEASURES, INDEX_MANUAL_MEASURES_COMPONENT_UUID, "component_uuid");
+  }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/DropIndexManualMeasuresComponentUuidTest/manual_measures.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/DropIndexManualMeasuresComponentUuidTest/manual_measures.sql
new file mode 100644 (file)
index 0000000..c9ca78e
--- /dev/null
@@ -0,0 +1,12 @@
+CREATE TABLE "MANUAL_MEASURES" (
+  "ID" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "METRIC_ID" INTEGER NOT NULL,
+  "COMPONENT_UUID" VARCHAR(50),
+  "VALUE" DOUBLE,
+  "TEXT_VALUE" VARCHAR(4000),
+  "USER_LOGIN" VARCHAR(255),
+  "DESCRIPTION" VARCHAR(4000),
+  "CREATED_AT" BIGINT,
+  "UPDATED_AT" BIGINT
+);
+CREATE INDEX "MANUAL_MEASURES_COMPONENT_UUID" ON "MANUAL_MEASURES" ("COMPONENT_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/MakeManualMeasuresComponentUuidNotNullableTest/manual_measures.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/MakeManualMeasuresComponentUuidNotNullableTest/manual_measures.sql
new file mode 100644 (file)
index 0000000..a719be5
--- /dev/null
@@ -0,0 +1,11 @@
+CREATE TABLE "MANUAL_MEASURES" (
+  "ID" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "METRIC_ID" INTEGER NOT NULL,
+  "COMPONENT_UUID" VARCHAR(50),
+  "VALUE" DOUBLE,
+  "TEXT_VALUE" VARCHAR(4000),
+  "USER_LOGIN" VARCHAR(255),
+  "DESCRIPTION" VARCHAR(4000),
+  "CREATED_AT" BIGINT,
+  "UPDATED_AT" BIGINT
+);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/RecreateIndexManualMeasuresComponentUuidTest/manual_measures.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/RecreateIndexManualMeasuresComponentUuidTest/manual_measures.sql
new file mode 100644 (file)
index 0000000..a719be5
--- /dev/null
@@ -0,0 +1,11 @@
+CREATE TABLE "MANUAL_MEASURES" (
+  "ID" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "METRIC_ID" INTEGER NOT NULL,
+  "COMPONENT_UUID" VARCHAR(50),
+  "VALUE" DOUBLE,
+  "TEXT_VALUE" VARCHAR(4000),
+  "USER_LOGIN" VARCHAR(255),
+  "DESCRIPTION" VARCHAR(4000),
+  "CREATED_AT" BIGINT,
+  "UPDATED_AT" BIGINT
+);