diff options
author | Steve Marion <steve.marion@sonarsource.com> | 2025-02-28 17:32:52 +0100 |
---|---|---|
committer | Matteo Mara <matteo.mara@sonarsource.com> | 2025-03-17 22:23:55 +0100 |
commit | 78b095acfe3e7bbefb3e950afe9dbf894f1f7df7 (patch) | |
tree | 9e970c4671daaa0dd7d4d8e3082b1a5084c799fa /server | |
parent | a087eb237d62b3280f1fc5d3540b1b57afccd4bd (diff) | |
download | sonarqube-78b095acfe3e7bbefb3e950afe9dbf894f1f7df7.tar.gz sonarqube-78b095acfe3e7bbefb3e950afe9dbf894f1f7df7.zip |
SONAR-24514 add architecture_graphs table.
Diffstat (limited to 'server')
4 files changed, 120 insertions, 1 deletions
diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl index 304e086bcac..7121ffb05f8 100644 --- a/server/sonar-db-dao/src/schema/schema-sq.ddl +++ b/server/sonar-db-dao/src/schema/schema-sq.ddl @@ -118,6 +118,15 @@ CREATE UNIQUE NULLS NOT DISTINCT INDEX "UNIQ_APP_PROJECTS" ON "APP_PROJECTS"("AP CREATE INDEX "IDX_APP_PROJ_APPLICATION_UUID" ON "APP_PROJECTS"("APPLICATION_UUID" NULLS FIRST); CREATE INDEX "IDX_APP_PROJ_PROJECT_UUID" ON "APP_PROJECTS"("PROJECT_UUID" NULLS FIRST); +CREATE TABLE "ARCHITECTURE_GRAPHS"( + "UUID" CHARACTER VARYING(40) NOT NULL, + "BRANCH_UUID" CHARACTER VARYING(40) NOT NULL, + "SOURCE" CHARACTER VARYING(255) NOT NULL, + "TYPE" CHARACTER VARYING(255) NOT NULL, + "GRAPH_DATA" CHARACTER LARGE OBJECT NOT NULL +); +ALTER TABLE "ARCHITECTURE_GRAPHS" ADD CONSTRAINT "PK_ARCHITECTURE_GRAPHS" PRIMARY KEY("UUID"); + CREATE TABLE "AUDITS"( "UUID" CHARACTER VARYING(40) NOT NULL, "USER_UUID" CHARACTER VARYING(255) NOT NULL, diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v202502/CreateArchitectureGraphsTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v202502/CreateArchitectureGraphsTableIT.java new file mode 100644 index 00000000000..0e1c8670f2c --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v202502/CreateArchitectureGraphsTableIT.java @@ -0,0 +1,56 @@ +/* + * SonarQube + * Copyright (C) 2009-2025 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.v202502; + +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.sonar.db.MigrationDbTester; + +class CreateArchitectureGraphsTableIT { + public static final String TABLE_NAME = "architecture_graphs"; + + @RegisterExtension + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateArchitectureGraphsTable.class); + private final CreateArchitectureGraphsTable underTest = new CreateArchitectureGraphsTable(db.database()); + + @Test + void execute_shouldCreateTable() throws SQLException { + db.assertTableDoesNotExist(TABLE_NAME); + underTest.execute(); + db.assertTableExists(TABLE_NAME); + db.assertColumnDefinition(TABLE_NAME, "uuid", Types.VARCHAR, UUID_SIZE, false); + db.assertColumnDefinition(TABLE_NAME, "branch_uuid", Types.VARCHAR, UUID_SIZE, false); + db.assertColumnDefinition(TABLE_NAME, "source", Types.VARCHAR, 255, false); + db.assertColumnDefinition(TABLE_NAME, "type", Types.VARCHAR, 255, false); + db.assertColumnDefinition(TABLE_NAME, "graph_data", Types.CLOB, null, false); + } + + @Test + void execute_shouldSupportReentrantMigrationExecution() throws SQLException { + db.assertTableDoesNotExist(TABLE_NAME); + underTest.execute(); + underTest.execute(); + db.assertTableExists(TABLE_NAME); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202502/CreateArchitectureGraphsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202502/CreateArchitectureGraphsTable.java new file mode 100644 index 00000000000..72a984fcd85 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202502/CreateArchitectureGraphsTable.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2025 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.v202502; + +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder; + +import java.sql.SQLException; +import java.util.List; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.def.ClobColumnDef; +import org.sonar.server.platform.db.migration.sql.CreateTableBuilder; +import org.sonar.server.platform.db.migration.step.CreateTableChange; + +public class CreateArchitectureGraphsTable extends CreateTableChange { + public static final String TABLE_NAME = "architecture_graphs"; + + + protected CreateArchitectureGraphsTable(Database db) { + super(db, TABLE_NAME); + } + + @Override + public void execute(Context context, String tableName) throws SQLException { + List<String> createQueries = new CreateTableBuilder(getDialect(), tableName) + .addPkColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setIsNullable(false).setLimit(UUID_SIZE).build()) + .addColumn(newVarcharColumnDefBuilder().setColumnName("branch_uuid").setIsNullable(false).setLimit(UUID_SIZE).build()) + .addColumn(newVarcharColumnDefBuilder().setColumnName("source").setIsNullable(false).setLimit(255).build()) + .addColumn(newVarcharColumnDefBuilder().setColumnName("type").setIsNullable(false).setLimit(255).build()) + .addColumn(ClobColumnDef.newClobColumnDefBuilder().setColumnName("graph_data").setIsNullable(false).build()) + .build(); + + context.execute(createQueries); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202502/DbVersion202502.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202502/DbVersion202502.java index fa10e3d5083..0db5c95b6f3 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202502/DbVersion202502.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v202502/DbVersion202502.java @@ -52,6 +52,8 @@ public class DbVersion202502 implements DbVersion { .add(2025_02_013, "Create unique index for SCA issues to releases", CreateUniqueIndexOnScaIssuesReleases.class) .add(2025_02_014, "Add new_in_pull_request column to SCA releases", AddNewInPullRequestToScaReleasesTable.class) .add(2025_02_015, "Add new_in_pull_request column to SCA dependencies", AddNewInPullRequestToScaDependenciesTable.class) - .add(2025_02_016, "Insert default AI Codefix provider key and modelKey properties", InsertDefaultAiSuggestionProviderKeyAndModelKeyProperties.class); + .add(2025_02_016, "Insert default AI Codefix provider key and modelKey properties", InsertDefaultAiSuggestionProviderKeyAndModelKeyProperties.class) + .add(2025_02_017, "Add table 'architecture_graphs'", CreateArchitectureGraphsTable.class) + ; } } |