Skip to content

Commit

Permalink
Make account req data migration script rerunnable (#12932)
Browse files Browse the repository at this point in the history
  • Loading branch information
ziqing26 committed Mar 26, 2024
1 parent 1be2adb commit 716fdc4
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package teammates.client.scripts.sql;

// CHECKSTYLE.OFF:ImportOrder
import com.googlecode.objectify.cmd.Query;

import jakarta.persistence.criteria.CriteriaDelete;

import teammates.common.util.HibernateUtil;
import teammates.storage.sqlentity.AccountRequest;

// CHECKSTYLE.ON:ImportOrder

/**
* Data migration class for account request entity.
*/
Expand Down Expand Up @@ -33,7 +39,8 @@ protected boolean isPreview() {
*/
@Override
protected void setMigrationCriteria() {
// No migration criteria currently needed.
// Prepare clean db before migration
cleanAccountRequestInSql();
}

/**
Expand Down Expand Up @@ -73,4 +80,15 @@ protected void migrateEntity(teammates.storage.entity.AccountRequest oldEntity)

saveEntityDeferred(newEntity);
}

private void cleanAccountRequestInSql() {
HibernateUtil.beginTransaction();

CriteriaDelete<AccountRequest> cdAccountReq = HibernateUtil.getCriteriaBuilder()
.createCriteriaDelete(AccountRequest.class);
cdAccountReq.from(AccountRequest.class);
HibernateUtil.executeDelete(cdAccountReq);

HibernateUtil.commitTransaction();
}
}

0 comments on commit 716fdc4

Please sign in to comment.