]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1330 Create table QPROFILE_EDIT_GROUPS
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 25 Sep 2017 12:17:32 +0000 (14:17 +0200)
committerStas Vilchik <stas.vilchik@sonarsource.com>
Mon, 2 Oct 2017 15:18:15 +0000 (17:18 +0200)
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/v66/CreateTableQProfileEditGroups.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/CreateTableQProfileEditGroupsTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66Test.java
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/CreateTableQProfileEditGroupsTest/empty.sql [new file with mode: 0644]

index 4b66621e4d06b2ffa1064bd5cdd06ae019fea354..f4ea81d864e0d514f5048876c4ae97a508bb9ace 100644 (file)
@@ -100,6 +100,17 @@ CREATE INDEX "QPROFILE_EDIT_USERS_QPROFILE" ON "QPROFILE_EDIT_USERS" ("QPROFILE_
 CREATE UNIQUE INDEX "QPROFILE_EDIT_USERS_UNIQUE" ON "QPROFILE_EDIT_USERS" ("USER_ID", "QPROFILE_UUID");
 
 
+CREATE TABLE "QPROFILE_EDIT_GROUPS" (
+  "UUID" VARCHAR(40) NOT NULL PRIMARY KEY,
+  "GROUP_ID" INTEGER NOT NULL,
+  "QPROFILE_UUID" VARCHAR(255) NOT NULL,
+  "CREATED_AT" BIGINT,
+);
+CREATE UNIQUE INDEX "PK_QPROFILE_EDIT_GROUPS" ON "QPROFILE_EDIT_GROUPS" ("UUID");
+CREATE INDEX "QPROFILE_EDIT_GROUPS_QPROFILE" ON "QPROFILE_EDIT_GROUPS" ("QPROFILE_UUID");
+CREATE UNIQUE INDEX "QPROFILE_EDIT_GROUPS_UNIQUE" ON "QPROFILE_EDIT_GROUPS" ("GROUP_ID", "QPROFILE_UUID");
+
+
 CREATE TABLE "GROUPS" (
   "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
   "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/CreateTableQProfileEditGroups.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/CreateTableQProfileEditGroups.java
new file mode 100644 (file)
index 0000000..f0ce346
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * 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.v66;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.IntegerColumnDef;
+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.sql.CreateTableBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
+
+public class CreateTableQProfileEditGroups extends DdlChange {
+
+  private static final String TABLE_NAME = "qprofile_edit_groups";
+
+  public CreateTableQProfileEditGroups(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    IntegerColumnDef groupColumn = IntegerColumnDef.newIntegerColumnDefBuilder()
+      .setColumnName("group_id")
+      .setIsNullable(false)
+      .build();
+    VarcharColumnDef qProfileUuidColumn = VarcharColumnDef.newVarcharColumnDefBuilder()
+      .setColumnName("qprofile_uuid")
+      .setIsNullable(false)
+      .setLimit(255)
+      .build();
+    context.execute(new CreateTableBuilder(getDialect(), TABLE_NAME)
+      .addPkColumn(VarcharColumnDef.newVarcharColumnDefBuilder()
+        .setColumnName("uuid")
+        .setIsNullable(false)
+        .setLimit(40)
+        .build())
+      .addColumn(groupColumn)
+      .addColumn(qProfileUuidColumn)
+      .addColumn(newBigIntegerColumnDefBuilder()
+        .setColumnName("created_at")
+        .setIsNullable(false)
+        .build())
+      .build()
+    );
+
+    context.execute(
+      new CreateIndexBuilder(getDialect())
+        .setTable(TABLE_NAME)
+        .setName(TABLE_NAME + "_qprofile")
+        .addColumn(qProfileUuidColumn)
+        .setUnique(false)
+        .build());
+    context.execute(
+      new CreateIndexBuilder(getDialect())
+        .setTable(TABLE_NAME)
+        .setName(TABLE_NAME + "_unique")
+        .addColumn(groupColumn)
+        .addColumn(qProfileUuidColumn)
+        .setUnique(true)
+        .build());
+  }
+}
index 2a5736a2d595e86da6b4d77f2dc9bab6fe7ef665..bc9c28859d1a01fba4ef09cdc39c151cdb035ba4 100644 (file)
@@ -38,6 +38,7 @@ public class DbVersion66 implements DbVersion {
       .add(1809, "Populate project_branches with existing main branches", PopulateMainProjectBranches.class)
       .add(1810, "Add ce_activity.error_type", AddErrorTypeColumnToCeActivityTable.class)
       .add(1811, "Create table qprofile_edit_users", CreateTableQProfileEditUsers.class)
+      .add(1812, "Create table qprofile_edit_groups", CreateTableQProfileEditGroups.class)
     ;
   }
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/CreateTableQProfileEditGroupsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/CreateTableQProfileEditGroupsTest.java
new file mode 100644 (file)
index 0000000..5640f47
--- /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.v66;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class CreateTableQProfileEditGroupsTest {
+
+  private static final String TABLE = "qprofile_edit_groups";
+
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(CreateTableQProfileEditGroupsTest.class, "empty.sql");
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private CreateTableQProfileEditGroups underTest = new CreateTableQProfileEditGroups(db.database());
+
+  @Test
+  public void creates_table_on_empty_db() throws SQLException {
+    underTest.execute();
+
+    assertThat(db.countRowsOfTable(TABLE)).isEqualTo(0);
+
+    db.assertColumnDefinition(TABLE, "uuid", Types.VARCHAR, 40, false);
+    db.assertColumnDefinition(TABLE, "group_id", Types.INTEGER, null, false);
+    db.assertColumnDefinition(TABLE, "qprofile_uuid", Types.VARCHAR, 255, false);
+    db.assertColumnDefinition(TABLE, "created_at", Types.BIGINT, null, false);
+    db.assertPrimaryKey(TABLE, "pk_" + TABLE, "uuid");
+    db.assertIndex(TABLE, "qprofile_edit_groups_qprofile", "qprofile_uuid");
+    db.assertUniqueIndex(TABLE, "qprofile_edit_groups_unique", "group_id", "qprofile_uuid");
+  }
+
+  @Test
+  public void migration_is_not_reentrant() throws SQLException {
+    underTest.execute();
+
+    expectedException.expect(IllegalStateException.class);
+
+    underTest.execute();
+  }
+
+}
index d12cb8ada986f9755859ce8323dc8ea7194c4260..d249593f897e21aebd449e879f67e8380bbb9341 100644 (file)
@@ -36,7 +36,7 @@ public class DbVersion66Test {
 
   @Test
   public void verify_migration_count() {
-    verifyMigrationCount(underTest, 11);
+    verifyMigrationCount(underTest, 12);
   }
 
 }
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/CreateTableQProfileEditGroupsTest/empty.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/CreateTableQProfileEditGroupsTest/empty.sql
new file mode 100644 (file)
index 0000000..e69de29