From 7fee2884113d0c01af954f68ed5ec8a910cc1921 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Mon, 29 Feb 2016 16:00:28 +0100 Subject: [PATCH] SONAR-7329 Add RULES.RULE_TYPE column Reuse existing migration that add columns in rules table to decrease migration time --- ...ules_long_date_columns.rb => 1100_add_rules_columns.rb} | 5 +++-- .../java/org/sonar/db/version/MigrationStepModule.java | 4 ++-- .../{AddRulesLongDateColumns.java => AddRulesColumns.java} | 7 +++++-- .../src/main/resources/org/sonar/db/version/schema-h2.ddl | 1 + ...esLongDateColumnsTest.java => AddRulesColumnsTest.java} | 7 ++++--- .../schema.sql | 0 6 files changed, 15 insertions(+), 9 deletions(-) rename server/sonar-web/src/main/webapp/WEB-INF/db/migrate/{1100_add_rules_long_date_columns.rb => 1100_add_rules_columns.rb} (87%) rename sonar-db/src/main/java/org/sonar/db/version/v55/{AddRulesLongDateColumns.java => AddRulesColumns.java} (87%) rename sonar-db/src/test/java/org/sonar/db/version/v55/{AddRulesLongDateColumnsTest.java => AddRulesColumnsTest.java} (87%) rename sonar-db/src/test/resources/org/sonar/db/version/v55/{AddRulesLongDateColumnsTest => AddRulesColumnsTest}/schema.sql (100%) diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1100_add_rules_long_date_columns.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1100_add_rules_columns.rb similarity index 87% rename from server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1100_add_rules_long_date_columns.rb rename to server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1100_add_rules_columns.rb index 54db7d77691..ccda643b6f5 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1100_add_rules_long_date_columns.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1100_add_rules_columns.rb @@ -20,12 +20,13 @@ # # SonarQube 5.5 +# SONAR-7329 # SONAR-7330 # -class AddRulesLongDateColumns < ActiveRecord::Migration +class AddRulesColumns < ActiveRecord::Migration def self.up - execute_java_migration('org.sonar.db.version.v55.AddRulesLongDateColumns') + execute_java_migration('org.sonar.db.version.v55.AddRulesColumns') end end diff --git a/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java b/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java index 6859cac4175..30ab456009e 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java +++ b/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java @@ -71,7 +71,7 @@ import org.sonar.db.version.v54.RemoveComponentPageProperties; import org.sonar.db.version.v54.RemovePreviewPermission; import org.sonar.db.version.v55.AddActiveRulesLongDateColumns; import org.sonar.db.version.v55.AddIssuesType; -import org.sonar.db.version.v55.AddRulesLongDateColumns; +import org.sonar.db.version.v55.AddRulesColumns; import org.sonar.db.version.v55.DeleteMeasuresWithCharacteristicId; import org.sonar.db.version.v55.DropActiveRulesDateColumns; import org.sonar.db.version.v55.DropRulesDateColumns; @@ -145,7 +145,7 @@ public class MigrationStepModule extends Module { IncreaseProjectsNameColumnsSize.class, // 5.5 - AddRulesLongDateColumns.class, + AddRulesColumns.class, FeedRulesLongDateColumns.class, DeleteMeasuresWithCharacteristicId.class, AddActiveRulesLongDateColumns.class, diff --git a/sonar-db/src/main/java/org/sonar/db/version/v55/AddRulesLongDateColumns.java b/sonar-db/src/main/java/org/sonar/db/version/v55/AddRulesColumns.java similarity index 87% rename from sonar-db/src/main/java/org/sonar/db/version/v55/AddRulesLongDateColumns.java rename to sonar-db/src/main/java/org/sonar/db/version/v55/AddRulesColumns.java index 727d927e2b8..8b2d748d521 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v55/AddRulesLongDateColumns.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v55/AddRulesColumns.java @@ -23,6 +23,7 @@ import java.sql.SQLException; import org.sonar.db.Database; import org.sonar.db.version.AddColumnsBuilder; import org.sonar.db.version.DdlChange; +import org.sonar.db.version.TinyIntColumnDef; import static org.sonar.db.version.BigDecimalColumnDef.newBigDecimalColumnDefBuilder; @@ -30,12 +31,13 @@ import static org.sonar.db.version.BigDecimalColumnDef.newBigDecimalColumnDefBui * Add the following columns to the rules table : * - created_at_ms * - updated_at_ms + * - rule_type */ -public class AddRulesLongDateColumns extends DdlChange { +public class AddRulesColumns extends DdlChange { private final Database db; - public AddRulesLongDateColumns(Database db) { + public AddRulesColumns(Database db) { super(db); this.db = db; } @@ -49,6 +51,7 @@ public class AddRulesLongDateColumns extends DdlChange { return new AddColumnsBuilder(db.getDialect(), "rules") .addColumn(newBigDecimalColumnDefBuilder().setColumnName("created_at_ms").setIsNullable(true).build()) .addColumn(newBigDecimalColumnDefBuilder().setColumnName("updated_at_ms").setIsNullable(true).build()) + .addColumn(new TinyIntColumnDef.Builder().setColumnName("rule_type").setIsNullable(true).build()) .build(); } diff --git a/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl b/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl index 93c5661b02a..e48a5310fbe 100644 --- a/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl +++ b/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl @@ -124,6 +124,7 @@ CREATE TABLE "RULES" ( "EFFORT_TO_FIX_DESCRIPTION" VARCHAR(4000), "TAGS" VARCHAR(4000), "SYSTEM_TAGS" VARCHAR(4000), + "RULE_TYPE" TINYINT, "CREATED_AT" BIGINT, "UPDATED_AT" BIGINT ); diff --git a/sonar-db/src/test/java/org/sonar/db/version/v55/AddRulesLongDateColumnsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v55/AddRulesColumnsTest.java similarity index 87% rename from sonar-db/src/test/java/org/sonar/db/version/v55/AddRulesLongDateColumnsTest.java rename to sonar-db/src/test/java/org/sonar/db/version/v55/AddRulesColumnsTest.java index 8e29ecb328b..3750f9cf924 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/v55/AddRulesLongDateColumnsTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/v55/AddRulesColumnsTest.java @@ -27,16 +27,16 @@ import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.db.version.MigrationStep; -public class AddRulesLongDateColumnsTest { +public class AddRulesColumnsTest { @Rule - public DbTester db = DbTester.createForSchema(System2.INSTANCE, AddRulesLongDateColumnsTest.class, "schema.sql"); + public DbTester db = DbTester.createForSchema(System2.INSTANCE, AddRulesColumnsTest.class, "schema.sql"); MigrationStep migration; @Before public void setUp() { - migration = new AddRulesLongDateColumns(db.database()); + migration = new AddRulesColumns(db.database()); } @Test @@ -45,6 +45,7 @@ public class AddRulesLongDateColumnsTest { db.assertColumnDefinition("rules", "created_at_ms", Types.BIGINT, null); db.assertColumnDefinition("rules", "updated_at_ms", Types.BIGINT, null); + db.assertColumnDefinition("rules", "rule_type", Types.TINYINT, null); } } diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v55/AddRulesLongDateColumnsTest/schema.sql b/sonar-db/src/test/resources/org/sonar/db/version/v55/AddRulesColumnsTest/schema.sql similarity index 100% rename from sonar-db/src/test/resources/org/sonar/db/version/v55/AddRulesLongDateColumnsTest/schema.sql rename to sonar-db/src/test/resources/org/sonar/db/version/v55/AddRulesColumnsTest/schema.sql -- 2.39.5