From ea0fa88f0379acc96f8b7d45ecf295326201b7cb Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Mon, 8 Dec 2014 16:59:54 +0100 Subject: [PATCH] Support missing dates in the migration FeedLissueLongDates --- .../db/migrations/v50/FeedIssueLongDates.java | 12 ++++++++-- .../v50/FeedIssueLongDatesTest.java | 2 +- .../v50/FeedIssueLongDatesTest/before.xml | 23 +++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedIssueLongDates.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedIssueLongDates.java index cc65ac86564..c97938f721d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedIssueLongDates.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedIssueLongDates.java @@ -53,8 +53,16 @@ public class FeedIssueLongDates extends BaseDataChange { Date createdAt = row.getDate(2); Date updatedAt = row.getDate(3); - update.setLong(1, Math.min(now, createdAt.getTime())); - update.setLong(2, Math.min(now, updatedAt.getTime())); + if (createdAt == null) { + update.setLong(1, now); + } else { + update.setLong(1, Math.min(now, createdAt.getTime())); + } + if (updatedAt == null) { + update.setLong(2, now); + } else { + update.setLong(2, Math.min(now, updatedAt.getTime())); + } update.setLong(3, id); return true; } diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedIssueLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedIssueLongDatesTest.java index 91d47c7ea2e..b164d8e18be 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedIssueLongDatesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedIssueLongDatesTest.java @@ -45,7 +45,7 @@ public class FeedIssueLongDatesTest { migration.execute(); int count = db.count("select count(*) from issues where created_at_ms is not null and updated_at_ms is not null"); - assertThat(count).isEqualTo(2); + assertThat(count).isEqualTo(3); } } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/FeedIssueLongDatesTest/before.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/FeedIssueLongDatesTest/before.xml index 2c029ebf895..9e28208c426 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/FeedIssueLongDatesTest/before.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/FeedIssueLongDatesTest/before.xml @@ -48,4 +48,27 @@ UPDATED_AT_MS="1500000000000" /> + + -- 2.39.5