diff options
author | lukasz-jarocki-sonarsource <lukasz.jarocki@sonarsource.com> | 2024-07-09 15:00:35 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-07-24 20:02:47 +0000 |
commit | 0bd5289a0f535e88aba1b83fb18053671b50f8b8 (patch) | |
tree | 4650ee4ed2d0a876153124315678ca80285baf05 | |
parent | 7941ea01731364ce635c6f6078896503c83fbeab (diff) | |
download | sonarqube-0bd5289a0f535e88aba1b83fb18053671b50f8b8.tar.gz sonarqube-0bd5289a0f535e88aba1b83fb18053671b50f8b8.zip |
SONAR-22479 added new table 'telemetry_metrics_sent'
7 files changed, 190 insertions, 3 deletions
diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl index dbe7d4108fe..e2c92046c64 100644 --- a/server/sonar-db-dao/src/schema/schema-sq.ddl +++ b/server/sonar-db-dao/src/schema/schema-sq.ddl @@ -1064,6 +1064,13 @@ CREATE TABLE "SNAPSHOTS"( ALTER TABLE "SNAPSHOTS" ADD CONSTRAINT "PK_SNAPSHOTS" PRIMARY KEY("UUID"); CREATE INDEX "SNAPSHOTS_ROOT_COMPONENT_UUID" ON "SNAPSHOTS"("ROOT_COMPONENT_UUID" NULLS FIRST); +CREATE TABLE "TELEMETRY_METRICS_SENT"( + "METRIC_KEY" CHARACTER VARYING(40) NOT NULL, + "DIMENSION" CHARACTER VARYING(40) NOT NULL, + "LAST_SENT" BIGINT NOT NULL +); +ALTER TABLE "TELEMETRY_METRICS_SENT" ADD CONSTRAINT "PK_TELEMETRY_METRICS_SENT" PRIMARY KEY("METRIC_KEY", "DIMENSION"); + CREATE TABLE "USER_DISMISSED_MESSAGES"( "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/v107/CreateTelemetryMetricsSentTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v107/CreateTelemetryMetricsSentTableIT.java new file mode 100644 index 00000000000..d6e4bba37f9 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v107/CreateTelemetryMetricsSentTableIT.java @@ -0,0 +1,61 @@ +/* + * 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.v107; + +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; +import org.sonar.server.platform.db.migration.step.DdlChange; + +class CreateTelemetryMetricsSentTableIT { + + private static final String EXPECTED_TABLE_NAME = "telemetry_metrics_sent"; + + @RegisterExtension + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(CreateTelemetryMetricsSentTable.class); + + private final DdlChange underTest = new CreateTelemetryMetricsSentTable(db.database()); + + @Test + void migration_should_create_a_table() throws SQLException { + db.assertTableDoesNotExist(EXPECTED_TABLE_NAME); + + underTest.execute(); + + db.assertTableExists(EXPECTED_TABLE_NAME); + db.assertColumnDefinition(EXPECTED_TABLE_NAME, "metric_key", Types.VARCHAR, 40, false); + db.assertColumnDefinition(EXPECTED_TABLE_NAME, "dimension", Types.VARCHAR, 40, false); + db.assertColumnDefinition(EXPECTED_TABLE_NAME, "last_sent", Types.BIGINT, null, false); + db.assertPrimaryKey(EXPECTED_TABLE_NAME, null, "metric_key", "dimension"); + } + + @Test + void migration_should_be_reentrant() throws SQLException { + db.assertTableDoesNotExist(EXPECTED_TABLE_NAME); + + underTest.execute(); + // re-entrant + underTest.execute(); + + db.assertTableExists(EXPECTED_TABLE_NAME); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java index 5f35923716a..6a5c0c28cb6 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java @@ -35,6 +35,7 @@ import org.sonar.server.platform.db.migration.version.v103.DbVersion103; import org.sonar.server.platform.db.migration.version.v104.DbVersion104; import org.sonar.server.platform.db.migration.version.v105.DbVersion105; import org.sonar.server.platform.db.migration.version.v106.DbVersion106; +import org.sonar.server.platform.db.migration.version.v107.DbVersion107; public class MigrationConfigurationModule extends Module { @Override @@ -50,6 +51,7 @@ public class MigrationConfigurationModule extends Module { DbVersion104.class, DbVersion105.class, DbVersion106.class, + DbVersion107.class, // migration steps MigrationStepRegistryImpl.class, diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v106/DbVersion106.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v106/DbVersion106.java index 6f1ded53b60..ff9b8629d44 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v106/DbVersion106.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v106/DbVersion106.java @@ -41,8 +41,8 @@ public class DbVersion106 implements DbVersion { @Override public void addSteps(MigrationStepRegistry registry) { registry - .add(10_6_000,"Add 'prioritized_rule' column to 'issues' table", AddPrioritizedRuleColumnToIssuesTable.class) - .add(10_6_001,"Add 'prioritized_rule' column to 'active_rules' table", AddPrioritizedRuleColumnToActiveRulesTable.class) - .add(10_6_002,"Ensure 'value' column is resized to 400 in 'rule_tags' table", ResizeValueColumnInRuleTagsTable.class); + .add(10_6_000, "Add 'prioritized_rule' column to 'issues' table", AddPrioritizedRuleColumnToIssuesTable.class) + .add(10_6_001, "Add 'prioritized_rule' column to 'active_rules' table", AddPrioritizedRuleColumnToActiveRulesTable.class) + .add(10_6_002, "Ensure 'value' column is resized to 400 in 'rule_tags' table", ResizeValueColumnInRuleTagsTable.class); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v107/CreateTelemetryMetricsSentTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v107/CreateTelemetryMetricsSentTable.java new file mode 100644 index 00000000000..a1cb828ad8d --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v107/CreateTelemetryMetricsSentTable.java @@ -0,0 +1,49 @@ +/* + * 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.v107; + +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.VarcharColumnDef.newVarcharColumnDefBuilder; + +public class CreateTelemetryMetricsSentTable extends CreateTableChange { + + private static final String TABLE_NAME = "telemetry_metrics_sent"; + private static final int LENGTH_OF_METRIC_KEY_AND_DIMENSION = 40; + + protected CreateTelemetryMetricsSentTable(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("metric_key").setIsNullable(false) + .setLimit(LENGTH_OF_METRIC_KEY_AND_DIMENSION).build()) + .addPkColumn(newVarcharColumnDefBuilder().setColumnName("dimension").setIsNullable(false) + .setLimit(LENGTH_OF_METRIC_KEY_AND_DIMENSION).build()) + .addColumn(newBigIntegerColumnDefBuilder().setColumnName("last_sent").setIsNullable(false).build()) + .build()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v107/DbVersion107.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v107/DbVersion107.java new file mode 100644 index 00000000000..3c752d9b6d8 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v107/DbVersion107.java @@ -0,0 +1,45 @@ +/* + * 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.v107; + +import org.sonar.server.platform.db.migration.step.MigrationStepRegistry; +import org.sonar.server.platform.db.migration.version.DbVersion; + +public class DbVersion107 implements DbVersion { + + /** + * We use the start of the 10.X cycle as an opportunity to align migration numbers with the SQ version number. + * Please follow this pattern: + * 10_0_000 + * 10_0_001 + * 10_0_002 + * 10_1_000 + * 10_1_001 + * 10_1_002 + * 10_2_000 + */ + + @Override + public void addSteps(MigrationStepRegistry registry) { + registry + .add(10_7_000, "Create 'telemetry_metrics_sent' table", CreateTelemetryMetricsSentTable.class); + } + +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v107/package-info.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v107/package-info.java new file mode 100644 index 00000000000..6881e46b64b --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v107/package-info.java @@ -0,0 +1,23 @@ +/* + * 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. + */ +@ParametersAreNonnullByDefault +package org.sonar.server.platform.db.migration.version.v107; + +import javax.annotation.ParametersAreNonnullByDefault; |