]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-22479 added new table 'telemetry_metrics_sent'
authorlukasz-jarocki-sonarsource <lukasz.jarocki@sonarsource.com>
Tue, 9 Jul 2024 13:00:35 +0000 (15:00 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 24 Jul 2024 20:02:47 +0000 (20:02 +0000)
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v107/CreateTelemetryMetricsSentTableIT.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v106/DbVersion106.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v107/CreateTelemetryMetricsSentTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v107/DbVersion107.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v107/package-info.java [new file with mode: 0644]

index dbe7d4108fe16de28ac629e7f2a9505caec717b3..e2c92046c64766c83bb2e0197b7ceee35095503e 100644 (file)
@@ -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 (file)
index 0000000..d6e4bba
--- /dev/null
@@ -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);
+  }
+}
index 5f35923716a348601bcce9f1a518801ddd4636bd..6a5c0c28cb6799dc818e12c9b7d453e6a1d32e54 100644 (file)
@@ -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,
index 6f1ded53b60383e982f85ced71c8c89da61fdf09..ff9b8629d449a95f469aabf229b187e380c37b42 100644 (file)
@@ -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 (file)
index 0000000..a1cb828
--- /dev/null
@@ -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 (file)
index 0000000..3c752d9
--- /dev/null
@@ -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 (file)
index 0000000..6881e46
--- /dev/null
@@ -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;