]> source.dussan.org Git - sonarqube.git/commitdiff
Fix migration on active rule changes by renaming user_name to username
authorJulien Lancelot <julien.lancelot@gmail.com>
Thu, 25 Apr 2013 13:31:12 +0000 (15:31 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Thu, 25 Apr 2013 13:31:12 +0000 (15:31 +0200)
sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql
sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java
sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRuleChange.java
sonar-server/src/main/webapp/WEB-INF/app/views/profiles/changelog.html.erb
sonar-server/src/main/webapp/WEB-INF/db/migrate/384_update_active_rule_changes_user_name_to_nullable.rb [deleted file]
sonar-server/src/main/webapp/WEB-INF/db/migrate/392_update_active_rule_changes_user_name_to_nullable.rb [new file with mode: 0644]

index 703f03edf845cc64735fb8ffe0cea55223d9d845..e5fd64348f01bcda15ef3d342867167b51c158a0 100644 (file)
@@ -32,7 +32,7 @@ import java.util.List;
  */
 public class DatabaseVersion implements BatchComponent, ServerComponent {
 
-  public static final int LAST_VERSION = 391;
+  public static final int LAST_VERSION = 392;
 
   public static enum Status {
     UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL
index dc7aa16b9b9a48da681d6a0254c8229219759b43..2618646ea537383ca8683cc9dd10544df2bf777f 100644 (file)
@@ -154,12 +154,12 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('380');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('381');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('382');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('383');
-INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('384');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('387');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('388');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('389');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('390');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('391');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('392');
 
 INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null);
 ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
index 77f660d9bb0fb90468708b6f878ea5de9cc5e23b..0a9816efc1a2b7c81263075bbc028343b667398d 100644 (file)
@@ -224,7 +224,7 @@ CREATE TABLE "REVIEW_COMMENTS" (
 
 CREATE TABLE "ACTIVE_RULE_CHANGES" (
   "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
-  "USER_NAME" VARCHAR(200),
+  "USERNAME" VARCHAR(200),
   "PROFILE_ID" INTEGER NOT NULL,
   "PROFILE_VERSION" INTEGER NOT NULL,
   "RULE_ID" INTEGER NOT NULL,
index e8231cd201fed97cc4915f8030e9a342d6cc79fc..6937e5756860cc21da79e6157492c5131c5780c9 100644 (file)
@@ -302,6 +302,11 @@ public final class CoreMetrics {
       .create();
 
   public static final String CLASS_COMPLEXITY_KEY = "class_complexity";
+
+  /**
+   * Information about the cyclomatic complexity per class, calculated by divided the complexity in classes by the number of classes.
+   * If the complexity in classes is not available, the complexity of the file is used.
+   */
   public static final Metric CLASS_COMPLEXITY = new Metric.Builder(CLASS_COMPLEXITY_KEY, "Complexity /class", Metric.ValueType.FLOAT)
       .setDescription("Complexity average by class")
       .setDirection(Metric.DIRECTION_WORST)
index b8782a69132e3c80bbbf3c03a1d83ad6bd1e19e5..630fd6cf6059fd8122bc50bc70700740fdaf04fb 100644 (file)
@@ -26,16 +26,7 @@ import org.apache.commons.lang.builder.ToStringStyle;
 import org.sonar.api.database.BaseIdentifiable;
 import org.sonar.api.profiles.RulesProfile;
 
-import javax.persistence.CascadeType;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.EnumType;
-import javax.persistence.Enumerated;
-import javax.persistence.FetchType;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.OneToMany;
-import javax.persistence.Table;
+import javax.persistence.*;
 
 import java.util.ArrayList;
 import java.util.Calendar;
@@ -51,7 +42,7 @@ import java.util.List;
 @Table(name = "active_rule_changes")
 public class ActiveRuleChange extends BaseIdentifiable {
 
-  @Column(name = "user_name", updatable = false, nullable = true)
+  @Column(name = "username", updatable = false, nullable = true)
   private String userName;
 
   @ManyToOne(fetch = FetchType.EAGER)
index d4cc7e8311825aaa8ddae0a418127907bc22acb8..c78dd2d55472d9b0d84634395c61840f9a1db574 100644 (file)
@@ -31,7 +31,7 @@
     <tr class="<%= cycle('even', 'odd') -%>">
       <td valign="top" width="1%" nowrap><%= change.profile_version - 1 %> -> <%= change.profile_version %></td>
       <td valign="top" width="1%" nowrap><%= l(change.change_date) -%></td>
-      <td valign="top" width="1%" nowrap><%= change.user_name ? change.user_name : 'System' %></td>
+      <td valign="top" width="1%" nowrap><%= change.username ? change.username : 'System' %></td>
       <td valign="top" width="1%" nowrap><%= change.action_text %></td>
       <td valign="top"><%= change.rule.name %></td>
       <td valign="top">
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/384_update_active_rule_changes_user_name_to_nullable.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/384_update_active_rule_changes_user_name_to_nullable.rb
deleted file mode 100644 (file)
index a2b0362..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-#
-# Sonar, entreprise quality control tool.
-# Copyright (C) 2008-2013 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.
-#
-
-#
-# Sonar 3.6
-#
-class UpdateActiveRuleChangesUserNameToNullable < ActiveRecord::Migration
-
-  def self.up
-    # Due to some Oracle limitation, we have to update also the limit in order to the change on nullable to be taken in account
-    change_column('active_rule_changes', 'user_name', :string, :limit => 201, :null => true)
-  end
-
-end
-
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/392_update_active_rule_changes_user_name_to_nullable.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/392_update_active_rule_changes_user_name_to_nullable.rb
new file mode 100644 (file)
index 0000000..933f509
--- /dev/null
@@ -0,0 +1,41 @@
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2008-2013 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.
+#
+
+#
+# Sonar 3.6
+#
+class UpdateActiveRuleChangesUserNameToNullable < ActiveRecord::Migration
+
+  class ActiveRuleChange < ActiveRecord::Base
+  end
+
+  def self.up
+    # Due to an issue on Oracle, it's not possible to use change_column to set a column to nullable, we had to create another column
+
+    add_column 'active_rule_changes', 'username', :string, :limit => 200, :null => true
+    ActiveRuleChange.reset_column_information
+    ActiveRuleChange.all.each do |a|
+      a.update_attributes!(:username => a.user_name)
+    end
+
+    remove_column 'active_rule_changes', 'user_name'
+  end
+
+end
\ No newline at end of file