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,
--- /dev/null
+/*
+ * 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);
+ }
+}
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
DbVersion104.class,
DbVersion105.class,
DbVersion106.class,
+ DbVersion107.class,
// migration steps
MigrationStepRegistryImpl.class,
@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);
}
}
--- /dev/null
+/*
+ * 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());
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+
+}
--- /dev/null
+/*
+ * 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;