aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-migration
diff options
context:
space:
mode:
authorAurelien Poscia <aurelien.poscia@sonarsource.com>2023-08-14 10:11:31 +0200
committersonartech <sonartech@sonarsource.com>2023-08-22 20:03:04 +0000
commit1aa7ae3a18bcb2413792cf75be725d7c3d0851ca (patch)
tree6bba7f2a1cb9e4e8705b561850789069fdc06f5d /server/sonar-db-migration
parent7d665c2c36a19375e4e10056f1281371d9bf7c19 (diff)
downloadsonarqube-1aa7ae3a18bcb2413792cf75be725d7c3d0851ca.tar.gz
sonarqube-1aa7ae3a18bcb2413792cf75be725d7c3d0851ca.zip
SONAR-19783 add github_orgs_groups table
Diffstat (limited to 'server/sonar-db-migration')
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateGithubOrganizationsGroupsTable.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java4
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateGithubOrganizationsGroupsTableTest.java43
3 files changed, 96 insertions, 1 deletions
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
index 00000000000..4a6fd4b04cb
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/CreateGithubOrganizationsGroupsTable.java
@@ -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());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java
index 9bcbd45fb20..7446ce9558c 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java
@@ -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
index 00000000000..dc44a594654
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/CreateGithubOrganizationsGroupsTableTest.java
@@ -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);
+ }
+}