From 0ffd9d683485c9a179e83ed4a466370c6036d1fe Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lievremont Date: Fri, 31 Oct 2014 14:56:55 +0100 Subject: SONAR-5814 Add updated_at column on snapshot_sources --- .../sonar/core/persistence/DatabaseVersion.java | 2 +- .../migration/v50/Migration50Mapper.java | 15 ++++++ .../persistence/migration/v50/SnapshotSource.java | 57 ++++++++++++++++++++++ .../org/sonar/core/persistence/rows-h2.sql | 2 + .../org/sonar/core/persistence/schema-h2.ddl | 1 + .../shouldDeleteSnapshot-result.xml | 2 +- .../shouldPurgeSnapshot-result.xml | 2 +- .../db/SnapshotSourceDaoTest/insert-result.xml | 4 +- 8 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 sonar-core/src/main/java/org/sonar/core/persistence/migration/v50/SnapshotSource.java (limited to 'sonar-core/src') diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java index 0c03ea7641c..93d65401b9e 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java @@ -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 diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/migration/v50/Migration50Mapper.java b/sonar-core/src/main/java/org/sonar/core/persistence/migration/v50/Migration50Mapper.java index e5e9af6a2a7..c06489a7f3c 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/migration/v50/Migration50Mapper.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/migration/v50/Migration50Mapper.java @@ -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 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 index 00000000000..4132cacb4b5 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/persistence/migration/v50/SnapshotSource.java @@ -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; + } + +} diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql index fa04f902cf1..b7118612b8a 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql @@ -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; diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl index b7c6a74457c..4db09659428 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl @@ -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) ); diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot-result.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot-result.xml index 9987056896c..d2aaf6dba28 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot-result.xml @@ -13,7 +13,7 @@ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="[false]" path="[null]"/> - + - + - + - + -- cgit v1.2.3