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;
// 5.0
InsertProjectsAuthorizationUpdatedAtMigration.class,
PopulateProjectsUuidColumnsMigration.class,
- ReplaceIssueFiltersProjectKeyByUuid.class
+ ReplaceIssueFiltersProjectKeyByUuid.class,
+ FeedSnapshotSourcesUpdatedAt.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.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();
+ }
+ }
+}
--- /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 5.0
+# SONAR-5753
+#
+class AddUpdatedAtToSnapshotSources < ActiveRecord::Migration
+ def self.up
+ add_column 'snapshot_sources', :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 5.0
+# SONAR-5810
+#
+class FeedSnapshotSourcesUpdatedAt < ActiveRecord::Migration
+ def self.up
+ execute_java_migration('org.sonar.server.db.migrations.v50.FeedSnapshotSourcesUpdatedAt')
+ end
+end
- 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
--- /dev/null
+<?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>
--- /dev/null
+<?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>
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>
*/
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
@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);
}
--- /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.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;
+ }
+
+}
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;
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)
);
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]"
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]"
<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>