Kaynağa Gözat

SONAR-20548 created tables to store changelog events

tags/10.3.0.82913
lukasz-jarocki-sonarsource 7 ay önce
ebeveyn
işleme
975cca52c3
14 değiştirilmiş dosya ile 588 ekleme ve 3 silme
  1. 36
    0
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileChangeDto.java
  2. 71
    0
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/RuleImpactChangeDto.java
  3. 19
    1
      server/sonar-db-dao/src/schema/schema-sq.ddl
  4. 55
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/AddRuleChangesUuidColumnInQProfileChanges.java
  5. 48
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/CreateRuleChangesTable.java
  6. 48
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/CreateRuleImpactChangesTable.java
  7. 57
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/CreateUniqueIndexForRuleImpactChangesTable.java
  8. 4
    2
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/DbVersion103.java
  9. 53
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/AddRuleChangesUuidColumnInQProfileChangesTest.java
  10. 63
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateRuleChangesTableTest.java
  11. 65
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateRuleImpactChangesTableTest.java
  12. 52
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateUniqueIndexForRuleImpactChangesTableTest.java
  13. 10
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v103/AddRuleChangesUuidColumnInQProfileChangesTest/schema.sql
  14. 7
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v103/CreateUniqueIndexForRuleImpactChangesTableTest/schema.sql

+ 36
- 0
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileChangeDto.java Dosyayı Görüntüle

@@ -20,12 +20,16 @@
package org.sonar.db.qualityprofile;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.rules.CleanCodeAttribute;
import org.sonar.api.utils.KeyValueFormat;
import org.sonar.db.issue.ImpactDto;

public class QProfileChangeDto {

@@ -34,6 +38,12 @@ public class QProfileChangeDto {
private String changeType;
private String userUuid;
private String data;

private CleanCodeAttribute oldCleanCodeAttribute;
private CleanCodeAttribute newCleanCodeAttribute;

private Set<RuleImpactChangeDto> ruleImpactChangeDtos;

private long createdAt;

public String getUuid() {
@@ -108,8 +118,34 @@ public class QProfileChangeDto {
return this;
}

public CleanCodeAttribute getOldCleanCodeAttribute() {
return oldCleanCodeAttribute;
}

public void setOldCleanCodeAttribute(CleanCodeAttribute oldCleanCodeAttribute) {
this.oldCleanCodeAttribute = oldCleanCodeAttribute;
}

public CleanCodeAttribute getNewCleanCodeAttribute() {
return newCleanCodeAttribute;
}

public void setNewCleanCodeAttribute(CleanCodeAttribute newCleanCodeAttribute) {
this.newCleanCodeAttribute = newCleanCodeAttribute;
}

public Set<RuleImpactChangeDto> getRuleImpactChangeDtos() {
return ruleImpactChangeDtos;
}

public void setRuleImpactChangeDtos(Set<RuleImpactChangeDto> ruleImpactChangeDtos) {
this.ruleImpactChangeDtos = ruleImpactChangeDtos;
}

@Override
public String toString() {
return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
}


}

+ 71
- 0
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/RuleImpactChangeDto.java Dosyayı Görüntüle

@@ -0,0 +1,71 @@
/*
* 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.db.qualityprofile;

public class RuleImpactChangeDto {

private String newSoftwareQuality;
private String oldSoftwareQuality;

private String newSeverity;
private String oldSeverity;

private String ruleChangeUuid;

public String getNewSoftwareQuality() {
return newSoftwareQuality;
}

public void setNewSoftwareQuality(String newSoftwareQuality) {
this.newSoftwareQuality = newSoftwareQuality;
}

public String getOldSoftwareQuality() {
return oldSoftwareQuality;
}

public void setOldSoftwareQuality(String oldSoftwareQuality) {
this.oldSoftwareQuality = oldSoftwareQuality;
}

public String getNewSeverity() {
return newSeverity;
}

public void setNewSeverity(String newSeverity) {
this.newSeverity = newSeverity;
}

public String getOldSeverity() {
return oldSeverity;
}

public void setOldSeverity(String oldSeverity) {
this.oldSeverity = oldSeverity;
}

public String getRuleChangeUuid() {
return ruleChangeUuid;
}

public void setRuleChangeUuid(String ruleChangeUuid) {
this.ruleChangeUuid = ruleChangeUuid;
}
}

+ 19
- 1
server/sonar-db-dao/src/schema/schema-sq.ddl Dosyayı Görüntüle

@@ -810,7 +810,8 @@ CREATE TABLE "QPROFILE_CHANGES"(
"CHANGE_TYPE" CHARACTER VARYING(20) NOT NULL,
"USER_UUID" CHARACTER VARYING(255),
"CHANGE_DATA" CHARACTER LARGE OBJECT,
"CREATED_AT" BIGINT NOT NULL
"CREATED_AT" BIGINT NOT NULL,
"RULE_CHANGE_UUID" CHARACTER VARYING(40)
);
ALTER TABLE "QPROFILE_CHANGES" ADD CONSTRAINT "PK_QPROFILE_CHANGES" PRIMARY KEY("KEE");
CREATE INDEX "QP_CHANGES_RULES_PROFILE_UUID" ON "QPROFILE_CHANGES"("RULES_PROFILE_UUID" NULLS FIRST);
@@ -873,6 +874,14 @@ CREATE TABLE "REPORT_SUBSCRIPTIONS"(
ALTER TABLE "REPORT_SUBSCRIPTIONS" ADD CONSTRAINT "PK_REPORT_SUBSCRIPTIONS" PRIMARY KEY("UUID");
CREATE UNIQUE NULLS DISTINCT INDEX "UNIQ_REPORT_SUBSCRIPTIONS" ON "REPORT_SUBSCRIPTIONS"("PORTFOLIO_UUID" NULLS FIRST, "BRANCH_UUID" NULLS FIRST, "USER_UUID" NULLS FIRST);

CREATE TABLE "RULE_CHANGES"(
"UUID" CHARACTER VARYING(40) NOT NULL,
"NEW_CLEAN_CODE_ATTRIBUTE" CHARACTER VARYING(40),
"OLD_CLEAN_CODE_ATTRIBUTE" CHARACTER VARYING(40),
"RULE_UUID" CHARACTER VARYING(40) NOT NULL
);
ALTER TABLE "RULE_CHANGES" ADD CONSTRAINT "PK_RULE_CHANGES" PRIMARY KEY("UUID");

CREATE TABLE "RULE_DESC_SECTIONS"(
"UUID" CHARACTER VARYING(40) NOT NULL,
"RULE_UUID" CHARACTER VARYING(40) NOT NULL,
@@ -884,6 +893,15 @@ CREATE TABLE "RULE_DESC_SECTIONS"(
ALTER TABLE "RULE_DESC_SECTIONS" ADD CONSTRAINT "PK_RULE_DESC_SECTIONS" PRIMARY KEY("UUID");
CREATE UNIQUE NULLS DISTINCT INDEX "UNIQ_RULE_DESC_SECTIONS" ON "RULE_DESC_SECTIONS"("RULE_UUID" NULLS FIRST, "KEE" NULLS FIRST, "CONTEXT_KEY" NULLS FIRST);

CREATE TABLE "RULE_IMPACT_CHANGES"(
"NEW_SOFTWARE_QUALITY" CHARACTER VARYING(40) NOT NULL,
"OLD_SOFTWARE_QUALITY" CHARACTER VARYING(40) NOT NULL,
"NEW_SEVERITY" CHARACTER VARYING(40) NOT NULL,
"OLD_SEVERITY" CHARACTER VARYING(40) NOT NULL,
"RULE_CHANGE_UUID" CHARACTER VARYING(40) NOT NULL
);
CREATE UNIQUE NULLS DISTINCT INDEX "UNIQ_RULE_IMPACT_CHANGES" ON "RULE_IMPACT_CHANGES"("RULE_CHANGE_UUID" NULLS FIRST, "NEW_SOFTWARE_QUALITY" NULLS FIRST, "NEW_SEVERITY" NULLS FIRST);

CREATE TABLE "RULE_REPOSITORIES"(
"KEE" CHARACTER VARYING(200) NOT NULL,
"LANGUAGE" CHARACTER VARYING(20) NOT NULL,

+ 55
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/AddRuleChangesUuidColumnInQProfileChanges.java Dosyayı Görüntüle

@@ -0,0 +1,55 @@
/*
* 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.v103;

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.def.ColumnDef;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class AddRuleChangesUuidColumnInQProfileChanges extends DdlChange {
private static final String TABLE_NAME = "qprofile_changes";
private static final String COLUMN_NAME = "rule_change_uuid";

private static final int NEW_COLUMN_SIZE = 40;

public AddRuleChangesUuidColumnInQProfileChanges(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
try (Connection connection = getDatabase().getDataSource().getConnection()) {
if (!DatabaseUtils.tableColumnExists(connection, TABLE_NAME, COLUMN_NAME)) {
ColumnDef columnDef = VarcharColumnDef.newVarcharColumnDefBuilder()
.setColumnName(COLUMN_NAME)
.setLimit(NEW_COLUMN_SIZE)
.setIsNullable(true)
.build();

context.execute(new AddColumnsBuilder(getDialect(), TABLE_NAME).addColumn(columnDef).build());
}
}
}
}

+ 48
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/CreateRuleChangesTable.java Dosyayı Görüntüle

@@ -0,0 +1,48 @@
/*
* 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.v103;

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 org.sonar.server.platform.db.migration.step.DdlChange;

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 CreateRuleChangesTable extends CreateTableChange {

static final String TABLE_NAME = "rule_changes";

public CreateRuleChangesTable(Database db) {
super(db, TABLE_NAME);
}

@Override
public void execute(DdlChange.Context context, String tableName) throws SQLException {
context.execute(new CreateTableBuilder(getDialect(), tableName)
.addPkColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("new_clean_code_attribute").setIsNullable(true).setLimit(40).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("old_clean_code_attribute").setIsNullable(true).setLimit(40).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("rule_uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
.build());
}
}

+ 48
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/CreateRuleImpactChangesTable.java Dosyayı Görüntüle

@@ -0,0 +1,48 @@
/*
* 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.v103;

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 org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class CreateRuleImpactChangesTable extends CreateTableChange {

static final String TABLE_NAME = "rule_impact_changes";

public CreateRuleImpactChangesTable(Database db) {
super(db, TABLE_NAME);
}

@Override
public void execute(DdlChange.Context context, String tableName) throws SQLException {
context.execute(new CreateTableBuilder(getDialect(), tableName)
.addColumn(newVarcharColumnDefBuilder().setColumnName("new_software_quality").setIsNullable(false).setLimit(40).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("old_software_quality").setIsNullable(false).setLimit(40).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("new_severity").setIsNullable(false).setLimit(40).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("old_severity").setIsNullable(false).setLimit(40).build())
.addColumn(newVarcharColumnDefBuilder().setColumnName("rule_change_uuid").setIsNullable(false).setLimit(40).build())
.build());
}
}

+ 57
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/CreateUniqueIndexForRuleImpactChangesTable.java Dosyayı Görüntüle

@@ -0,0 +1,57 @@
/*
* 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.v103;

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 CreateUniqueIndexForRuleImpactChangesTable extends DdlChange {

static final String INDEX_NAME = "uniq_rule_impact_changes";
static final String TABLE_NAME = "rule_impact_changes";

public CreateUniqueIndexForRuleImpactChangesTable(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
try (Connection connection = getDatabase().getDataSource().getConnection()) {
createUniqueIndex(context, connection);
}
}

private static void createUniqueIndex(Context context, Connection connection) {
if (!DatabaseUtils.indexExistsIgnoreCase(TABLE_NAME, INDEX_NAME, connection)) {
context.execute(new CreateIndexBuilder()
.setTable(TABLE_NAME)
.setName(INDEX_NAME)
.addColumn("rule_change_uuid")
.addColumn("new_software_quality")
.addColumn("new_severity")
.setUnique(true)
.build());
}
}
}

+ 4
- 2
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/DbVersion103.java Dosyayı Görüntüle

@@ -46,10 +46,12 @@ public class DbVersion103 implements DbVersion {
.add(10_3_002, "Create unique index on 'github_perms_mapping'", CreateUniqueIndexForGithubPermissionsMappingTable.class)
.add(10_3_003, "Add default mappings to 'github_perms_mapping'", PopulateGithubPermissionsMapping.class)
.add(10_3_004, "Add 'clean_code_attribute' column in 'issues' table", AddCleanCodeAttributeColumnInIssuesTable.class)

.add(10_3_005, "Add 'creation_method' column in 'projects' table", AddCreationMethodColumnInProjectsTable.class)
.add(10_3_006, "Populate 'creation_method' column in 'projects' table", PopulateCreationMethodColumnInProjectsTable.class)
.add(10_3_007, "Make 'creation_method' column in 'projects' table non-nullable", MakeCreationMethodColumnInProjectsNotNullable.class)
;
.add(10_3_008, "Add 'rule_changes_uuid' column in 'qprofile_changes'", AddRuleChangesUuidColumnInQProfileChanges.class)
.add(10_3_009, "Create table 'rule_changes'", CreateRuleChangesTable.class)
.add(10_3_010, "Create table 'rule_impact_changes", CreateRuleImpactChangesTable.class)
.add(10_3_011, "Create index for 'rule_impact_changes", CreateUniqueIndexForRuleImpactChangesTable.class);
}
}

+ 53
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/AddRuleChangesUuidColumnInQProfileChangesTest.java Dosyayı Görüntüle

@@ -0,0 +1,53 @@
/*
* 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.v103;

import java.sql.SQLException;
import java.sql.Types;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;

import static org.assertj.core.api.Assertions.assertThatCode;

public class AddRuleChangesUuidColumnInQProfileChangesTest {

private static final String TABLE_NAME = "qprofile_changes";
private static final String COLUMN_NAME = "rule_change_uuid";

@Rule
public final CoreDbTester db = CoreDbTester.createForSchema(AddRuleChangesUuidColumnInQProfileChangesTest.class, "schema.sql");

private final AddRuleChangesUuidColumnInQProfileChanges underTest = new AddRuleChangesUuidColumnInQProfileChanges(db.database());

@Test
public void execute_whenColumnDoesNotExist_shouldCreateColumn() throws SQLException {
db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME);
underTest.execute();
db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.VARCHAR, 40, true);
}

@Test
public void execute_whenColumnsAlreadyExists_shouldNotFail() throws SQLException {
underTest.execute();
assertThatCode(underTest::execute).doesNotThrowAnyException();
}

}

+ 63
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateRuleChangesTableTest.java Dosyayı Görüntüle

@@ -0,0 +1,63 @@
/*
* 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.v103;

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;

import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;

public class CreateRuleChangesTableTest {

private final static String TABLE_NAME = "rule_changes";

@Rule
public final CoreDbTester db = CoreDbTester.createEmpty();

private final DdlChange underTest = new CreateRuleChangesTable(db.database());

@Test
public void migration_should_create_a_table() throws SQLException {
db.assertTableDoesNotExist(TABLE_NAME);

underTest.execute();

db.assertTableExists(TABLE_NAME);
db.assertColumnDefinition(TABLE_NAME, "uuid", Types.VARCHAR, UUID_SIZE, false);
db.assertColumnDefinition(TABLE_NAME, "new_clean_code_attribute", Types.VARCHAR, 40, true);
db.assertColumnDefinition(TABLE_NAME, "old_clean_code_attribute", Types.VARCHAR, 40, true);
db.assertColumnDefinition(TABLE_NAME, "rule_uuid", Types.VARCHAR, UUID_SIZE, false);
}

@Test
public void migration_should_be_reentrant() throws SQLException {
db.assertTableDoesNotExist(TABLE_NAME);

underTest.execute();
// re-entrant
underTest.execute();

db.assertTableExists(TABLE_NAME);
}
}

+ 65
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateRuleImpactChangesTableTest.java Dosyayı Görüntüle

@@ -0,0 +1,65 @@
/*
* 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.v103;

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;

import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;

public class CreateRuleImpactChangesTableTest {


private final static String TABLE_NAME = "rule_impact_changes";

@Rule
public final CoreDbTester db = CoreDbTester.createEmpty();

private final DdlChange underTest = new CreateRuleImpactChangesTable(db.database());

@Test
public void migration_should_create_a_table() throws SQLException {
db.assertTableDoesNotExist(TABLE_NAME);

underTest.execute();

db.assertTableExists(TABLE_NAME);
db.assertColumnDefinition(TABLE_NAME, "new_software_quality", Types.VARCHAR, 40, false);
db.assertColumnDefinition(TABLE_NAME, "old_software_quality", Types.VARCHAR, 40, false);
db.assertColumnDefinition(TABLE_NAME, "new_severity", Types.VARCHAR, 40, false);
db.assertColumnDefinition(TABLE_NAME, "old_severity", Types.VARCHAR, 40, false);
db.assertColumnDefinition(TABLE_NAME, "rule_change_uuid", Types.VARCHAR, UUID_SIZE, false);
}

@Test
public void migration_should_be_reentrant() throws SQLException {
db.assertTableDoesNotExist(TABLE_NAME);

underTest.execute();
// re-entrant
underTest.execute();

db.assertTableExists(TABLE_NAME);
}
}

+ 52
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/CreateUniqueIndexForRuleImpactChangesTableTest.java Dosyayı Görüntüle

@@ -0,0 +1,52 @@
/*
* 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.v103;

import java.sql.SQLException;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;

public class CreateUniqueIndexForRuleImpactChangesTableTest {

static final String INDEX_NAME = "uniq_rule_impact_changes";
static final String TABLE_NAME = "rule_impact_changes";
@Rule
public final CoreDbTester db = CoreDbTester.createForSchema(CreateUniqueIndexForRuleImpactChangesTableTest.class, "schema.sql");

private final CreateUniqueIndexForRuleImpactChangesTable underTest = new CreateUniqueIndexForRuleImpactChangesTable(db.database());

@Test
public void migration_should_create_index() throws SQLException {
db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME);

underTest.execute();

db.assertUniqueIndex(TABLE_NAME, INDEX_NAME, "rule_change_uuid", "new_software_quality", "new_severity");
}

@Test
public void migration_should_be_reentrant() throws SQLException {
underTest.execute();
underTest.execute();

db.assertUniqueIndex(TABLE_NAME, INDEX_NAME, "rule_change_uuid", "new_software_quality", "new_severity");
}
}

+ 10
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v103/AddRuleChangesUuidColumnInQProfileChangesTest/schema.sql Dosyayı Görüntüle

@@ -0,0 +1,10 @@
CREATE TABLE "QPROFILE_CHANGES"(
"KEE" CHARACTER VARYING(40) NOT NULL,
"RULES_PROFILE_UUID" CHARACTER VARYING(255) NOT NULL,
"CHANGE_TYPE" CHARACTER VARYING(20) NOT NULL,
"USER_UUID" CHARACTER VARYING(255),
"CHANGE_DATA" CHARACTER LARGE OBJECT,
"CREATED_AT" BIGINT NOT NULL
);
ALTER TABLE "QPROFILE_CHANGES" ADD CONSTRAINT "PK_QPROFILE_CHANGES" PRIMARY KEY("KEE");
CREATE INDEX "QP_CHANGES_RULES_PROFILE_UUID" ON "QPROFILE_CHANGES"("RULES_PROFILE_UUID" NULLS FIRST);

+ 7
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v103/CreateUniqueIndexForRuleImpactChangesTableTest/schema.sql Dosyayı Görüntüle

@@ -0,0 +1,7 @@
CREATE TABLE "RULE_IMPACT_CHANGES"(
"NEW_SOFTWARE_QUALITY" CHARACTER VARYING(40) NOT NULL,
"OLD_SOFTWARE_QUALITY" CHARACTER VARYING(40) NOT NULL,
"NEW_SEVERITY" CHARACTER VARYING(40) NOT NULL,
"OLD_SEVERITY" CHARACTER VARYING(40) NOT NULL,
"RULE_CHANGE_UUID" CHARACTER VARYING(40) NOT NULL
);

Loading…
İptal
Kaydet