*/
public class DatabaseVersion implements BatchComponent, ServerComponent {
- public static final int LAST_VERSION = 551;
+ public static final int LAST_VERSION = 553;
public static enum Status {
UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL
// migration of measures "profile" and "profile_version"
List<ProfileMeasure> selectProfileMeasures();
int selectProfileVersion(long snapshotId);
- @CheckForNull Date selectProfileVersionDate(@Param("profileId") long profileId, @Param("profileVersion") int profileVersion);
+ @CheckForNull Date selectProfileVersionDate(@Param("profileId") int profileId, @Param("profileVersion") int profileVersion);
void updateProfileMeasure(@Param("measureId") long measureId, @Param("json") String json);
// creation of columns RULES_PROFILES.CREATED_AT and UPDATED_AT
- @CheckForNull Date selectProfileCreatedAt(long profileId);
- @CheckForNull Date selectProfileUpdatedAt(long profileId);
+ @CheckForNull Date selectProfileCreatedAt(int profileId);
+ @CheckForNull Date selectProfileUpdatedAt(int profileId);
+ void updateProfileDates(@Param("profileId") int profileId, @Param("createdAt") Date createdAt, @Param("updatedAt") Date updatedAt);
// migrate changeLog to Activities
List<ChangeLog> selectActiveRuleChange(@Param("enabled") Boolean enabled);
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+import java.util.Date;
public class QualityProfileDto extends Dto<String> {
private String name;
private String language;
private String parentKee;
+ private Date createdAt, updatedAt, rulesUpdatedAt;
/**
* @deprecated use {@link #createFor(String)}
return this;
}
+ public Date getCreatedAt() {
+ return createdAt;
+ }
+
+ public void setCreatedAt(Date createdAt) {
+ this.createdAt = createdAt;
+ }
+
+ public Date getUpdatedAt() {
+ return updatedAt;
+ }
+
+ public void setUpdatedAt(Date updatedAt) {
+ this.updatedAt = updatedAt;
+ }
+
public static QualityProfileDto createFor(String key) {
return new QualityProfileDto().setKee(key);
}
void update(QualityProfileDto dto);
- void delete(Integer id);
+ void delete(int id);
List<QualityProfileDto> selectAll();
where id=#{measureId}
</update>
- <select id="selectProfileUpdateAt" resultType="date" parameterType="long">
+ <select id="selectProfileUpdatedAt" resultType="date" parameterType="int">
select max(change_date) from active_rule_changes
where profile_id=#{id}
</select>
- <select id="selectProfileCreatedAt" resultType="date" parameterType="long">
+ <select id="selectProfileCreatedAt" resultType="date" parameterType="int">
select min(change_date) from active_rule_changes
where profile_id=#{id}
</select>
+ <update id="updateProfileDates" parameterType="map">
+ update rules_profiles
+ set created_at=#{createdAt}, updated_at=#{updatedAt}, rules_updated_at=#{updatedAt}
+ where id=#{profileId}
+ </update>
+
<select id="selectActiveRuleChange" parameterType="Boolean"
resultType="org.sonar.core.persistence.migration.v44.ChangeLog">
select
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('548');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('549');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('551');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('552');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('553');
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;
"NAME" VARCHAR(100) NOT NULL,
"LANGUAGE" VARCHAR(20),
"KEE" VARCHAR(1000) NOT NULL,
- "PARENT_KEE" VARCHAR(1000)
+ "PARENT_KEE" VARCHAR(1000),
+ "RULES_UPDATED_AT" TIMESTAMP,
+ "CREATED_AT" TIMESTAMP,
+ "UPDATED_AT" TIMESTAMP
);
CREATE TABLE "WIDGETS" (
--- /dev/null
+/*
+ * 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.
+ */
+package org.sonar.core.persistence.migration.v44;
+
+import org.junit.Test;
+
+import static com.google.code.beanmatchers.BeanMatchers.*;
+import static org.hamcrest.Matchers.allOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class ProfileMeasureTest {
+
+ @Test
+ public void getId() throws Exception {
+ assertThat(ProfileMeasure.class, allOf(
+ hasValidBeanConstructor(),
+ hasValidGettersAndSetters()
+ ));
+ }
+}
<dataset>
- <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way"/>
+ <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way"
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
</dataset>
<dataset>
- <rules_profiles id="1" name="Child1" language="java" parent_kee="java_parent" kee="java_child1"/>
+ <rules_profiles id="1" name="Child1" language="java" parent_kee="java_parent" kee="java_child1"
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
- <rules_profiles id="2" name="Child2" language="java" parent_kee="java_parent" kee="java_child2"/>
+ <rules_profiles id="2" name="Child2" language="java" parent_kee="java_parent" kee="java_child2"
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
- <rules_profiles id="3" name="Parent" language="java" parent_kee="[null]" kee="java_parent"/>
+ <rules_profiles id="3" name="Parent" language="java" parent_kee="[null]" kee="java_parent"
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
<!-- Same profile for another language -->
- <rules_profiles id="4" name="Child1" language="js" parent_kee="js_parent" kee="js_child1"/>
+ <rules_profiles id="4" name="Child1" language="js" parent_kee="js_parent" kee="js_child1"
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
- <rules_profiles id="5" name="Child2" language="js" parent_kee="js_parent" kee="js_child2"/>
+ <rules_profiles id="5" name="Child2" language="js" parent_kee="js_parent" kee="js_child2"
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
- <rules_profiles id="6" name="Parent" language="js" parent_kee="[null]" kee="js_parent"/>
+ <rules_profiles id="6" name="Parent" language="js" parent_kee="[null]" kee="js_parent"
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
</dataset>
<dataset>
- <rules_profiles id="1" name="Sonar Way" language="java" parent_kee="[null]" kee="java_sonar_way"/>
+ <rules_profiles id="1" name="Sonar Way" language="java" parent_kee="[null]" kee="java_sonar_way"
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
- <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way"/>
+ <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way"
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
- <rules_profiles id="3" name="ABCDE" language="xoo" parent_kee="[null]" kee="abcde"/>
+ <rules_profiles id="3" name="ABCDE" language="xoo" parent_kee="[null]" kee="abcde"
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
</dataset>
<dataset>
- <rules_profiles id="1" name="Sonar Way" language="java" parent_kee="[null]" kee="java_sonar_way"/>
- <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way"/>
+ <rules_profiles id="1" name="Sonar Way" language="java" parent_kee="[null]" kee="java_sonar_way"
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
+ <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way"
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
<projects id="1" kee="org.codehaus.sonar:sonar" name="SonarQube"/>
<projects id="2" kee="org.codehaus.sonar-plugins.java:java" name="SonarQube Java"/>
<dataset>
- <rules_profiles id="3" name="Third" language="js" parent_kee="[null]" kee="js_third"/>
+ <rules_profiles id="3" name="Third" language="js" parent_kee="[null]" kee="js_third"
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
- <rules_profiles id="1" name="First" language="js" parent_kee="[null]" kee="js_first"/>
+ <rules_profiles id="1" name="First" language="js" parent_kee="[null]" kee="js_first"
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
- <rules_profiles id="2" name="Second" language="js" parent_kee="[null]" kee="js_second"/>
+ <rules_profiles id="2" name="Second" language="js" parent_kee="[null]" kee="js_second"
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
</dataset>
<dataset>
- <rules_profiles id="1" name="Sonar Way 1" language="java" parent_kee="[null]" kee="java_sonar_way"/>
+ <rules_profiles id="1" name="Sonar Way 1" language="java" parent_kee="[null]" kee="java_sonar_way"
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
<rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way"
- used_profile="[false]"/>
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
- <rules_profiles id="3" name="Sonar Way 2" language="java" parent_kee="[null]" kee="java_sonar_way2"/>
+ <rules_profiles id="3" name="Sonar Way 2" language="java" parent_kee="[null]" kee="java_sonar_way2"
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
</dataset>
<dataset>
- <rules_profiles id="1" name="Sonar Way" language="java" parent_kee="[null]" kee="java_sonar_way"/>
+ <rules_profiles id="1" name="Sonar Way" language="java" parent_kee="[null]" kee="java_sonar_way"
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
- <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way"/>
+ <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way"
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
<properties id="1" prop_key="sonar.profile.java" text_value="Sonar Way" resource_id="[null]"/>
<properties id="2" prop_key="sonar.profile.java" text_value="Sonar Way" resource_id="1"/>
<dataset>
- <rules_profiles id="1" name="New Name" language="js" parent_kee="fghij" kee="java_sonar_way"/>
+ <rules_profiles id="1" name="New Name" language="js" parent_kee="fghij" kee="java_sonar_way"
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
- <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way"/>
+ <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way"
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
</dataset>
+++ /dev/null
-<dataset>
-
- <rules tags="[null]" system_tags="[null]" id="1" name="rule one" description="desc" plugin_config_key="config"
- plugin_rule_key="rule_one" plugin_name="plugin1" status="READY" is_template="[false]" template_id="[null]"/>
-
- <rules tags="[null]" system_tags="[null]" id="2" name="rule two" description="desc" plugin_config_key="config"
- plugin_rule_key="rule_two" plugin_name="plugin2" status="READY" is_template="[false]" template_id="[null]"/>
- <rules tags="[null]" system_tags="[null]" id="3" name="rule three" description="desc" plugin_config_key="config"
- plugin_rule_key="rule_three" plugin_name="plugin2" status="READY" is_template="[false]" template_id="[null]"/>
-
- <rules tags="[null]" system_tags="[null]" id="4" name="rule 4" description="desc" plugin_config_key="config"
- plugin_rule_key="rule_4" plugin_name="plugin2" status="READY" is_template="[false]" template_id="[null]"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <rules tags="[null]" system_tags="[null]" id="1" name="rule1" description="desc" plugin_config_key="config"
- plugin_rule_key="key1" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
-
- <rules_parameters id="1" rule_id="1" name="param1" description="[null]" param_type="REGULAR_EXPRESSION"/>
- <rules_parameters id="2" rule_id="1" name="param2" description="[null]" param_type="REGULAR_EXPRESSION"/>
-
- <rules_profiles id="1" name="profile1" language="java"/>
- <rules_profiles id="2" name="profile2" language="OTHER"/>
-
- <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="1" failure_level="2"/>
- <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="2" rule_id="1" failure_level="2"/>
-
- <!-- deleted -->
- <!--<active_rule_parameters id="1" active_rule_id="1" rules_parameter_id="1" value="20"/>-->
- <!--<active_rule_parameters id="2" active_rule_id="2" rules_parameter_id="1" value="15"/>-->
- <active_rule_parameters id="3" active_rule_id="2" rules_parameter_id="2" value="15"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <rules tags="[null]" system_tags="[null]" id="1" name="rule1" description="desc" plugin_config_key="config"
- plugin_rule_key="key1" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
-
- <rules_parameters id="1" rule_id="1" name="param1" description="foo" param_type="REGULAR_EXPRESSION"/>
- <rules_parameters id="2" rule_id="1" name="param2" description="foo" param_type="REGULAR_EXPRESSION"/>
-
- <rules_profiles id="1" name="profile1" language="java"/>
- <rules_profiles id="2" name="profile2" language="OTHER"/>
-
- <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="1" failure_level="2"/>
- <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="2" rule_id="1" failure_level="2"/>
-
- <active_rule_parameters id="1" active_rule_id="1" rules_parameter_id="1" value="20"/>
- <active_rule_parameters id="2" active_rule_id="2" rules_parameter_id="1" value="15"/>
- <active_rule_parameters id="3" active_rule_id="2" rules_parameter_id="2" value="15"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <rules_profiles id="1" name="profile one" language="java"/>
- <rules_profiles id="2" name="profile two" language="java"/>
-
- <rules tags="[null]" system_tags="[null]" id="1" name="foo" description="test" plugin_config_key="checker/foo"
- plugin_rule_key="checkstyle.rule1" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
- <rules tags="[null]" system_tags="[null]" id="2" name="bar" description="test" plugin_config_key="checker/bar"
- plugin_rule_key="checkstyle.rule2" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
- <rules tags="[null]" system_tags="[null]" id="3" name="baz" description="test" plugin_config_key="checker/baz"
- plugin_rule_key="checkstyle.rule3" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
-
- <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="1" failure_level="2"/>
- <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="1" rule_id="2" failure_level="2"/>
- <active_rules created_at="[null]" updated_at="[null]" id="3" profile_id="1" rule_id="3" failure_level="2"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <rules_profiles id="1" name="profile one" language="java" />
- <rules_profiles id="2" name="profile two" language="java" />
-
- <rules tags="[null]" system_tags="[null]" id="1" name="foo" description="test" plugin_config_key="checker/foo"
- plugin_rule_key="checkstyle.rule1" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
- <rules tags="[null]" system_tags="[null]" id="2" name="bar" description="test" plugin_config_key="checker/bar"
- plugin_rule_key="checkstyle.rule2" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
- <rules tags="[null]" system_tags="[null]" id="3" name="baz" description="test" plugin_config_key="checker/baz"
- plugin_rule_key="checkstyle.rule3" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
-
- <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="1" failure_level="2"/>
- <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="1" rule_id="2" failure_level="2"/>
- <active_rules created_at="[null]" updated_at="[null]" id="3" profile_id="1" rule_id="3" failure_level="2"/>
-
- <active_rules created_at="[null]" updated_at="[null]" id="4" profile_id="2" rule_id="1" failure_level="2"/>
- <active_rules created_at="[null]" updated_at="[null]" id="5" profile_id="2" rule_id="2" failure_level="2"/>
- <active_rules created_at="[null]" updated_at="[null]" id="6" profile_id="2" rule_id="3" failure_level="2"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <rules_profiles id="1" name="profile one" language="java" />
- <rules_profiles id="2" name="profile two" language="java" />
-
- <rules tags="[null]" system_tags="[null]" id="1" name="foo" description="test" plugin_config_key="checker/foo"
- plugin_rule_key="checkstyle.rule1" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
- <rules tags="[null]" system_tags="[null]" id="2" name="bar" description="test" plugin_config_key="checker/bar"
- plugin_rule_key="checkstyle.rule2" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
- <rules tags="[null]" system_tags="[null]" id="3" name="baz" description="test" plugin_config_key="checker/baz"
- plugin_rule_key="checkstyle.rule3" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
-
- <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="1" failure_level="2"/>
- <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="1" rule_id="2" failure_level="2"/>
- <active_rules created_at="[null]" updated_at="[null]" id="3" profile_id="1" rule_id="3" failure_level="2"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <!-- Rules -->
- <rules tags="[null]" system_tags="[null]" id="1" name="new1" description="test1" plugin_config_key="checker/new1"
- plugin_rule_key="checkstyle.new1" plugin_name="PLUGIN_KEY" status="READY" is_template="[false]" template_id="[null]"/>
- <rules tags="[null]" system_tags="[null]" id="2" name="new2" description="test2" plugin_config_key="checker/new2"
- plugin_rule_key="checkstyle.new2" plugin_name="PLUGIN_KEY" status="READY" is_template="[false]" template_id="[null]"/>
-
- <!-- Rules parameters -->
- <rules_parameters id="1" rule_id="1" name="rule1_param1" description="rule1_desc1" param_type="REGULAR_EXPRESSION"
- />
- <rules_parameters id="2" rule_id="1" name="rule1_param2" description="rule1_desc2" param_type="REGULAR_EXPRESSION"
- />
- <rules_parameters id="3" rule_id="2" name="rule2_param1" description="rule2_desc1" param_type="REGULAR_EXPRESSION"
- />
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <rules tags="[null]" system_tags="[null]" id="1" name="foo" description="test" plugin_config_key="checker/foo"
- plugin_rule_key="checkstyle.rule1" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <rules tags="[null]" system_tags="[null]" id="1" name="rule one" description="desc" plugin_config_key="other config"
- plugin_rule_key="rule_one" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
- <rules tags="[null]" system_tags="[null]" id="2" name="rule two" description="desc" plugin_config_key="config"
- plugin_rule_key="rule_two" plugin_name="other plugin" status="READY" is_template="[false]" template_id="[null]"/>
-
- <rules_parameters id="1" rule_id="1" name="rule1_param1" description="rule1_desc1" param_type="REGULAR_EXPRESSION"
- />
- <rules_parameters id="2" rule_id="2" name="rule2_param1" description="rule2_desc1" param_type="REGULAR_EXPRESSION"
- />
-
-</dataset>
import org.sonar.server.db.migrations.v43.TechnicalDebtMeasuresMigration;
import org.sonar.server.db.migrations.v44.ChangeLogMigration;
import org.sonar.server.db.migrations.v44.ConvertProfileMeasures;
+import org.sonar.server.db.migrations.v44.FeedQProfileDatesMigration;
+import org.sonar.server.db.migrations.v44.FeedQProfileKeysMigration;
import org.sonar.server.db.migrations.v44.IssueActionPlanKeyMigration;
import org.sonar.server.db.migrations.v44.MeasureDataMigration;
-import org.sonar.server.db.migrations.v44.QProfileKeyMigration;
import java.util.List;
// 4.4
IssueActionPlanKeyMigration.class,
MeasureDataMigration.class,
- QProfileKeyMigration.class,
+ FeedQProfileKeysMigration.class,
+ FeedQProfileDatesMigration.class,
ChangeLogMigration.class,
ConvertProfileMeasures.class
);
--- /dev/null
+/*
+ * 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.
+ */
+
+package org.sonar.server.db.migrations.v44;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.commons.lang.ObjectUtils;
+import org.sonar.api.utils.System2;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.core.persistence.migration.v44.Migration44Mapper;
+import org.sonar.core.qualityprofile.db.QualityProfileDto;
+import org.sonar.core.qualityprofile.db.QualityProfileMapper;
+import org.sonar.server.db.DbClient;
+import org.sonar.server.db.migrations.DatabaseMigration;
+
+import java.util.Date;
+
+/**
+ * Feed the new columns RULES_PROFILES.CREATED_AT and UPDATED_AT
+ *
+ * @since 4.4
+ */
+public class FeedQProfileDatesMigration implements DatabaseMigration {
+
+ private final DbClient db;
+ private final System2 system;
+
+ @VisibleForTesting
+ FeedQProfileDatesMigration(DbClient db, System2 system) {
+ this.db = db;
+ this.system = system;
+ }
+
+ public FeedQProfileDatesMigration(DbClient db) {
+ this(db, System2.INSTANCE);
+ }
+
+ @Override
+ public void execute() {
+ DbSession session = db.openSession(false);
+ try {
+ Date now = new Date(system.now());
+ int i = 0;
+ QualityProfileMapper profileMapper = session.getMapper(QualityProfileMapper.class);
+ Migration44Mapper migrationMapper = session.getMapper(Migration44Mapper.class);
+ for (QualityProfileDto profile : profileMapper.selectAll()) {
+ Date createdAt = migrationMapper.selectProfileCreatedAt(profile.getId());
+ Date updatedAt = migrationMapper.selectProfileUpdatedAt(profile.getId());
+ migrationMapper.updateProfileDates(profile.getId(),
+ (Date) ObjectUtils.defaultIfNull(createdAt, now), (Date) ObjectUtils.defaultIfNull(updatedAt, now));
+ if (i % 100 == 0) {
+ session.commit();
+ i++;
+ }
+ }
+ session.commit();
+ } finally {
+ session.close();
+ }
+ }
+}
--- /dev/null
+/*
+ * 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.
+ */
+
+package org.sonar.server.db.migrations.v44;
+
+import org.sonar.core.persistence.Database;
+import org.sonar.server.db.migrations.DatabaseMigration;
+import org.sonar.server.db.migrations.MassUpdater;
+import org.sonar.server.db.migrations.SqlUtil;
+import org.sonar.server.util.Slug;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * Feed the new columns RULES_PROFILES.KEE and PARENT_KEE.
+ *
+ * @since 4.4
+ */
+public class FeedQProfileKeysMigration implements DatabaseMigration {
+
+ private final Database db;
+
+ public FeedQProfileKeysMigration(Database database) {
+ this.db = database;
+ }
+
+ @Override
+ public void execute() {
+ updateKeys();
+ updateParentKeys();
+ }
+
+ private void updateKeys() {
+ new MassUpdater(db, 100).execute(
+ new MassUpdater.InputLoader<Row>() {
+ @Override
+ public String selectSql() {
+ return "SELECT id,language,name FROM rules_profiles";
+ }
+
+ @Override
+ public Row load(ResultSet rs) throws SQLException {
+ Row row = new Row();
+ row.id = SqlUtil.getLong(rs, 1);
+ row.lang = rs.getString(2);
+ row.name = rs.getString(3);
+ return row;
+ }
+ },
+ new MassUpdater.InputConverter<Row>() {
+
+ @Override
+ public String updateSql() {
+ return "UPDATE rules_profiles SET kee=? WHERE id=?";
+ }
+
+ @Override
+ public boolean convert(Row row, PreparedStatement updateStatement) throws SQLException {
+ updateStatement.setString(1, Slug.slugify(String.format("%s %s", row.lang, row.name)));
+ updateStatement.setLong(2, row.id);
+ return true;
+ }
+ }
+ );
+ }
+
+ private void updateParentKeys() {
+ new MassUpdater(db, 100).execute(
+ new MassUpdater.InputLoader<Row>() {
+ @Override
+ public String selectSql() {
+ return "SELECT child.id,parent.kee FROM rules_profiles child, rules_profiles parent WHERE child.parent_name=parent.name " +
+ "and child.language=parent.language AND child.parent_name IS NOT NULL";
+ }
+
+ @Override
+ public Row load(ResultSet rs) throws SQLException {
+ Row row = new Row();
+ row.id = SqlUtil.getLong(rs, 1);
+ row.parentKey = rs.getString(2);
+ return row;
+ }
+ },
+ new MassUpdater.InputConverter<Row>() {
+
+ @Override
+ public String updateSql() {
+ return "UPDATE rules_profiles SET parent_kee=? WHERE id=?";
+ }
+
+ @Override
+ public boolean convert(Row row, PreparedStatement updateStatement) throws SQLException {
+ updateStatement.setString(1, row.parentKey);
+ updateStatement.setLong(2, row.id);
+ return true;
+ }
+ }
+ );
+ }
+
+ private static class Row {
+ private Long id;
+ private String lang, name, parentKey;
+ }
+}
+++ /dev/null
-/*
- * 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.
- */
-
-package org.sonar.server.db.migrations.v44;
-
-import org.sonar.core.persistence.Database;
-import org.sonar.server.db.migrations.DatabaseMigration;
-import org.sonar.server.db.migrations.MassUpdater;
-import org.sonar.server.db.migrations.SqlUtil;
-import org.sonar.server.util.Slug;
-
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
-/**
- * Feed the new columns RULES_PROFILE.KEE and PARENT_KEE.
- *
- * @since 4.4
- */
-public class QProfileKeyMigration implements DatabaseMigration {
-
- private final Database db;
-
- public QProfileKeyMigration(Database database) {
- this.db = database;
- }
-
- @Override
- public void execute() {
- updateKeys();
- updateParentKeys();
- }
-
- private void updateKeys() {
- new MassUpdater(db, 100).execute(
- new MassUpdater.InputLoader<Row>() {
- @Override
- public String selectSql() {
- return "SELECT id,language,name FROM rules_profiles";
- }
-
- @Override
- public Row load(ResultSet rs) throws SQLException {
- Row row = new Row();
- row.id = SqlUtil.getLong(rs, 1);
- row.lang = rs.getString(2);
- row.name = rs.getString(3);
- return row;
- }
- },
- new MassUpdater.InputConverter<Row>() {
-
- @Override
- public String updateSql() {
- return "UPDATE rules_profiles SET kee=? WHERE id=?";
- }
-
- @Override
- public boolean convert(Row row, PreparedStatement updateStatement) throws SQLException {
- updateStatement.setString(1, Slug.slugify(String.format("%s %s", row.lang, row.name)));
- updateStatement.setLong(2, row.id);
- return true;
- }
- }
- );
- }
-
- private void updateParentKeys() {
- new MassUpdater(db, 100).execute(
- new MassUpdater.InputLoader<Row>() {
- @Override
- public String selectSql() {
- return "SELECT child.id,parent.kee FROM rules_profiles child, rules_profiles parent WHERE child.parent_name=parent.name " +
- "and child.language=parent.language AND child.parent_name IS NOT NULL";
- }
-
- @Override
- public Row load(ResultSet rs) throws SQLException {
- Row row = new Row();
- row.id = SqlUtil.getLong(rs, 1);
- row.parentKey = rs.getString(2);
- return row;
- }
- },
- new MassUpdater.InputConverter<Row>() {
-
- @Override
- public String updateSql() {
- return "UPDATE rules_profiles SET parent_kee=? WHERE id=?";
- }
-
- @Override
- public boolean convert(Row row, PreparedStatement updateStatement) throws SQLException {
- updateStatement.setString(1, row.parentKey);
- updateStatement.setLong(2, row.id);
- return true;
- }
- }
- );
- }
-
- private static class Row {
- private Long id;
- private String lang, name, parentKey;
- }
-}
--- /dev/null
+#
+# 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 4.4
+# SONAR-5384
+#
+class FeedQprofileKeys < ActiveRecord::Migration
+
+ def self.up
+ execute_java_migration('org.sonar.server.db.migrations.v44.FeedQProfileKeysMigration')
+
+ # set as non-null and unique
+ change_column :rules_profiles, :kee, :string, :limit => 1000, :null => false
+ add_index :rules_profiles, :kee, :name => 'uniq_qprof_key', :unique => true
+
+ remove_column :rules_profiles, :parent_name
+ remove_column :rules_profiles, :version
+ remove_column :rules_profiles, :used_profile
+ end
+
+end
+++ /dev/null
-#
-# 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 4.4
-# SONAR-5384
-#
-class SetQprofileKeys < ActiveRecord::Migration
-
- def self.up
- Java::OrgSonarServerUi::JRubyFacade.getInstance().databaseMigrator().executeMigration('org.sonar.server.db.migrations.v44.QProfileKeyMigration')
-
- # set as non-null and unique
- change_column :rules_profiles, :kee, :string, :limit => 1000, :null => false
- add_index :rules_profiles, :kee, :name => 'uniq_qprof_key', :unique => true
-
- remove_column :rules_profiles, :parent_name
- remove_column :rules_profiles, :version
- remove_column :rules_profiles, :used_profile
- end
-
-end
end
def self.up
- Java::OrgSonarServerUi::JRubyFacade.getInstance().databaseMigrator().executeMigration('org.sonar.server.db.migrations.v44.ConvertProfileMeasures')
+ execute_java_migration('org.sonar.server.db.migrations.v44.ConvertProfileMeasures')
Metric.reset_column_information
metric = Metric.find_by_name('profile')
class UpdateLogsToActivities < ActiveRecord::Migration
def self.up
- Java::OrgSonarServerUi::JRubyFacade.getInstance().databaseMigrator().executeMigration('org.sonar.server.db.migrations.v44.ChangeLogMigration')
+ execute_java_migration('org.sonar.server.db.migrations.v44.ChangeLogMigration')
end
end
--- /dev/null
+#
+# 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 4.4
+#
+class AddQprofileDates < ActiveRecord::Migration
+
+ def self.up
+ add_column :rules_profiles, :rules_updated_at, :datetime, :null => true
+ add_column :rules_profiles, :created_at, :datetime, :null => true
+ add_column :rules_profiles, :updated_at, :datetime, :null => true
+ end
+
+end
--- /dev/null
+#
+# 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 4.4
+#
+class FeedQprofileDates < ActiveRecord::Migration
+
+ def self.up
+ execute_java_migration 'org.sonar.server.db.migrations.v44.FeedQProfileDatesMigration'
+ end
+
+end
--- /dev/null
+/*
+ * 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.
+ */
+
+package org.sonar.server.db.migrations.v44;
+
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonar.api.utils.DateUtils;
+import org.sonar.api.utils.System2;
+import org.sonar.core.persistence.TestDatabase;
+import org.sonar.server.db.DbClient;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class FeedQProfileDatesMigrationTest {
+
+ @ClassRule
+ public static TestDatabase db = new TestDatabase().schema(FeedQProfileDatesMigrationTest.class, "schema.sql");
+
+ FeedQProfileDatesMigration migration;
+
+ @Before
+ public void setUp() throws Exception {
+ DbClient dbClient = new DbClient(db.database(), db.myBatis());
+ System2 system = mock(System2.class);
+ when(system.now()).thenReturn(DateUtils.parseDate("2014-07-03").getTime());
+ migration = new FeedQProfileDatesMigration(dbClient, system);
+ }
+
+ @Test
+ public void feed_created_at_and_updated_at() throws Exception {
+ db.prepareDbUnit(getClass(), "feed_created_at_and_updated_at.xml");
+
+ migration.execute();
+
+ db.assertDbUnit(getClass(), "feed_created_at_and_updated_at_result.xml", "rules_profiles");
+ }
+
+ @Test
+ public void use_default_dates_when_no_changes() throws Exception {
+ db.prepareDbUnit(getClass(), "use_default_dates_when_no_changes.xml");
+
+ migration.execute();
+
+ db.assertDbUnit(getClass(), "use_default_dates_when_no_changes_result.xml", "rules_profiles");
+ }
+
+}
--- /dev/null
+<?xml version='1.0' encoding='UTF-8'?>
+<dataset>
+
+ <rules_profiles id="10" name="Sonar Way" language="java" kee="java-sw" parent_kee="[null]"
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
+
+ <!-- oldest to newest changes -->
+ <active_rule_changes id="122" profile_id="10" profile_version="2" rule_id="1" change_date="2011-12-25 20:20:05.158"
+ enabled="true" old_severity="[null]" new_severity="1" username="robert"/>
+
+ <active_rule_changes id="123" profile_id="10" profile_version="2" rule_id="1" change_date="2013-05-18 10:20:05.158"
+ enabled="[null]" old_severity="1" new_severity="4" username="lucie"/>
+
+ <active_rule_changes id="126" profile_id="10" profile_version="3" rule_id="1" change_date="2014-01-24 20:20:05.158"
+ enabled="[null]" old_severity="[null]" new_severity="[null]" username="tatiana"/>
+
+ <!-- another profile -->
+ <active_rule_changes id="124" profile_id="11" profile_version="1" rule_id="2" change_date="2011-12-05 20:20:05.158"
+ enabled="true" old_severity="[null]" new_severity="1" username="Administrator"/>
+
+</dataset>
--- /dev/null
+<?xml version='1.0' encoding='UTF-8'?>
+<dataset>
+
+ <rules_profiles id="10" name="Sonar Way" language="java" kee="java-sw" parent_kee="[null]"
+ rules_updated_at="2014-01-24 20:20:05.158" created_at="2011-12-25 20:20:05.158" updated_at="2014-01-24 20:20:05.158"/>
+
+ <!-- oldest to newest changes -->
+ <active_rule_changes id="122" profile_id="10" profile_version="2" rule_id="1" change_date="2011-12-25 20:20:05.158"
+ enabled="true" old_severity="[null]" new_severity="1" username="robert"/>
+
+ <active_rule_changes id="123" profile_id="10" profile_version="2" rule_id="1" change_date="2013-05-18 10:20:05.158"
+ enabled="[null]" old_severity="1" new_severity="4" username="lucie"/>
+
+ <active_rule_changes id="126" profile_id="10" profile_version="3" rule_id="1" change_date="2014-01-24 20:20:05.158"
+ enabled="[null]" old_severity="[null]" new_severity="[null]" username="tatiana"/>
+
+ <!-- another profile -->
+ <active_rule_changes id="124" profile_id="11" profile_version="1" rule_id="2" change_date="2011-12-05 20:20:05.158"
+ enabled="true" old_severity="[null]" new_severity="1" username="Administrator"/>
+
+</dataset>
--- /dev/null
+CREATE TABLE "RULES_PROFILES" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "NAME" VARCHAR(100) NOT NULL,
+ "LANGUAGE" VARCHAR(20),
+ "KEE" VARCHAR(1000) NOT NULL,
+ "PARENT_KEE" VARCHAR(1000),
+ "RULES_UPDATED_AT" TIMESTAMP,
+ "CREATED_AT" TIMESTAMP,
+ "UPDATED_AT" TIMESTAMP
+);
+
+CREATE TABLE "ACTIVE_RULE_CHANGES" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "USERNAME" VARCHAR(255),
+ "PROFILE_ID" INTEGER NOT NULL,
+ "PROFILE_VERSION" INTEGER NOT NULL,
+ "RULE_ID" INTEGER NOT NULL,
+ "CHANGE_DATE" TIMESTAMP NOT NULL,
+ "ENABLED" BOOLEAN,
+ "OLD_SEVERITY" INTEGER,
+ "NEW_SEVERITY" INTEGER
+);
+
+CREATE TABLE "ACTIVE_RULE_PARAM_CHANGES" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "ACTIVE_RULE_CHANGE_ID" INTEGER NOT NULL,
+ "RULES_PARAMETER_ID" INTEGER NOT NULL,
+ "OLD_VALUE" VARCHAR(4000),
+ "NEW_VALUE" VARCHAR(4000)
+ );
--- /dev/null
+<?xml version='1.0' encoding='UTF-8'?>
+<dataset>
+
+ <rules_profiles id="10" name="Sonar Way" language="java" kee="java-sw" parent_kee="[null]"
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
+
+
+ <!-- another profile -->
+ <active_rule_changes id="124" profile_id="11" profile_version="1" rule_id="2" change_date="2011-12-05 20:20:05.158"
+ enabled="true" old_severity="[null]" new_severity="1" username="Administrator"/>
+
+</dataset>
--- /dev/null
+<?xml version='1.0' encoding='UTF-8'?>
+<dataset>
+
+ <rules_profiles id="10" name="Sonar Way" language="java" kee="java-sw" parent_kee="[null]"
+ rules_updated_at="2014-07-03" created_at="2014-07-03" updated_at="2014-07-03"/>
+
+
+ <!-- another profile -->
+ <active_rule_changes id="124" profile_id="11" profile_version="1" rule_id="2" change_date="2011-12-05 20:20:05.158"
+ enabled="true" old_severity="[null]" new_severity="1" username="Administrator"/>
+
+</dataset>