]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7794 add column RULES_PROFILES.USER_UPDATED_AT
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Thu, 23 Jun 2016 14:57:21 +0000 (16:57 +0200)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Wed, 29 Jun 2016 09:06:00 +0000 (11:06 +0200)
15 files changed:
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1262_add_user_updated_at_to_rules_profiles.rb [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/qualityprofile/QualityProfileDto.java
sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java
sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java
sonar-db/src/main/java/org/sonar/db/version/v60/AddUserUpdatedAtToRulesProfiles.java [new file with mode: 0644]
sonar-db/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml
sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql
sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl
sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java
sonar-db/src/test/java/org/sonar/db/version/v60/AddUserUpdatedAtToRulesProfilesTest.java [new file with mode: 0644]
sonar-db/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/delete-result.xml
sonar-db/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/insert-result.xml
sonar-db/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/shared.xml
sonar-db/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/update-result.xml
sonar-db/src/test/resources/org/sonar/db/version/v60/AddUserUpdatedAtToRulesProfilesTest/rules_profiles.sql [new file with mode: 0644]

diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1262_add_user_updated_at_to_rules_profiles.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/1262_add_user_updated_at_to_rules_profiles.rb
new file mode 100644 (file)
index 0000000..e3d4d5e
--- /dev/null
@@ -0,0 +1,28 @@
+#
+# 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 6.0
+# SONAR-7794
+#
+class AddUserUpdatedAtToRulesProfiles < ActiveRecord::Migration
+  def self.up
+    execute_java_migration('org.sonar.db.version.v60.AddUserUpdatedAtToRulesProfiles')
+  end
+end
index 944b3353c8a977c851870494fbeae06432d65bc6..43dd95e99ceca632a6a226e8ad2ad4040800ec07 100644 (file)
@@ -34,6 +34,7 @@ public class QualityProfileDto extends Dto<String> {
   private String parentKee;
   private String rulesUpdatedAt;
   private Long lastUsed;
+  private Long userUpdatedAt;
   private boolean isDefault;
 
   /**
@@ -123,6 +124,16 @@ public class QualityProfileDto extends Dto<String> {
     return this;
   }
 
+  @CheckForNull
+  public Long getUserUpdatedAt() {
+    return userUpdatedAt;
+  }
+
+  public QualityProfileDto setUserUpdatedAt(@Nullable Long userUpdatedAt) {
+    this.userUpdatedAt = userUpdatedAt;
+    return this;
+  }
+
   public boolean isDefault() {
     return isDefault;
   }
index 1ab5f63e5370d7e0dfa71929690b4406466d9abf..857ced783b49f14438618421ea76717f71fff3e4 100644 (file)
@@ -30,7 +30,7 @@ import org.sonar.db.MyBatis;
 
 public class DatabaseVersion {
 
-  public static final int LAST_VERSION = 1_261;
+  public static final int LAST_VERSION = 1_262;
 
   /**
    * The minimum supported version which can be upgraded. Lower
index 15292be30f8e68a1858a130aadfc4da12a57be9a..e975696a8a4f4ab0292e98ce2df91dd1a0ab7373 100644 (file)
@@ -91,6 +91,7 @@ import org.sonar.db.version.v60.AddComponentUuidColumnToMeasures;
 import org.sonar.db.version.v60.AddComponentUuidColumnsToSnapshots;
 import org.sonar.db.version.v60.AddLastUsedColumnToRulesProfiles;
 import org.sonar.db.version.v60.AddProfileKeyToActivities;
+import org.sonar.db.version.v60.AddUserUpdatedAtToRulesProfiles;
 import org.sonar.db.version.v60.AddUuidColumnToSnapshots;
 import org.sonar.db.version.v60.AddUuidColumnsToProjects;
 import org.sonar.db.version.v60.AddUuidColumnsToResourceIndex;
@@ -247,6 +248,7 @@ public class MigrationStepModule extends Module {
       AddProfileKeyToActivities.class,
       PopulateProfileKeyOfActivities.class,
       MakeProfileKeyNotNullOnActivities.class,
+      AddUserUpdatedAtToRulesProfiles.class,
 
       // SNAPSHOTS.UUID
       AddUuidColumnToSnapshots.class,
diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/AddUserUpdatedAtToRulesProfiles.java b/sonar-db/src/main/java/org/sonar/db/version/v60/AddUserUpdatedAtToRulesProfiles.java
new file mode 100644 (file)
index 0000000..4935ab7
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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.v60;
+
+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;
+
+public class AddUserUpdatedAtToRulesProfiles extends DdlChange {
+
+  private static final String TABLE_QUALITY_PROFILES = "rules_profiles";
+
+  public AddUserUpdatedAtToRulesProfiles(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AddColumnsBuilder(getDatabase().getDialect(), TABLE_QUALITY_PROFILES)
+      .addColumn(newBigDecimalColumnDefBuilder().setColumnName("user_updated_at").setIsNullable(true).build())
+      .build());
+  }
+
+}
index e33f92db1d237f906d76c5ba9555b7aa23965c9d..381c53dba5471af600437fd6a9713356cfb5d898 100644 (file)
     p.created_at as createdAt,
     p.updated_at as updatedAt,
     p.rules_updated_at as rulesUpdatedAt,
-    p.last_used as lastUsed
+    p.last_used as lastUsed,
+    p.user_updated_at as userUpdatedAt
   </sql>
 
   <insert id="insert" parameterType="QualityProfile" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
-    INSERT INTO rules_profiles (kee, parent_kee, name, language, is_default, created_at, updated_at, rules_updated_at, last_used)
-    VALUES (#{kee, jdbcType=VARCHAR}, #{parentKee,jdbcType=VARCHAR}, #{name, jdbcType=VARCHAR}, #{language, jdbcType=VARCHAR}, #{isDefault, jdbcType=BOOLEAN},
-    #{createdAt, jdbcType=TIMESTAMP}, #{updatedAt, jdbcType=TIMESTAMP}, #{rulesUpdatedAt, jdbcType=VARCHAR}, #{lastUsed, jdbcType=BIGINT})
+    INSERT INTO rules_profiles (kee, parent_kee, name, language, is_default, created_at, updated_at, rules_updated_at, last_used, user_updated_at)
+    VALUES (
+    #{kee, jdbcType=VARCHAR},
+    #{parentKee, jdbcType=VARCHAR},
+    #{name, jdbcType=VARCHAR},
+    #{language, jdbcType=VARCHAR},
+    #{isDefault, jdbcType=BOOLEAN},
+    #{createdAt, jdbcType=TIMESTAMP},
+    #{updatedAt, jdbcType=TIMESTAMP},
+    #{rulesUpdatedAt, jdbcType=VARCHAR},
+    #{lastUsed, jdbcType=BIGINT},
+    #{userUpdatedAt, jdbcType=BIGINT})
   </insert>
 
   <update id="update" parameterType="QualityProfile">
@@ -30,7 +40,8 @@
     parent_kee=#{parentKee, jdbcType=VARCHAR},
     updated_at=#{updatedAt, jdbcType=TIMESTAMP},
     rules_updated_at=#{rulesUpdatedAt, jdbcType=VARCHAR},
-    last_used=#{lastUsed, jdbcType=BIGINT}
+    last_used=#{lastUsed, jdbcType=BIGINT},
+    user_updated_at=#{userUpdatedAt, jdbcType=BIGINT}
     WHERE id=#{id}
   </update>
 
index 0f997903b43826b7d7665840229bf230d1a34a33..0fd0413b98b11427b83d7f729d26d8f989fec1f0 100644 (file)
@@ -467,6 +467,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1257');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1258');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1259');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1260');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1261');
 
 INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, USER_LOCAL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT) VALUES (1, 'admin', 'Administrator', '', 'admin', 'sonarqube', true, 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '1418215735482', '1418215735482');
 ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
index b89ca216e4e309920c3efc3808df5aa3c5da64e3..6c8476ee4f748140c1b4568307b3324195e074db 100644 (file)
@@ -22,7 +22,8 @@ CREATE TABLE "RULES_PROFILES" (
   "IS_DEFAULT" BOOLEAN NOT NULL DEFAULT FALSE,
   "CREATED_AT" TIMESTAMP,
   "UPDATED_AT" TIMESTAMP,
-  "LAST_USED" BIGINT
+  "LAST_USED" BIGINT,
+  "USER_UPDATED_AT" BIGINT
 );
 
 CREATE TABLE "PROJECT_QPROFILES" (
index b72caa7bfbad180dfa1710fd1e4bf6da8839e42c..8de343972a9c728fda5d6f61aaad48b114c89578 100644 (file)
@@ -29,6 +29,6 @@ public class MigrationStepModuleTest {
   public void verify_count_of_added_MigrationStep_types() {
     ComponentContainer container = new ComponentContainer();
     new MigrationStepModule().configure(container);
-    assertThat(container.size()).isEqualTo(117);
+    assertThat(container.size()).isEqualTo(118);
   }
 }
diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/AddUserUpdatedAtToRulesProfilesTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/AddUserUpdatedAtToRulesProfilesTest.java
new file mode 100644 (file)
index 0000000..8e2c703
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * 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.v60;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+
+public class AddUserUpdatedAtToRulesProfilesTest {
+
+  @Rule
+  public DbTester db = DbTester.createForSchema(System2.INSTANCE, AddUserUpdatedAtToRulesProfilesTest.class, "rules_profiles.sql");
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  AddUserUpdatedAtToRulesProfiles underTest = new AddUserUpdatedAtToRulesProfiles(db.database());
+
+  @Test
+  public void migration_adds_column_to_empty_table() throws SQLException {
+    underTest.execute();
+
+    verifyAddedColumn();
+  }
+
+  @Test
+  public void migration_adds_column_to_populated_table() throws SQLException {
+    for (int i = 0; i < 9; i++) {
+      db.executeInsert(
+        "rules_profiles",
+        "name", "NAME_" + i,
+        "language", "java",
+        "kee", "" + i,
+        "rules_updated_at", "2016-06-21",
+        "last_used", "123456789");
+    }
+    db.commit();
+
+    underTest.execute();
+
+    verifyAddedColumn();
+  }
+
+  @Test
+  public void migration_is_not_reentrant() throws SQLException {
+    underTest.execute();
+
+    expectedException.expect(IllegalStateException.class);
+    expectedException.expectMessage("Fail to execute ");
+    underTest.execute();
+  }
+
+  private void verifyAddedColumn() {
+    db.assertColumnDefinition("rules_profiles", "user_updated_at", Types.BIGINT, null, true);
+  }
+}
index a503c6b3950493c26f3b81dfc22d77a7c9a1cb8a..b2344538ad3e3212a6249677f1e1a7701617eb28 100644 (file)
@@ -1,6 +1,6 @@
 <dataset>
 
   <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way" is_default="[false]"
-                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="123456789"/>
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="123456789" user_updated_at="987654321"/>
 
 </dataset>
index 9090f8728dc989c93b657034d3c7f8db40e14712..e8c8c219220b0b9e7f75e6a46b2219279d1ca90e 100644 (file)
@@ -1,13 +1,13 @@
 <dataset>
 
   <rules_profiles id="1" name="Sonar Way" language="java" parent_kee="[null]" kee="java_sonar_way" is_default="[true]"
-                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="[null]"/>
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="[null]" user_updated_at="[null]"/>
 
   <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way" is_default="[false]"
-                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="123456789"/>
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="123456789" user_updated_at="987654321"/>
 
   <rules_profiles id="3" name="ABCDE" language="xoo" parent_kee="[null]" kee="abcde" is_default="[false]"
-                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="[null]"/>
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="[null]" user_updated_at="[null]"/>
 
 
 </dataset>
index 92509d96554cfdb298e3c05097211f27b3e779d6..5736ef59bd42d767d9b346dad42b6df7be7202d4 100644 (file)
@@ -1,9 +1,9 @@
 <dataset>
 
   <rules_profiles id="1" name="Sonar Way" language="java" parent_kee="[null]" kee="java_sonar_way" is_default="[true]"
-                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="[null]"/>
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="[null]" user_updated_at="[null]"/>
 
   <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way" is_default="[false]"
-                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="123456789"/>
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="123456789" user_updated_at="987654321"/>
 
 </dataset>
index 952372c6a12759f667a2c516e044f6865c4ee530..d7cb1a3a3a60f8aa7a2e08b103b7305a60bdcfe8 100644 (file)
@@ -1,10 +1,8 @@
 <dataset>
 
   <rules_profiles id="1" name="New Name" language="js" parent_kee="fghij" kee="java_sonar_way" is_default="[false]"
-                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="[null]"/>
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="[null]" user_updated_at="[null]"/>
 
   <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way" is_default="[false]"
-                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="123456789"/>
-
-
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="123456789" user_updated_at="987654321"/>
 </dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v60/AddUserUpdatedAtToRulesProfilesTest/rules_profiles.sql b/sonar-db/src/test/resources/org/sonar/db/version/v60/AddUserUpdatedAtToRulesProfilesTest/rules_profiles.sql
new file mode 100644 (file)
index 0000000..efa759b
--- /dev/null
@@ -0,0 +1,12 @@
+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(255) NOT NULL,
+  "PARENT_KEE" VARCHAR(255),
+  "RULES_UPDATED_AT" VARCHAR(100),
+  "IS_DEFAULT" BOOLEAN NOT NULL DEFAULT FALSE,
+  "CREATED_AT" TIMESTAMP,
+  "UPDATED_AT" TIMESTAMP,
+  "LAST_USED" BIGINT
+);