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,
--- /dev/null
+/*
+ * 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());
+ }
+}
.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);
}
}
--- /dev/null
+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);
+ }
+}