Skip to content

Commit

Permalink
[#12048] Patch account and read notification migration (#12884)
Browse files Browse the repository at this point in the history
* Add a separate script for patching

* Separate patch script from the first run script

* Revert separated script
  • Loading branch information
ziqing26 authored Mar 10, 2024
1 parent 2caea93 commit 9043ae4
Showing 1 changed file with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ private boolean isPreview() {
* Returns whether the account has been migrated.
*/
protected boolean isMigrationNeeded(teammates.storage.entity.Account entity) {
return !entity.isMigrated();
return true;
}

/**
* Returns the filter query.
*/
protected Query<teammates.storage.entity.Account> getFilterQuery() {
return ofy().load().type(teammates.storage.entity.Account.class);
return ofy().load().type(teammates.storage.entity.Account.class).filter("isMigrated =", false);
}

private void doMigration(teammates.storage.entity.Account entity) {
Expand Down Expand Up @@ -147,9 +147,8 @@ private void migrateReadNotification(teammates.storage.entity.Account oldAccount
Notification newNotification = HibernateUtil.get(Notification.class, notificationId);
HibernateUtil.commitTransaction();

// Error if the notification does not exist in the new database
// If the notification does not exist in the new database
if (newNotification == null) {
logError("Notification not found: " + notificationId);
continue;
}

Expand All @@ -169,6 +168,8 @@ protected void doOperation() {
} else {
log("Start from cursor position: " + cursor.toUrlSafe());
}

// // Clean account and read notification in SQL before migration
// cleanAccountAndReadNotificationInSql();
boolean shouldContinue = true;
while (shouldContinue) {
Expand Down Expand Up @@ -207,24 +208,21 @@ protected void doOperation() {
log("Number of updated entities: " + numberOfUpdatedEntities.get());
}

// This method was used to clean the account and read notification in the SQL
// private void cleanAccountAndReadNotificationInSql() {
// HibernateUtil.beginTransaction();

// CriteriaDelete<ReadNotification> cdReadNotification =
// HibernateUtil.getCriteriaBuilder()
// .createCriteriaDelete(ReadNotification.class);
// cdReadNotification.from(ReadNotification.class);
// HibernateUtil.executeDelete(cdReadNotification);

// CriteriaDelete<teammates.storage.sqlentity.Account> cdAccount =
// HibernateUtil.getCriteriaBuilder()
// .createCriteriaDelete(
// teammates.storage.sqlentity.Account.class);
// cdAccount.from(teammates.storage.sqlentity.Account.class);
// HibernateUtil.executeDelete(cdAccount);

// HibernateUtil.commitTransaction();
// HibernateUtil.beginTransaction();

// CriteriaDelete<ReadNotification> cdReadNotification = HibernateUtil.getCriteriaBuilder()
// .createCriteriaDelete(ReadNotification.class);
// cdReadNotification.from(ReadNotification.class);
// HibernateUtil.executeDelete(cdReadNotification);

// CriteriaDelete<teammates.storage.sqlentity.Account> cdAccount = HibernateUtil.getCriteriaBuilder()
// .createCriteriaDelete(
// teammates.storage.sqlentity.Account.class);
// cdAccount.from(teammates.storage.sqlentity.Account.class);
// HibernateUtil.executeDelete(cdAccount);

// HibernateUtil.commitTransaction();
// }

/**
Expand Down

0 comments on commit 9043ae4

Please sign in to comment.