]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5814 Add updated_at column on snapshot_sources
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 31 Oct 2014 13:56:55 +0000 (14:56 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 31 Oct 2014 15:14:37 +0000 (16:14 +0100)
16 files changed:
server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedSnapshotSourcesUpdatedAt.java [new file with mode: 0644]
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/711_add_updated_at_to_snapshot_sources.rb [new file with mode: 0644]
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/712_feed_snapshot_sources_updated_at.rb [new file with mode: 0644]
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/README.txt
sonar-batch/.sonar/profiling/myProject-profiler.xml [new file with mode: 0644]
sonar-batch/.sonar/profiling/total-execution-profiler.xml [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/shouldSaveSource-result.xml
sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
sonar-core/src/main/java/org/sonar/core/persistence/migration/v50/Migration50Mapper.java
sonar-core/src/main/java/org/sonar/core/persistence/migration/v50/SnapshotSource.java [new file with mode: 0644]
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-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot-result.xml
sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldPurgeSnapshot-result.xml
sonar-core/src/test/resources/org/sonar/core/source/db/SnapshotSourceDaoTest/insert-result.xml

index d114d6ec2a9e35ae76d97c0d46e0d8bc6f8b5274..ff9d7617233bb4b4a85651982109e06bd923f7ee 100644 (file)
@@ -29,6 +29,7 @@ import org.sonar.server.db.migrations.v45.AddMissingRuleParameterDefaultValuesMi
 import org.sonar.server.db.migrations.v45.DeleteMeasuresOnDeletedProfilesMigration;
 import org.sonar.server.db.migrations.v451.AddMissingCustomRuleParametersMigration;
 import org.sonar.server.db.migrations.v451.DeleteUnescapedActivities;
+import org.sonar.server.db.migrations.v50.FeedSnapshotSourcesUpdatedAt;
 import org.sonar.server.db.migrations.v50.InsertProjectsAuthorizationUpdatedAtMigration;
 import org.sonar.server.db.migrations.v50.PopulateProjectsUuidColumnsMigration;
 import org.sonar.server.db.migrations.v50.ReplaceIssueFiltersProjectKeyByUuid;
@@ -71,7 +72,8 @@ public interface DatabaseMigrations {
     // 5.0
     InsertProjectsAuthorizationUpdatedAtMigration.class,
     PopulateProjectsUuidColumnsMigration.class,
-    ReplaceIssueFiltersProjectKeyByUuid.class
+    ReplaceIssueFiltersProjectKeyByUuid.class,
+    FeedSnapshotSourcesUpdatedAt.class
   );
 
 }
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedSnapshotSourcesUpdatedAt.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedSnapshotSourcesUpdatedAt.java
new file mode 100644 (file)
index 0000000..67b9617
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * 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.v50;
+
+import org.apache.ibatis.session.ResultContext;
+import org.apache.ibatis.session.ResultHandler;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.core.persistence.migration.v50.Migration50Mapper;
+import org.sonar.core.persistence.migration.v50.SnapshotSource;
+import org.sonar.server.db.DbClient;
+import org.sonar.server.db.migrations.DatabaseMigration;
+import org.sonar.server.db.migrations.MassUpdate;
+
+import java.util.Timer;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * Used in the Active Record Migration 705
+ *
+ * @since 5.0
+ */
+public class FeedSnapshotSourcesUpdatedAt implements DatabaseMigration {
+
+  private final DbClient db;
+  private final AtomicLong counter = new AtomicLong(0L);
+  private final MassUpdate.ProgressTask progressTask = new MassUpdate.ProgressTask(counter);
+
+  public FeedSnapshotSourcesUpdatedAt(DbClient db) {
+    this.db = db;
+  }
+
+  @Override
+  public void execute() {
+    Timer timer = new Timer("Db Migration Progress");
+    timer.schedule(progressTask, MassUpdate.ProgressTask.PERIOD_MS, MassUpdate.ProgressTask.PERIOD_MS);
+
+    final DbSession readSession = db.openSession(false);
+    final DbSession writeSession = db.openSession(true);
+    try {
+      readSession.select("org.sonar.core.persistence.migration.v50.Migration50Mapper.selectSnapshotSources", new ResultHandler() {
+        @Override
+        public void handleResult(ResultContext context) {
+          SnapshotSource snapshotSource = (SnapshotSource) context.getResultObject();
+          snapshotSource.setUpdatedAt(snapshotSource.getSnapshotBuildDate());
+          writeSession.getMapper(Migration50Mapper.class).updateSnapshotSource(snapshotSource);
+          counter.getAndIncrement();
+        }
+      });
+      writeSession.commit();
+      readSession.commit();
+
+      // log the total number of process rows
+      progressTask.log();
+    } finally {
+      readSession.close();
+      writeSession.close();
+      timer.cancel();
+      timer.purge();
+    }
+  }
+}
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/711_add_updated_at_to_snapshot_sources.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/711_add_updated_at_to_snapshot_sources.rb
new file mode 100644 (file)
index 0000000..092bf23
--- /dev/null
@@ -0,0 +1,29 @@
+#
+# 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.0
+# SONAR-5753
+#
+class AddUpdatedAtToSnapshotSources < ActiveRecord::Migration
+  def self.up
+    add_column 'snapshot_sources', :updated_at, :datetime, :null => true
+  end
+end
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/712_feed_snapshot_sources_updated_at.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/712_feed_snapshot_sources_updated_at.rb
new file mode 100644 (file)
index 0000000..86891f5
--- /dev/null
@@ -0,0 +1,29 @@
+#
+# 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.0
+# SONAR-5810
+#
+class FeedSnapshotSourcesUpdatedAt < ActiveRecord::Migration
+  def self.up
+    execute_java_migration('org.sonar.server.db.migrations.v50.FeedSnapshotSourcesUpdatedAt')
+  end
+end
index 581cae28364befcf21edf142277f1900712b5709..12fc9a78d52b0b6d2e81856814240881a28a9a46 100644 (file)
@@ -7,6 +7,10 @@ HOW TO ADD A MIGRATION
     - add "INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('<THE MIGRATION ID>')"
 * Update the migration id defined in sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
 * If a table is added or removed, then edit sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
+* Changes in bulk must be handled using Java migrations based on org.sonar.server.db.migrations.MassUpdate :
+  + Create the class for the Java migration in package package org.sonar.server.db.migrations.vXYZ, where XYZ is the version of SQ without dots
+  + Add the class to org.sonar.server.db.migrations.DatabaseMigrations.CLASSES
+  + Create a Ruby migration which calls execute_java_migration('org.sonar.server.db.migrations.vXYZ.MyMigration')
 
 
 RECOMMENDATIONS
diff --git a/sonar-batch/.sonar/profiling/myProject-profiler.xml b/sonar-batch/.sonar/profiling/myProject-profiler.xml
new file mode 100644 (file)
index 0000000..45bac7a
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
+<properties>
+<comment>SonarQube</comment>
+<entry key="FakeScanPersister">40</entry>
+<entry key="FakePostJob">30</entry>
+<entry key="FakeDecorator2">10</entry>
+<entry key="Initializers">7</entry>
+<entry key="FakeDecorator1">20</entry>
+<entry key="Post-Jobs">30</entry>
+<entry key="FakeSensor">10</entry>
+<entry key="Maven">4</entry>
+<entry key="Free memory">9</entry>
+<entry key="Persisters">40</entry>
+<entry key="Decorators">30</entry>
+<entry key="FakeInitializer">7</entry>
+<entry key="Sensors">10</entry>
+</properties>
diff --git a/sonar-batch/.sonar/profiling/total-execution-profiler.xml b/sonar-batch/.sonar/profiling/total-execution-profiler.xml
new file mode 100644 (file)
index 0000000..1656097
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
+<properties>
+<comment>SonarQube</comment>
+<entry key="FakeScanPersister">120</entry>
+<entry key="FakePostJob">90</entry>
+<entry key="FakeDecorator2">30</entry>
+<entry key="Initializers">21</entry>
+<entry key="FakeDecorator1">60</entry>
+<entry key="Post-Jobs">90</entry>
+<entry key="FakeSensor">30</entry>
+<entry key="Maven">12</entry>
+<entry key="Free memory">27</entry>
+<entry key="Persisters">120</entry>
+<entry key="Decorators">90</entry>
+<entry key="FakeInitializer">21</entry>
+<entry key="Sensors">30</entry>
+</properties>
index 8c56be129e2bcf3ce7f129fe21f62d1b882241cb..cb97c2439113325393a065071fe1529d2dc90c18 100644 (file)
@@ -8,5 +8,5 @@
              scope="FIL" qualifier="CLA" created_at="2008-11-01 13:58:00.00" build_date="2008-11-01 13:58:00.00" version="[null]" path=""
              status="U" islast="[false]" depth="3" />
 
-  <SNAPSHOT_SOURCES ID="1" SNAPSHOT_ID="1000" DATA="this is the file content"/>
+  <SNAPSHOT_SOURCES ID="1" SNAPSHOT_ID="1000" DATA="this is the file content" UPDATED_AT="[null]"/>
 </dataset>
index 0c03ea7641ce0e10f7b1fdf7fba28dce7c2e4065..93d65401b9eba79b3cbbd55e9475d703606bd94e 100644 (file)
@@ -33,7 +33,7 @@ import java.util.List;
  */
 public class DatabaseVersion implements BatchComponent, ServerComponent {
 
-  public static final int LAST_VERSION = 710;
+  public static final int LAST_VERSION = 712;
   /**
    * List of all the tables.
    * This list is hardcoded because we didn't succeed in using java.sql.DatabaseMetaData#getTables() in the same way
index e5e9af6a2a76aa2bc4a993a7145957ce6b978534..c06489a7f3cc622d5fa851a74828b03365de20d6 100644 (file)
@@ -123,4 +123,19 @@ public interface Migration50Mapper {
   @Options(useGeneratedKeys = false)
   void updateComponentUuids(Component component);
 
+  @Select("SELECT " +
+    "  ss.id as \"id\", " +
+    "  ss.updated_at as \"updatedAt\", " +
+    "  s.build_date as \"snapshotBuildDate\" " +
+    "FROM snapshot_sources ss " +
+    "  INNER JOIN snapshots s ON s.id = ss.snapshot_id " +
+    "  WHERE ss.updated_at IS NULL")
+  @Result(javaType = SnapshotSource.class)
+  List<SnapshotSource> selectSnapshotSources();
+
+  @Update("UPDATE snapshot_sources " +
+    " SET updated_at=#{updatedAt} " +
+    " WHERE id=#{id}")
+  @Options(useGeneratedKeys = false)
+  void updateSnapshotSource(SnapshotSource snapshotSource);
 }
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/migration/v50/SnapshotSource.java b/sonar-core/src/main/java/org/sonar/core/persistence/migration/v50/SnapshotSource.java
new file mode 100644 (file)
index 0000000..4132cac
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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.v50;
+
+import javax.annotation.CheckForNull;
+
+import java.util.Date;
+
+public class SnapshotSource {
+
+  private Long id;
+  private Date updatedAt;
+  private Date snapshotBuildDate;
+
+  public Long getId() {
+    return id;
+  }
+
+  public void setId(Long id) {
+    this.id = id;
+  }
+
+  @CheckForNull
+  public Date getUpdatedAt() {
+    return updatedAt;
+  }
+
+  public void setUpdatedAt(Date updatedAt) {
+    this.updatedAt = updatedAt;
+  }
+
+  public Date getSnapshotBuildDate() {
+    return snapshotBuildDate;
+  }
+
+  public void setSnapshotBuildDate(Date snapshotBuildDate) {
+    this.snapshotBuildDate = snapshotBuildDate;
+  }
+
+}
index fa04f902cf1e7e9933f164bea9e3130bfc152d01..b7118612b8a934261a985447176658046e5708cd 100644 (file)
@@ -270,6 +270,8 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('707');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('708');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('709');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('710');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('711');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('712');
 
 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 b7c6a74457cfd0da950e028465554ea288692abb..4db09659428a8381828b25b37ea2619fffc86c9a 100644 (file)
@@ -247,6 +247,7 @@ CREATE TABLE "PROJECT_MEASURES" (
 CREATE TABLE "SNAPSHOT_SOURCES" (
   "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
   "SNAPSHOT_ID" INTEGER NOT NULL,
+  "UPDATED_AT" TIMESTAMP,
   "DATA" CLOB(2147483647)
 );
 
index 9987056896c90aaa6a4aea1af408c553f26529b4..d2aaf6dba2848559a8939306c2d97ed352c67bce 100644 (file)
@@ -13,7 +13,7 @@
              parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="[false]"
              path="[null]"/>
 
-  <snapshot_sources ID="1" SNAPSHOT_ID="1" DATA="foo"/>
+  <snapshot_sources ID="1" SNAPSHOT_ID="1" DATA="foo" UPDATED_AT="[null]"/>
   <project_measures ID="1" characteristic_id="[null]" url="[null]" variation_value_1="[null]" variation_value_2="[null]"
                     variation_value_3="[null]" variation_value_4="[null]"
                     variation_value_5="[null]"
index f2ab60752db6807df2296e4b1ee7f3d34f5ea736..3144614ec5246b386b69bf3d3bdce74ab94a2bfe 100644 (file)
@@ -58,7 +58,7 @@ Note that measures, events and reviews are not deleted.
              period5_mode="[null]" period5_param="[null]" period5_date="[null]"
              depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/>
 
-  <snapshot_sources ID="2" SNAPSHOT_ID="2" DATA="foo"/>
+  <snapshot_sources ID="2" SNAPSHOT_ID="2" DATA="foo" UPDATED_AT="[null]"/>
 
   <project_measures ID="2" project_id="2" SNAPSHOT_ID="2" RULE_ID="[null]" characteristic_id="[null]"
                     url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]"
index c7004b60f812420f995060054157f9fa541eb1fc..13f1e23579375b552e9317743190a3f45669c52a 100644 (file)
@@ -5,8 +5,8 @@
   <snapshots id="10" project_id="1" islast="[false]"/>
   <snapshots id="11" project_id="1" islast="[true]"/>
 
-  <snapshot_sources id="101" snapshot_id="11" data="public class Foo {public Foo(){}}"/>
+  <snapshot_sources id="101" snapshot_id="11" data="public class Foo {public Foo(){}}" updated_at="[null]"/>
 
-  <snapshot_sources id="102" snapshot_id="11" data="bar"/>
+  <snapshot_sources id="102" snapshot_id="11" data="bar" updated_at="[null]"/>
 
 </dataset>