Skip to content

Commit

Permalink
Finish course migration
Browse files Browse the repository at this point in the history
  • Loading branch information
mingyuanc committed Apr 3, 2024
1 parent a0885c6 commit 3097e6e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,6 +15,8 @@
public class DataMigrationForCourseSql extends
DataMigrationEntitiesBaseScriptSql<teammates.storage.entity.Course, teammates.storage.sqlentity.Course> {

private static final int HOURS_OFFSET = 1;

public static void main(String[] args) {
new DataMigrationForCourseSql().doOperationRemotely();
}
Expand Down Expand Up @@ -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);
}
}
7 changes: 6 additions & 1 deletion src/client/java/teammates/client/scripts/sql/SeedDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 3097e6e

Please sign in to comment.