From 9043ae4422c991943e9a428d7e1fa8bb5754746a Mon Sep 17 00:00:00 2001 From: Zhang Ziqing <69516975+ziqing26@users.noreply.github.com> Date: Sun, 10 Mar 2024 23:36:48 +0800 Subject: [PATCH] [#12048] Patch account and read notification migration (#12884) * Add a separate script for patching * Separate patch script from the first run script * Revert separated script --- ...ationForAccountAndReadNotificationSql.java | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/client/java/teammates/client/scripts/sql/DataMigrationForAccountAndReadNotificationSql.java b/src/client/java/teammates/client/scripts/sql/DataMigrationForAccountAndReadNotificationSql.java index c42399b3f70..08f026f68d5 100644 --- a/src/client/java/teammates/client/scripts/sql/DataMigrationForAccountAndReadNotificationSql.java +++ b/src/client/java/teammates/client/scripts/sql/DataMigrationForAccountAndReadNotificationSql.java @@ -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 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) { @@ -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; } @@ -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) { @@ -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 cdReadNotification = - // HibernateUtil.getCriteriaBuilder() - // .createCriteriaDelete(ReadNotification.class); - // cdReadNotification.from(ReadNotification.class); - // HibernateUtil.executeDelete(cdReadNotification); - - // CriteriaDelete cdAccount = - // HibernateUtil.getCriteriaBuilder() - // .createCriteriaDelete( - // teammates.storage.sqlentity.Account.class); - // cdAccount.from(teammates.storage.sqlentity.Account.class); - // HibernateUtil.executeDelete(cdAccount); - - // HibernateUtil.commitTransaction(); + // HibernateUtil.beginTransaction(); + + // CriteriaDelete cdReadNotification = HibernateUtil.getCriteriaBuilder() + // .createCriteriaDelete(ReadNotification.class); + // cdReadNotification.from(ReadNotification.class); + // HibernateUtil.executeDelete(cdReadNotification); + + // CriteriaDelete cdAccount = HibernateUtil.getCriteriaBuilder() + // .createCriteriaDelete( + // teammates.storage.sqlentity.Account.class); + // cdAccount.from(teammates.storage.sqlentity.Account.class); + // HibernateUtil.executeDelete(cdAccount); + + // HibernateUtil.commitTransaction(); // } /**