diff options
author | antoine.vinot <antoine.vinot@sonarsource.com> | 2024-10-11 15:54:52 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-10-21 20:03:59 +0000 |
commit | 596b193a1a2d64c50c728ff8051721f61cd79d0c (patch) | |
tree | 530b28376d5313c83d818c41dfae2273edbc4a54 /server/sonar-db-migration | |
parent | 65d606200841e8d63af5e2ad5039cefdd69bc72a (diff) | |
download | sonarqube-596b193a1a2d64c50c728ff8051721f61cd79d0c.tar.gz sonarqube-596b193a1a2d64c50c728ff8051721f61cd79d0c.zip |
SONAR-23098 Create Project Dependencies DB model
Diffstat (limited to 'server/sonar-db-migration')
4 files changed, 129 insertions, 1 deletions
diff --git a/server/sonar-db-migration/src/docs/table_ownership.md b/server/sonar-db-migration/src/docs/table_ownership.md index 99e27309c35..f988a75eb27 100644 --- a/server/sonar-db-migration/src/docs/table_ownership.md +++ b/server/sonar-db-migration/src/docs/table_ownership.md @@ -67,6 +67,7 @@ Important read: [Data Ownership Principles](https://xtranet-sonarsource.atlassia | project_alm_settings | Integration Squad | | project_badge_token | Dev and Team Workflow Squad | | project_branches | | +| project_dependencies | Analysis Experience Squad | | project_links | Dev and Team Workflow Squad | | project_measures | Analysis Experience Squad | | project_qgates | Dev and Team Workflow Squad | diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/CreateProjectDependenciesTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/CreateProjectDependenciesTableIT.java new file mode 100644 index 00000000000..5ae52c51f2a --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/CreateProjectDependenciesTableIT.java @@ -0,0 +1,69 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 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.v108; + +import java.sql.SQLException; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static java.sql.Types.BIGINT; +import static java.sql.Types.CLOB; +import static java.sql.Types.VARCHAR; +import static org.sonar.db.MigrationDbTester.createForMigrationStep; +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; + +class CreateProjectDependenciesTableIT { + + private static final String TABLE_NAME = "project_dependencies"; + + @RegisterExtension + public final MigrationDbTester db = createForMigrationStep(CreateProjectDependenciesTable.class); + + private final DdlChange underTest = new CreateProjectDependenciesTable(db.database()); + + @Test + void execute_shouldCreateTable() throws SQLException { + db.assertTableDoesNotExist(TABLE_NAME); + + underTest.execute(); + + db.assertTableExists(TABLE_NAME); + db.assertPrimaryKey(TABLE_NAME, "pk_project_dependencies", "uuid"); + db.assertColumnDefinition(TABLE_NAME, "uuid", VARCHAR, UUID_SIZE, false); + db.assertColumnDefinition(TABLE_NAME, "version", CLOB, null, true); + db.assertColumnDefinition(TABLE_NAME, "include_paths", CLOB, null, true); + db.assertColumnDefinition(TABLE_NAME, "package_manager", VARCHAR, 50, true); + db.assertColumnDefinition(TABLE_NAME, "created_at", BIGINT, null, false); + db.assertColumnDefinition(TABLE_NAME, "updated_at", BIGINT, null, false); + } + + @Test + void execute_shouldBeReentrant() 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/v108/CreateProjectDependenciesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/CreateProjectDependenciesTable.java new file mode 100644 index 00000000000..db96b2023a0 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/CreateProjectDependenciesTable.java @@ -0,0 +1,58 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 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.v108; + +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.BigIntegerColumnDef.newBigIntegerColumnDefBuilder; +import static org.sonar.server.platform.db.migration.def.ClobColumnDef.newClobColumnDefBuilder; +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 CreateProjectDependenciesTable extends CreateTableChange { + + private static final String TABLE_NAME = "project_dependencies"; + private static final String COLUMN_UUID_NAME = "uuid"; + private static final String COLUMN_VERSION_NAME = "version"; + private static final String COLUMN_INCLUDE_PATHS_NAME = "include_paths"; + private static final String COLUMN_PACKAGE_MANAGER_NAME = "package_manager"; + private static final int COLUMN_PACKAGE_MANAGER_SIZE = 50; + private static final String COLUMN_CREATED_AT_NAME = "created_at"; + private static final String COLUMN_UPDATED_AT_NAME = "updated_at"; + + protected CreateProjectDependenciesTable(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(COLUMN_UUID_NAME).setIsNullable(false).setLimit(UUID_SIZE).build()) + .addColumn(newClobColumnDefBuilder().setColumnName(COLUMN_VERSION_NAME).setIsNullable(true).build()) + .addColumn(newClobColumnDefBuilder().setColumnName(COLUMN_INCLUDE_PATHS_NAME).setIsNullable(true).build()) + .addColumn(newVarcharColumnDefBuilder().setColumnName(COLUMN_PACKAGE_MANAGER_NAME).setIsNullable(true).setLimit(COLUMN_PACKAGE_MANAGER_SIZE).build()) + .addColumn(newBigIntegerColumnDefBuilder().setColumnName(COLUMN_CREATED_AT_NAME).setIsNullable(false).build()) + .addColumn(newBigIntegerColumnDefBuilder().setColumnName(COLUMN_UPDATED_AT_NAME).setIsNullable(false).build()) + .build()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DbVersion108.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DbVersion108.java index 1c3340bdfce..aab86608e2f 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DbVersion108.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DbVersion108.java @@ -56,7 +56,7 @@ public class DbVersion108 implements DbVersion { .add(10_8_013, "Drop index on 'project_branches.measures_migrated'", DropIndexOnProjectBranchesMeasuresMigrated.class) .add(10_8_014, "Drop 'measures_migrated' column on 'project_branches' table", DropMeasuresMigratedColumnInProjectBranchesTable.class) .add(10_8_015, "Add column 'impacts' in 'active_rules' table", AddImpactsColumnInActiveRulesTable.class) - ; + .add(10_8_016, "Create 'project_dependencies' table", CreateProjectDependenciesTable.class); } } |