From 9e3d50f54b37411f5a0138ea8788fcb79b4a3058 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 25 Apr 2013 15:31:12 +0200 Subject: [PATCH] Fix migration on active rule changes by renaming user_name to username --- .../sonar/core/persistence/DatabaseVersion.java | 2 +- .../org/sonar/core/persistence/rows-h2.sql | 2 +- .../org/sonar/core/persistence/schema-h2.ddl | 2 +- .../org/sonar/api/measures/CoreMetrics.java | 5 +++++ .../org/sonar/api/rules/ActiveRuleChange.java | 13 ++----------- .../app/views/profiles/changelog.html.erb | 2 +- ...ctive_rule_changes_user_name_to_nullable.rb} | 17 +++++++++++++---- 7 files changed, 24 insertions(+), 19 deletions(-) rename sonar-server/src/main/webapp/WEB-INF/db/migrate/{384_update_active_rule_changes_user_name_to_nullable.rb => 392_update_active_rule_changes_user_name_to_nullable.rb} (66%) diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java index 703f03edf84..e5fd64348f0 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java @@ -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 diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql index dc7aa16b9b9..2618646ea53 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql @@ -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; diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl index 77f660d9bb0..0a9816efc1a 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl @@ -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, diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java index e8231cd201f..6937e575686 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java @@ -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) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRuleChange.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRuleChange.java index b8782a69132..630fd6cf605 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRuleChange.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRuleChange.java @@ -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) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/changelog.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/changelog.html.erb index d4cc7e83118..c78dd2d5547 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/changelog.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/changelog.html.erb @@ -31,7 +31,7 @@ <%= change.profile_version - 1 %> -> <%= change.profile_version %> <%= l(change.change_date) -%> - <%= change.user_name ? change.user_name : 'System' %> + <%= change.username ? change.username : 'System' %> <%= change.action_text %> <%= change.rule.name %> 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/392_update_active_rule_changes_user_name_to_nullable.rb similarity index 66% rename from sonar-server/src/main/webapp/WEB-INF/db/migrate/384_update_active_rule_changes_user_name_to_nullable.rb rename to sonar-server/src/main/webapp/WEB-INF/db/migrate/392_update_active_rule_changes_user_name_to_nullable.rb index a2b0362f64f..933f50991d2 100644 --- 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/392_update_active_rule_changes_user_name_to_nullable.rb @@ -23,10 +23,19 @@ # 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) + class ActiveRuleChange < ActiveRecord::Base end -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 -- 2.39.5