]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19783 add github_orgs_groups table
authorAurelien Poscia <aurelien.poscia@sonarsource.com>
Mon, 14 Aug 2023 08:11:31 +0000 (10:11 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 22 Aug 2023 20:03:04 +0000 (20:03 +0000)
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateGithubOrganizationsGroupsTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateGithubOrganizationsGroupsTableTest.java [new file with mode: 0644]

index 4646bf41591704f46b0877956c9d05d1672d11cb..bb2b29411021f2122ea6e43b35ef8aa9f1c27357 100644 (file)
@@ -351,6 +351,12 @@ CREATE UNIQUE INDEX "FILE_SOURCES_FILE_UUID" ON "FILE_SOURCES"("FILE_UUID" NULLS
 CREATE INDEX "FILE_SOURCES_PROJECT_UUID" ON "FILE_SOURCES"("PROJECT_UUID" NULLS FIRST);
 CREATE INDEX "FILE_SOURCES_UPDATED_AT" ON "FILE_SOURCES"("UPDATED_AT" NULLS FIRST);
 
+CREATE TABLE "GITHUB_ORGS_GROUPS"(
+    "GROUP_UUID" CHARACTER VARYING(40) NOT NULL,
+    "ORGANIZATION_NAME" CHARACTER VARYING(100) NOT NULL
+);
+ALTER TABLE "GITHUB_ORGS_GROUPS" ADD CONSTRAINT "PK_GITHUB_ORGS_GROUPS" PRIMARY KEY("GROUP_UUID");
+
 CREATE TABLE "GROUP_ROLES"(
     "UUID" CHARACTER VARYING(40) NOT NULL,
     "ROLE" CHARACTER VARYING(64) NOT NULL,
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateGithubOrganizationsGroupsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateGithubOrganizationsGroupsTable.java
new file mode 100644 (file)
index 0000000..4a6fd4b
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.v102;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.CreateTableBuilder;
+import org.sonar.server.platform.db.migration.step.CreateTableChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class CreateGithubOrganizationsGroupsTable extends CreateTableChange {
+  @VisibleForTesting
+  static final String TABLE_NAME = "github_orgs_groups";
+  @VisibleForTesting
+  static final String GROUP_UUID_COLUMN_NAME = "group_uuid";
+  @VisibleForTesting
+  static final String ORGANIZATION_COLUMN_NAME = "organization_name";
+
+  public CreateGithubOrganizationsGroupsTable(Database db) {
+    super(db, TABLE_NAME);
+  }
+
+  @Override
+  public void execute(Context context, String tableName) throws SQLException {
+    context.execute(new CreateTableBuilder(getDialect(), tableName)
+      .addPkColumn(newVarcharColumnDefBuilder().setColumnName(GROUP_UUID_COLUMN_NAME).setIsNullable(false).setLimit(UUID_SIZE).build())
+      .addColumn(newVarcharColumnDefBuilder().setColumnName(ORGANIZATION_COLUMN_NAME).setIsNullable(false).setLimit(100).build())
+      .build());
+  }
+}
index 9bcbd45fb20c09f560df91800efc5062492b6271..7446ce9558cec126c5f971503274fa79fb01f5d5 100644 (file)
@@ -96,6 +96,8 @@ public class DbVersion102 implements DbVersion {
       .add(10_2_038, "Create 'issues_impacts' table", CreateIssueImpactsTable.class)
       .add(10_2_039, "Create unique constraint index on 'issues_impacts' table", CreateUniqueConstraintOnIssuesImpacts.class)
       .add(10_2_040, "Populate default impacts for existing rules", PopulateDefaultImpactsInRules.class)
-      .add(10_2_041, "Fix sqale_index metric description in 'metrics' table", FixSqaleIndexMetricDescription.class);
+      .add(10_2_041, "Fix sqale_index metric description in 'metrics' table", FixSqaleIndexMetricDescription.class)
+
+      .add(10_2_042, "Create table 'github_orgs_groups'", CreateGithubOrganizationsGroupsTable.class);
   }
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateGithubOrganizationsGroupsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateGithubOrganizationsGroupsTableTest.java
new file mode 100644 (file)
index 0000000..dc44a59
--- /dev/null
@@ -0,0 +1,43 @@
+package org.sonar.server.platform.db.migration.version.v102;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
+import static org.sonar.server.platform.db.migration.version.v102.CreateGithubOrganizationsGroupsTable.GROUP_UUID_COLUMN_NAME;
+import static org.sonar.server.platform.db.migration.version.v102.CreateGithubOrganizationsGroupsTable.ORGANIZATION_COLUMN_NAME;
+import static org.sonar.server.platform.db.migration.version.v102.CreateGithubOrganizationsGroupsTable.TABLE_NAME;
+
+public class CreateGithubOrganizationsGroupsTableTest {
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createEmpty();
+
+  private final DdlChange createGithubOrganizationsGroupsTable = new CreateGithubOrganizationsGroupsTable(db.database());
+
+  @Test
+  public void migration_should_create_a_table() throws SQLException {
+    db.assertTableDoesNotExist(TABLE_NAME);
+
+    createGithubOrganizationsGroupsTable.execute();
+
+    db.assertTableExists(TABLE_NAME);
+    db.assertColumnDefinition(TABLE_NAME, GROUP_UUID_COLUMN_NAME, Types.VARCHAR, UUID_SIZE, false);
+    db.assertColumnDefinition(TABLE_NAME, ORGANIZATION_COLUMN_NAME, Types.VARCHAR, 100, false);
+    db.assertPrimaryKey(TABLE_NAME, "pk_github_orgs_groups", GROUP_UUID_COLUMN_NAME);
+  }
+
+  @Test
+  public void migration_should_be_reentrant() throws SQLException {
+    db.assertTableDoesNotExist(TABLE_NAME);
+
+    createGithubOrganizationsGroupsTable.execute();
+    // re-entrant
+    createGithubOrganizationsGroupsTable.execute();
+
+    db.assertTableExists(TABLE_NAME);
+  }
+}