]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7329 Add RULES.RULE_TYPE column
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 29 Feb 2016 15:00:28 +0000 (16:00 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 29 Feb 2016 15:00:28 +0000 (16:00 +0100)
Reuse existing migration that add columns in rules table to decrease migration time

server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1100_add_rules_columns.rb [new file with mode: 0644]
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1100_add_rules_long_date_columns.rb [deleted file]
sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java
sonar-db/src/main/java/org/sonar/db/version/v55/AddRulesColumns.java [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/version/v55/AddRulesLongDateColumns.java [deleted file]
sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl
sonar-db/src/test/java/org/sonar/db/version/v55/AddRulesColumnsTest.java [new file with mode: 0644]
sonar-db/src/test/java/org/sonar/db/version/v55/AddRulesLongDateColumnsTest.java [deleted file]
sonar-db/src/test/resources/org/sonar/db/version/v55/AddRulesColumnsTest/schema.sql [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/version/v55/AddRulesLongDateColumnsTest/schema.sql [deleted file]

diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1100_add_rules_columns.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1100_add_rules_columns.rb
new file mode 100644 (file)
index 0000000..ccda643
--- /dev/null
@@ -0,0 +1,32 @@
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube 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.
+#
+# SonarQube 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.
+#
+
+#
+# SonarQube 5.5
+# SONAR-7329
+# SONAR-7330
+#
+class AddRulesColumns < ActiveRecord::Migration
+
+  def self.up
+    execute_java_migration('org.sonar.db.version.v55.AddRulesColumns')
+  end
+
+end
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_long_date_columns.rb
deleted file mode 100644 (file)
index 54db7d7..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-#
-# SonarQube, open source software quality management tool.
-# Copyright (C) 2008-2014 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# SonarQube 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.
-#
-# SonarQube 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.
-#
-
-#
-# SonarQube 5.5
-# SONAR-7330
-#
-class AddRulesLongDateColumns < ActiveRecord::Migration
-
-  def self.up
-    execute_java_migration('org.sonar.db.version.v55.AddRulesLongDateColumns')
-  end
-
-end
index 6859cac4175e8df2aa8d7500f410aac7072b491f..30ab456009ec6c164ade32274df270580c314201 100644 (file)
@@ -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/AddRulesColumns.java b/sonar-db/src/main/java/org/sonar/db/version/v55/AddRulesColumns.java
new file mode 100644 (file)
index 0000000..8b2d748
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.version.v55;
+
+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;
+
+/**
+ * Add the following columns to the rules table :
+ * - created_at_ms
+ * - updated_at_ms
+ * - rule_type
+ */
+public class AddRulesColumns extends DdlChange {
+
+  private final Database db;
+
+  public AddRulesColumns(Database db) {
+    super(db);
+    this.db = db;
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(generateSql());
+  }
+
+  private String generateSql() {
+    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/java/org/sonar/db/version/v55/AddRulesLongDateColumns.java b/sonar-db/src/main/java/org/sonar/db/version/v55/AddRulesLongDateColumns.java
deleted file mode 100644 (file)
index 727d927..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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.version.v55;
-
-import java.sql.SQLException;
-import org.sonar.db.Database;
-import org.sonar.db.version.AddColumnsBuilder;
-import org.sonar.db.version.DdlChange;
-
-import static org.sonar.db.version.BigDecimalColumnDef.newBigDecimalColumnDefBuilder;
-
-/**
- * Add the following columns to the rules table :
- * - created_at_ms
- * - updated_at_ms
- */
-public class AddRulesLongDateColumns extends DdlChange {
-
-  private final Database db;
-
-  public AddRulesLongDateColumns(Database db) {
-    super(db);
-    this.db = db;
-  }
-
-  @Override
-  public void execute(Context context) throws SQLException {
-    context.execute(generateSql());
-  }
-
-  private String generateSql() {
-    return new AddColumnsBuilder(db.getDialect(), "rules")
-      .addColumn(newBigDecimalColumnDefBuilder().setColumnName("created_at_ms").setIsNullable(true).build())
-      .addColumn(newBigDecimalColumnDefBuilder().setColumnName("updated_at_ms").setIsNullable(true).build())
-      .build();
-  }
-
-}
index 93c5661b02a715e6d723911389a95afcadbe09c5..e48a5310fbe748e07fae57efe6a23cffadc80d41 100644 (file)
@@ -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/AddRulesColumnsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v55/AddRulesColumnsTest.java
new file mode 100644 (file)
index 0000000..3750f9c
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.version.v55;
+
+import java.sql.Types;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+import org.sonar.db.version.MigrationStep;
+
+public class AddRulesColumnsTest {
+
+  @Rule
+  public DbTester db = DbTester.createForSchema(System2.INSTANCE, AddRulesColumnsTest.class, "schema.sql");
+
+  MigrationStep migration;
+
+  @Before
+  public void setUp() {
+    migration = new AddRulesColumns(db.database());
+  }
+
+  @Test
+  public void update_columns() throws Exception {
+    migration.execute();
+
+    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/java/org/sonar/db/version/v55/AddRulesLongDateColumnsTest.java b/sonar-db/src/test/java/org/sonar/db/version/v55/AddRulesLongDateColumnsTest.java
deleted file mode 100644 (file)
index 8e29ecb..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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.version.v55;
-
-import java.sql.Types;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.System2;
-import org.sonar.db.DbTester;
-import org.sonar.db.version.MigrationStep;
-
-public class AddRulesLongDateColumnsTest {
-
-  @Rule
-  public DbTester db = DbTester.createForSchema(System2.INSTANCE, AddRulesLongDateColumnsTest.class, "schema.sql");
-
-  MigrationStep migration;
-
-  @Before
-  public void setUp() {
-    migration = new AddRulesLongDateColumns(db.database());
-  }
-
-  @Test
-  public void update_columns() throws Exception {
-    migration.execute();
-
-    db.assertColumnDefinition("rules", "created_at_ms", Types.BIGINT, null);
-    db.assertColumnDefinition("rules", "updated_at_ms", Types.BIGINT, null);
-  }
-
-}
diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v55/AddRulesColumnsTest/schema.sql b/sonar-db/src/test/resources/org/sonar/db/version/v55/AddRulesColumnsTest/schema.sql
new file mode 100644 (file)
index 0000000..0c7c17f
--- /dev/null
@@ -0,0 +1,31 @@
+CREATE TABLE "RULES" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+  "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+  "DESCRIPTION" VARCHAR(16777215),
+  "DESCRIPTION_FORMAT" VARCHAR(20),
+  "PRIORITY" INTEGER,
+  "IS_TEMPLATE" BOOLEAN DEFAULT FALSE,
+  "TEMPLATE_ID" INTEGER,
+  "PLUGIN_CONFIG_KEY" VARCHAR(500),
+  "NAME" VARCHAR(200),
+  "STATUS" VARCHAR(40),
+  "LANGUAGE" VARCHAR(20),
+  "NOTE_DATA" CLOB(2147483647),
+  "NOTE_USER_LOGIN" VARCHAR(255),
+  "NOTE_CREATED_AT" TIMESTAMP,
+  "NOTE_UPDATED_AT" TIMESTAMP,
+  "CHARACTERISTIC_ID" INTEGER,
+  "DEFAULT_CHARACTERISTIC_ID" INTEGER,
+  "REMEDIATION_FUNCTION" VARCHAR(20),
+  "DEFAULT_REMEDIATION_FUNCTION" VARCHAR(20),
+  "REMEDIATION_COEFF" VARCHAR(20),
+  "DEFAULT_REMEDIATION_COEFF" VARCHAR(20),
+  "REMEDIATION_OFFSET" VARCHAR(20),
+  "DEFAULT_REMEDIATION_OFFSET" VARCHAR(20),
+  "EFFORT_TO_FIX_DESCRIPTION" VARCHAR(4000),
+  "TAGS" VARCHAR(4000),
+  "SYSTEM_TAGS" VARCHAR(4000),
+  "CREATED_AT" TIMESTAMP,
+  "UPDATED_AT" TIMESTAMP
+);
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/AddRulesLongDateColumnsTest/schema.sql
deleted file mode 100644 (file)
index 0c7c17f..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-CREATE TABLE "RULES" (
-  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
-  "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
-  "PLUGIN_NAME" VARCHAR(255) NOT NULL,
-  "DESCRIPTION" VARCHAR(16777215),
-  "DESCRIPTION_FORMAT" VARCHAR(20),
-  "PRIORITY" INTEGER,
-  "IS_TEMPLATE" BOOLEAN DEFAULT FALSE,
-  "TEMPLATE_ID" INTEGER,
-  "PLUGIN_CONFIG_KEY" VARCHAR(500),
-  "NAME" VARCHAR(200),
-  "STATUS" VARCHAR(40),
-  "LANGUAGE" VARCHAR(20),
-  "NOTE_DATA" CLOB(2147483647),
-  "NOTE_USER_LOGIN" VARCHAR(255),
-  "NOTE_CREATED_AT" TIMESTAMP,
-  "NOTE_UPDATED_AT" TIMESTAMP,
-  "CHARACTERISTIC_ID" INTEGER,
-  "DEFAULT_CHARACTERISTIC_ID" INTEGER,
-  "REMEDIATION_FUNCTION" VARCHAR(20),
-  "DEFAULT_REMEDIATION_FUNCTION" VARCHAR(20),
-  "REMEDIATION_COEFF" VARCHAR(20),
-  "DEFAULT_REMEDIATION_COEFF" VARCHAR(20),
-  "REMEDIATION_OFFSET" VARCHAR(20),
-  "DEFAULT_REMEDIATION_OFFSET" VARCHAR(20),
-  "EFFORT_TO_FIX_DESCRIPTION" VARCHAR(4000),
-  "TAGS" VARCHAR(4000),
-  "SYSTEM_TAGS" VARCHAR(4000),
-  "CREATED_AT" TIMESTAMP,
-  "UPDATED_AT" TIMESTAMP
-);