From 3097e6e4eab26b92082b09cfa377ec58e6ef35da Mon Sep 17 00:00:00 2001 From: mingyuanc Date: Wed, 3 Apr 2024 23:40:18 +0800 Subject: [PATCH] Finish course migration --- .../client/scripts/sql/DataMigrationForCourseSql.java | 11 ++++++++--- .../java/teammates/client/scripts/sql/SeedDb.java | 7 ++++++- .../client/scripts/sql/VerifyCourseAttributes.java | 5 +++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/client/java/teammates/client/scripts/sql/DataMigrationForCourseSql.java b/src/client/java/teammates/client/scripts/sql/DataMigrationForCourseSql.java index 962d82b4225a..beef38dff8d0 100644 --- a/src/client/java/teammates/client/scripts/sql/DataMigrationForCourseSql.java +++ b/src/client/java/teammates/client/scripts/sql/DataMigrationForCourseSql.java @@ -1,5 +1,8 @@ package teammates.client.scripts.sql; +import java.time.Duration; +import java.time.Instant; + import com.googlecode.objectify.cmd.Query; import teammates.common.util.HibernateUtil; @@ -12,6 +15,8 @@ public class DataMigrationForCourseSql extends DataMigrationEntitiesBaseScriptSql { + private static final int HOURS_OFFSET = 1; + public static void main(String[] args) { new DataMigrationForCourseSql().doOperationRemotely(); } @@ -50,9 +55,9 @@ protected void migrateEntity(Course oldCourse) throws Exception { oldCourse.getName(), oldCourse.getTimeZone(), oldCourse.getInstitute()); - newCourse.setCreatedAt(oldCourse.getCreatedAt()); - newCourse.setDeletedAt(oldCourse.getDeletedAt()); - + if (oldCourse.getDeletedAt() != null) { + newCourse.setDeletedAt(Instant.now().plus(Duration.ofHours(HOURS_OFFSET))); + } saveEntityDeferred(newCourse); } } diff --git a/src/client/java/teammates/client/scripts/sql/SeedDb.java b/src/client/java/teammates/client/scripts/sql/SeedDb.java index 25ed029a5e4c..76c4c7cd4d38 100644 --- a/src/client/java/teammates/client/scripts/sql/SeedDb.java +++ b/src/client/java/teammates/client/scripts/sql/SeedDb.java @@ -119,12 +119,17 @@ private void seedCourse() { log(String.format("Seeded %d %% of new sets of entities", (int) (100 * ((float) i / (float) MAX_ENTITY_SIZE)))); } + + Random rand = new Random(); + try { String courseName = String.format("Course %s", i); String courseInstitute = String.format("Institute %s", i); String courseTimeZone = String.format("Time Zone %s", i); Course course = new Course(UUID.randomUUID().toString(), courseName, courseTimeZone, courseInstitute, - getRandomInstant(), getRandomInstant(), false); + getRandomInstant(), + rand.nextInt(3) > 1 ? null : getRandomInstant(), // set deletedAt randomly at 25% chance + false); ofy().save().entities(course).now(); } catch (Exception e) { log(e.toString()); diff --git a/src/client/java/teammates/client/scripts/sql/VerifyCourseAttributes.java b/src/client/java/teammates/client/scripts/sql/VerifyCourseAttributes.java index 37d7c556828a..8883383ffa64 100644 --- a/src/client/java/teammates/client/scripts/sql/VerifyCourseAttributes.java +++ b/src/client/java/teammates/client/scripts/sql/VerifyCourseAttributes.java @@ -32,8 +32,9 @@ public boolean equals(teammates.storage.sqlentity.Course sqlEntity, Course datas && sqlEntity.getName().equals(datastoreEntity.getName()) && sqlEntity.getTimeZone().equals(datastoreEntity.getTimeZone()) && sqlEntity.getInstitute().equals(datastoreEntity.getInstitute()) - && sqlEntity.getCreatedAt().equals(datastoreEntity.getCreatedAt()) - && sqlEntity.getDeletedAt().equals(datastoreEntity.getDeletedAt()); + && (datastoreEntity.getDeletedAt() == null + ? sqlEntity.getDeletedAt() == null + : sqlEntity.getDeletedAt() != null); } catch (IllegalArgumentException iae) { return false; }