-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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] Data migration for feedback session entities #12986
Merged
NicolasCwy
merged 6 commits into
TEAMMATES:v9-course-migration
from
yuanxi1:v9-course-migration
Apr 7, 2024
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3e108c7
Add migration and verification script for feedback session
2275560
Optimize data migration
dba2272
Fix lint
64e02d8
Uncomment seed feedback session function
280eaed
Add counts verification script
82d0605
Amend getReference javadoc
NicolasCwy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
src/client/java/teammates/client/scripts/sql/DataMigrationForFeedbackSessionSql.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package teammates.client.scripts.sql; | ||
|
||
import java.time.Duration; | ||
|
||
// CHECKSTYLE.OFF:ImportOrder | ||
import com.googlecode.objectify.cmd.Query; | ||
import teammates.common.util.HibernateUtil; | ||
import teammates.storage.entity.FeedbackSession; | ||
import teammates.storage.sqlentity.Course; | ||
|
||
// CHECKSTYLE.ON:ImportOrder | ||
/** | ||
* Data migration class for feddback sessions. | ||
*/ | ||
@SuppressWarnings("PMD") | ||
public class DataMigrationForFeedbackSessionSql | ||
extends DataMigrationEntitiesBaseScriptSql<FeedbackSession, teammates.storage.sqlentity.FeedbackSession> { | ||
|
||
public static void main(String[] args) { | ||
new DataMigrationForFeedbackSessionSql().doOperationRemotely(); | ||
} | ||
|
||
@Override | ||
protected Query<FeedbackSession> getFilterQuery() { | ||
return ofy().load().type(teammates.storage.entity.FeedbackSession.class); | ||
} | ||
|
||
@Override | ||
protected boolean isPreview() { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected void setMigrationCriteria() { | ||
// No migration criteria currently needed. | ||
} | ||
|
||
@Override | ||
protected boolean isMigrationNeeded(FeedbackSession entity) { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected void migrateEntity(FeedbackSession oldEntity) throws Exception { | ||
HibernateUtil.beginTransaction(); | ||
Course course = HibernateUtil.get(teammates.storage.sqlentity.Course.class, oldEntity.getCourseId()); | ||
HibernateUtil.commitTransaction(); | ||
|
||
teammates.storage.sqlentity.FeedbackSession newFeedbackSession = new teammates.storage.sqlentity.FeedbackSession( | ||
oldEntity.getFeedbackSessionName(), | ||
course, | ||
oldEntity.getCreatorEmail(), | ||
oldEntity.getInstructions(), | ||
oldEntity.getStartTime(), | ||
oldEntity.getEndTime(), | ||
oldEntity.getSessionVisibleFromTime(), | ||
oldEntity.getResultsVisibleFromTime(), | ||
Duration.ofMinutes(oldEntity.getGracePeriod()), | ||
oldEntity.isOpeningEmailEnabled(), | ||
oldEntity.isClosingEmailEnabled(), | ||
oldEntity.isPublishedEmailEnabled() | ||
); | ||
|
||
newFeedbackSession.setClosedEmailSent(oldEntity.isSentClosedEmail()); | ||
newFeedbackSession.setClosingSoonEmailSent(oldEntity.isSentClosingEmail()); | ||
newFeedbackSession.setOpenEmailSent(oldEntity.isSentOpenEmail()); | ||
newFeedbackSession.setOpeningSoonEmailSent(oldEntity.isSentOpeningSoonEmail()); | ||
newFeedbackSession.setPublishedEmailSent(oldEntity.isSentPublishedEmail()); | ||
newFeedbackSession.setDeletedAt(oldEntity.getDeletedTime()); | ||
|
||
saveEntityDeferred(newFeedbackSession); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/client/java/teammates/client/scripts/sql/VerifyFeedbackSessionAttributes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package teammates.client.scripts.sql; | ||
|
||
import java.time.Duration; | ||
|
||
import teammates.common.util.SanitizationHelper; | ||
import teammates.storage.entity.FeedbackSession; | ||
|
||
/** | ||
* Verification of the feedback session attributes. | ||
*/ | ||
public class VerifyFeedbackSessionAttributes | ||
extends VerifyNonCourseEntityAttributesBaseScript<FeedbackSession, teammates.storage.sqlentity.FeedbackSession> { | ||
|
||
public VerifyFeedbackSessionAttributes() { | ||
super(FeedbackSession.class, teammates.storage.sqlentity.FeedbackSession.class); | ||
} | ||
|
||
@Override | ||
protected String generateID(teammates.storage.sqlentity.FeedbackSession sqlEntity) { | ||
return FeedbackSession.generateId(sqlEntity.getName(), sqlEntity.getCourse().getId()); | ||
yuanxi1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@Override | ||
protected boolean equals(teammates.storage.sqlentity.FeedbackSession sqlEntity, FeedbackSession datastoreEntity) { | ||
try { | ||
return sqlEntity.getCourse().getId().equals(datastoreEntity.getCourseId()) | ||
yuanxi1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
&& sqlEntity.getName().equals(datastoreEntity.getFeedbackSessionName()) | ||
&& sqlEntity.getCreatorEmail().equals(datastoreEntity.getCreatorEmail()) | ||
&& sqlEntity.getInstructions() | ||
.equals(SanitizationHelper.sanitizeForRichText(datastoreEntity.getInstructions())) | ||
&& sqlEntity.getStartTime().equals(datastoreEntity.getStartTime()) | ||
&& sqlEntity.getEndTime().equals(datastoreEntity.getEndTime()) | ||
&& sqlEntity.getSessionVisibleFromTime().equals(datastoreEntity.getSessionVisibleFromTime()) | ||
&& sqlEntity.getResultsVisibleFromTime().equals(datastoreEntity.getResultsVisibleFromTime()) | ||
&& sqlEntity.getGracePeriod().equals(Duration.ofMinutes(datastoreEntity.getGracePeriod())) | ||
&& sqlEntity.isOpeningEmailEnabled() == datastoreEntity.isOpeningEmailEnabled() | ||
&& sqlEntity.isClosingEmailEnabled() == datastoreEntity.isClosingEmailEnabled() | ||
&& sqlEntity.isOpenEmailSent() == datastoreEntity.isSentOpenEmail() | ||
&& sqlEntity.isOpeningSoonEmailSent() == datastoreEntity.isSentOpeningSoonEmail() | ||
&& sqlEntity.isClosedEmailSent() == datastoreEntity.isSentClosedEmail() | ||
&& sqlEntity.isClosingSoonEmailSent() == datastoreEntity.isSentClosingEmail() | ||
&& sqlEntity.isPublishedEmailSent() == datastoreEntity.isSentPublishedEmail() | ||
&& (sqlEntity.getDeletedAt() == datastoreEntity.getDeletedTime() | ||
|| sqlEntity.getDeletedAt().equals(datastoreEntity.getDeletedTime())); | ||
} catch (IllegalArgumentException iae) { | ||
return false; | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
VerifyFeedbackSessionAttributes script = new VerifyFeedbackSessionAttributes(); | ||
script.doOperationRemotely(); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This transaction is probably causing the migration to be slow, we probably can optimise this by joining courses with its feedback sessions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it to use EntityManager.getReference.