Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#12048] Rerunnable Account Request Migration Script #12932

Merged
merged 4 commits into from
Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Loading