underTest.deleteIssues(projectOrView.uuid());
assertThat(dbTester.countSql("select count(uuid) from new_code_reference_issues where issue_key in (" +
- String.join(", ", issueKeys) + ")")).isZero();
+ String.join(", ", issueKeys) + ")")).isZero();
+ }
+
+ @Test
+ @UseDataProvider("projectsAndViews")
+ public void deleteIssues_shouldDeleteIssuesImpacts(ComponentDto projectOrView) {
+ RuleDto rule = dbTester.rules().insert();
+ dbTester.components().insertComponent(projectOrView);
+ ComponentDto file = dbTester.components().insertComponent(newFileDto(projectOrView));
+ List<String> issueKeys = new ArrayList<>();
+ int count = 5;
+ IntStream.range(0, count).forEach(i -> {
+ IssueDto issue = dbTester.issues().insertIssue(t -> t.setRule(rule).setProject(projectOrView).setComponent(projectOrView)
+ .addImpact(new ImpactDto().setUuid(UuidFactoryFast.getInstance().create())
+ .setSoftwareQuality(SoftwareQuality.MAINTAINABILITY)
+ .setSeverity(Severity.HIGH)));
+ issueKeys.add("'" + issue.getKey() + "'");
+ });
+
+ underTest.deleteIssues(projectOrView.uuid());
+
+ assertThat(dbTester.countSql("select count(uuid) from issues_impacts where issue_key in (" +
+ String.join(", ", issueKeys) + ")")).isZero();
}
@Test
#{createdAt,jdbcType=BIGINT})
</insert>
- <insert id="deleteAsNewCodeOnReferenceBranch" parameterType="String" useGeneratedKeys="false">
+ <insert id="insertIssueImpact" parameterType="map" useGeneratedKeys="false">
+ INSERT INTO issues_impacts (uuid, issue_key, software_quality, severity)
+ VALUES (
+ #{dto.uuid,jdbcType=VARCHAR},
+ #{issueKey,jdbcType=VARCHAR},
+ #{dto.softwareQuality,jdbcType=VARCHAR},
+ #{dto.severity,jdbcType=VARCHAR})
+ </insert>
+
+ <delete id="deleteAsNewCodeOnReferenceBranch" parameterType="String" >
DELETE FROM new_code_reference_issues
where issue_key = #{issueKey, jdbcType=VARCHAR}
- </insert>
+ </delete>
+
+ <delete id="deleteIssueImpacts" parameterType="String" >
+ DELETE FROM issues_impacts
+ where issue_key = #{issueUuid, jdbcType=VARCHAR}
+ </delete>
<!--
IMPORTANT - invariant columns can't be updated. See IssueDto#toDtoForUpdate()
inner join components root on root.uuid=i.project_uuid
left join users u on i.assignee = u.uuid
left join new_code_reference_issues n on i.kee = n.issue_key
+ left outer join issues_impacts ii on i.kee = ii.issue_key
+ left outer join rules_default_impacts rdi on r.uuid = rdi.rule_uuid
where i.kee=#{kee,jdbcType=VARCHAR}
</select>
inner join components p on p.uuid=i.component_uuid
inner join components root on root.uuid=i.project_uuid
left join new_code_reference_issues n on i.kee = n.issue_key
+ left outer join issues_impacts ii on i.kee = ii.issue_key
+ left outer join rules_default_impacts rdi on r.uuid = rdi.rule_uuid
where
i.component_uuid = #{componentUuid,jdbcType=VARCHAR} and
i.status <> 'CLOSED'
and ic.change_data like '%status=%|CLOSED%'
left join new_code_reference_issues n on
i.kee = n.issue_key
+ left outer join issues_impacts ii on
+ i.kee = ii.issue_key
+ left outer join rules_default_impacts rdi on
+ r.uuid = rdi.rule_uuid
where
i.component_uuid = #{componentUuid,jdbcType=VARCHAR}
and i.status = 'CLOSED'
inner join components p on p.uuid=i.component_uuid
inner join components root on root.uuid=i.project_uuid
left join new_code_reference_issues n on i.kee = n.issue_key
+ left outer join issues_impacts ii on i.kee = ii.issue_key
+ left outer join rules_default_impacts rdi on r.uuid = rdi.rule_uuid
where i.kee in
<foreach collection="list" open="(" close=")" item="key" separator=",">
#{key,jdbcType=VARCHAR}
inner join components p on p.uuid=i.component_uuid
inner join components root on root.uuid=i.project_uuid
left join new_code_reference_issues n on i.kee = n.issue_key
+ left outer join issues_impacts ii on i.kee = ii.issue_key
+ left outer join rules_default_impacts rdi on r.uuid = rdi.rule_uuid
where
i.kee in
<foreach collection="keys" open="(" close=")" item="key" separator=",">
inner join components root on root.uuid=i.project_uuid
left join users u on i.assignee = u.uuid
left join new_code_reference_issues n on i.kee = n.issue_key
+ left outer join issues_impacts ii on i.kee = ii.issue_key
+ left outer join rules_default_impacts rdi on r.uuid = rdi.rule_uuid
where i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
order by i.issue_creation_date ASC
limit #{pagination.pageSize,jdbcType=INTEGER} offset #{pagination.offset,jdbcType=INTEGER}
inner join components root on root.uuid=i.project_uuid
left join users u on i.assignee = u.uuid
left join new_code_reference_issues n on i.kee = n.issue_key
+ left outer join issues_impacts ii on i.kee = ii.issue_key
+ left outer join rules_default_impacts rdi on r.uuid = rdi.rule_uuid
</select>
<select id="selectByComponentUuidPaginated" parameterType="map" resultType="Issue" databaseId="oracle">
inner join components root on root.uuid=i.project_uuid
left join users u on i.assignee = u.uuid
left join new_code_reference_issues n on i.kee = n.issue_key
+ left outer join issues_impacts ii on i.kee = ii.issue_key
+ left outer join rules_default_impacts rdi on r.uuid = rdi.rule_uuid
</select>
<sql id="selectByBranchColumns">
CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT" NULLS FIRST);
CREATE INDEX "ISSUES_RULE_UUID" ON "ISSUES"("RULE_UUID" NULLS FIRST);
+CREATE TABLE "ISSUES_IMPACTS"(
+ "UUID" CHARACTER VARYING(40) NOT NULL,
+ "ISSUE_KEY" CHARACTER VARYING(40) NOT NULL,
+ "SOFTWARE_QUALITY" CHARACTER VARYING(40) NOT NULL,
+ "SEVERITY" CHARACTER VARYING(40) NOT NULL
+);
+ALTER TABLE "ISSUES_IMPACTS" ADD CONSTRAINT "PK_ISSUES_IMPACTS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_ISS_KEY_SOF_QUAL" ON "ISSUES_IMPACTS"("ISSUE_KEY" NULLS FIRST, "SOFTWARE_QUALITY" NULLS FIRST);
+
CREATE TABLE "LIVE_MEASURES"(
"UUID" CHARACTER VARYING(40) NOT NULL,
"PROJECT_UUID" CHARACTER VARYING(50) NOT NULL,
ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("UUID");
CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY" NULLS FIRST, "PLUGIN_NAME" NULLS FIRST);
+CREATE TABLE "RULES_DEFAULT_IMPACTS"(
+ "UUID" CHARACTER VARYING(40) NOT NULL,
+ "RULE_UUID" CHARACTER VARYING(40) NOT NULL,
+ "SOFTWARE_QUALITY" CHARACTER VARYING(40) NOT NULL,
+ "SEVERITY" CHARACTER VARYING(40) NOT NULL
+);
+ALTER TABLE "RULES_DEFAULT_IMPACTS" ADD CONSTRAINT "PK_RULES_DEFAULT_IMPACTS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_RUL_UUID_SOF_QUAL" ON "RULES_DEFAULT_IMPACTS"("RULE_UUID" NULLS FIRST, "SOFTWARE_QUALITY" NULLS FIRST);
+
CREATE TABLE "RULES_PARAMETERS"(
"UUID" CHARACTER VARYING(40) NOT NULL,
"NAME" CHARACTER VARYING(128) NOT NULL,
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.v102;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+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.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class CreateIssueImpactsTable extends CreateTableChange {
+ static final String TABLE_NAME = "issues_impacts";
+
+ public CreateIssueImpactsTable(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("uuid").setIsNullable(false).setLimit(VarcharColumnDef.UUID_SIZE).build())
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("issue_key").setIsNullable(false).setLimit(VarcharColumnDef.UUID_SIZE).build())
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("software_quality").setIsNullable(false).setLimit(40).build())
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("severity").setIsNullable(false).setLimit(40).build())
+ .build());
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.v102;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+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.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class CreateRulesDefaultImpactsTable extends CreateTableChange {
+ static final String TABLE_NAME = "rules_default_impacts";
+
+ public CreateRulesDefaultImpactsTable(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("uuid").setIsNullable(false).setLimit(VarcharColumnDef.UUID_SIZE).build())
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("rule_uuid").setIsNullable(false).setLimit(VarcharColumnDef.UUID_SIZE).build())
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("software_quality").setIsNullable(false).setLimit(40).build())
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("severity").setIsNullable(false).setLimit(40).build())
+ .build());
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.v102;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class CreateUniqueConstraintOnIssuesImpacts extends DdlChange {
+ private static final String TABLE_NAME = "issues_impacts";
+ private static final String INDEX_NAME = "uniq_iss_key_sof_qual";
+
+ public CreateUniqueConstraintOnIssuesImpacts(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ try (Connection connection = getDatabase().getDataSource().getConnection()) {
+ createIndex(context, connection);
+ }
+ }
+
+ private static void createIndex(Context context, Connection connection) {
+ if (!DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection)) {
+ context.execute(new CreateIndexBuilder()
+ .setTable(TABLE_NAME)
+ .setName(INDEX_NAME)
+ .addColumn("issue_key")
+ .addColumn("software_quality")
+ .setUnique(true)
+ .build());
+ }
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.v102;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class CreateUniqueConstraintOnRulesDefaultImpacts extends DdlChange {
+ private static final String TABLE_NAME = "rules_default_impacts";
+ private static final String INDEX_NAME = "uniq_rul_uuid_sof_qual";
+
+ public CreateUniqueConstraintOnRulesDefaultImpacts(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ try (Connection connection = getDatabase().getDataSource().getConnection()) {
+ createIndex(context, connection);
+ }
+ }
+
+ private static void createIndex(Context context, Connection connection) {
+ if (!DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection)) {
+ context.execute(new CreateIndexBuilder()
+ .setTable(TABLE_NAME)
+ .setName(INDEX_NAME)
+ .addColumn("rule_uuid")
+ .addColumn("software_quality")
+ .setUnique(true)
+ .build());
+ }
+ }
+}
.add(10_2_034, "Populate 'clean_code_attribute' column in 'rules' table", PopulateCleanCodeAttributeColumnInRules.class)
//TODO SONAR-20073
//.add(10_2_035, "Make 'clean_code_attribute' column not nullable in 'rules' table", MakeCleanCodeAttributeColumnNotNullableInRules.class);
+
+ .add(10_2_036, "Create 'rules_default_impacts' table", CreateRulesDefaultImpactsTable.class)
+ .add(10_2_037, "Create unique constraint index on 'rules_default_impacts' table", CreateUniqueConstraintOnRulesDefaultImpacts.class)
+ .add(10_2_038, "Create 'issues_impacts' table", CreateIssueImpactsTable.class)
+ .add(10_2_039, "Create unique constraint index on 'issues_impacts' table", CreateUniqueConstraintOnIssuesImpacts.class);
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.v102;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class CreateIssueImpactsTableTest {
+ private static final String EXPECTED_TABLE_NAME = "issues_impacts";
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createEmpty();
+
+ private final DdlChange underTest = new CreateIssueImpactsTable(db.database());
+
+ @Test
+ public 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, "issue_key", Types.VARCHAR, 40, false);
+ db.assertColumnDefinition(EXPECTED_TABLE_NAME, "software_quality", Types.VARCHAR, 40, false);
+ db.assertColumnDefinition(EXPECTED_TABLE_NAME, "severity", Types.VARCHAR, 40, false);
+ db.assertPrimaryKey(EXPECTED_TABLE_NAME, null, "uuid");
+ }
+
+ @Test
+ public void migration_should_be_reentrant() throws SQLException {
+ db.assertTableDoesNotExist(EXPECTED_TABLE_NAME);
+
+ underTest.execute();
+ // re-entrant
+ underTest.execute();
+
+ db.assertTableExists(EXPECTED_TABLE_NAME);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.v102;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+
+public class CreateRulesDefaultImpactsTableTest {
+ private static final String EXPECTED_TABLE_NAME = "rules_default_impacts";
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createEmpty();
+
+ private final DdlChange underTest = new CreateRulesDefaultImpactsTable(db.database());
+
+ @Test
+ public 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, "rule_uuid", Types.VARCHAR, 40, false);
+ db.assertColumnDefinition(EXPECTED_TABLE_NAME, "software_quality", Types.VARCHAR, 40, false);
+ db.assertColumnDefinition(EXPECTED_TABLE_NAME, "severity", Types.VARCHAR, 40, false);
+ db.assertPrimaryKey(EXPECTED_TABLE_NAME, null, "uuid");
+ }
+
+ @Test
+ public void migration_should_be_reentrant() throws SQLException {
+ db.assertTableDoesNotExist(EXPECTED_TABLE_NAME);
+
+ underTest.execute();
+ // re-entrant
+ underTest.execute();
+
+ db.assertTableExists(EXPECTED_TABLE_NAME);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.v102;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class CreateUniqueConstraintOnIssuesImpactsTest {
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(CreateUniqueConstraintOnIssuesImpactsTest.class, "schema.sql");
+
+ private final CreateUniqueConstraintOnIssuesImpacts underTest = new CreateUniqueConstraintOnIssuesImpacts(db.database());
+
+ @Test
+ public void migration_should_create_index() throws SQLException {
+ db.assertIndexDoesNotExist("issues_impacts", "uniq_iss_key_sof_qual");
+
+ underTest.execute();
+
+ db.assertUniqueIndex("issues_impacts", "uniq_iss_key_sof_qual", "issue_key", "software_quality");
+ }
+
+ @Test
+ public void migration_should_be_reentrant() throws SQLException {
+ underTest.execute();
+ underTest.execute();
+
+ db.assertUniqueIndex("issues_impacts", "uniq_iss_key_sof_qual", "issue_key", "software_quality");
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.v102;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+
+public class CreateUniqueConstraintOnRulesDefaultImpactsTest {
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(CreateUniqueConstraintOnRulesDefaultImpactsTest.class, "schema.sql");
+
+ private final CreateUniqueConstraintOnRulesDefaultImpacts underTest = new CreateUniqueConstraintOnRulesDefaultImpacts(db.database());
+
+ @Test
+ public void migration_should_create_index() throws SQLException {
+ db.assertIndexDoesNotExist("rules_default_impacts", "uniq_rul_uuid_sof_qual");
+
+ underTest.execute();
+
+ db.assertUniqueIndex("rules_default_impacts", "uniq_rul_uuid_sof_qual", "rule_uuid", "software_quality");
+ }
+
+ @Test
+ public void migration_should_be_reentrant() throws SQLException {
+ underTest.execute();
+ underTest.execute();
+
+ db.assertUniqueIndex("rules_default_impacts", "uniq_rul_uuid_sof_qual", "rule_uuid", "software_quality");
+ }
+}
+
--- /dev/null
+CREATE TABLE "ISSUES_IMPACTS"(
+ "UUID" CHARACTER VARYING(40) NOT NULL,
+ "ISSUE_KEY" CHARACTER VARYING(40) NOT NULL,
+ "SOFTWARE_QUALITY" CHARACTER VARYING(40) NOT NULL,
+ "SEVERITY" CHARACTER VARYING(40) NOT NULL
+);
+ALTER TABLE "ISSUES_IMPACTS" ADD CONSTRAINT "PK_ISSUES_IMPACTS" PRIMARY KEY("UUID");
+CREATE INDEX "ISSUES_IMPACTS_ISSUE_KEY" ON "ISSUES_IMPACTS"("ISSUE_KEY" NULLS FIRST);
--- /dev/null
+CREATE TABLE "RULES_DEFAULT_IMPACTS"(
+ "UUID" CHARACTER VARYING(40) NOT NULL,
+ "RULE_UUID" CHARACTER VARYING(40) NOT NULL,
+ "SOFTWARE_QUALITY" CHARACTER VARYING(40) NOT NULL,
+ "SEVERITY" CHARACTER VARYING(40) NOT NULL
+);
+ALTER TABLE "RULES_DEFAULT_IMPACTS" ADD CONSTRAINT "PK_RULES_DEFAULT_IMPACTS" PRIMARY KEY("UUID");
+CREATE INDEX "RUL_DEF_IMP_RULE_UUID" ON "RULES_DEFAULT_IMPACTS"("RULE_UUID" NULLS FIRST);