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] Data migration: ensure consistency when script is stopped and resumed #13046

Merged

Conversation

yuanxi1
Copy link
Contributor

@yuanxi1 yuanxi1 commented Apr 16, 2024

Part of #12048

Outline of Solution

  • Using the cursor saving mechanism from base sql script as checkpoints
    1. Cursor position is saved after successfully migrating a course entity
    2. Cursor position is loaded when first start up the script, and the course entity A it points to if is not marked as migrated, a casecadeDelete method will be called to delete all related entities in the sql database and migration will restart from A.

Edit:
CascadeType.REMOVE is already present for most parts of the chain but not present for Course-FeedbackSession, Course-User. For easier implementation for deleteCourseCascade, added cascade = CascadeType.REMOVE annotation for the two relations in Course.java.

@FergusMok FergusMok added the s.ToReview The PR is waiting for review(s) label Apr 17, 2024
Copy link
Contributor

@FergusMok FergusMok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, looks good to me, just very tiny nits

Copy link
Contributor

@NicolasCwy NicolasCwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on getting this out, some changes are required though

*/
private void deleteCourseCascade(Course oldCourse) {
// TODO: Implement deleteCourseCascase
log("delete course id: " + oldCourse.getUniqueId());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a one-liner, could we do this in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think calling HibernateUtil.remove(course) can cascade delete other entities, maybe need to do something like in CourseLogic

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right, I was originally thinking of using Cascade on delete annotation but there may be performance issues with this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think performance issues should be fine because deleting is expected to only happen rarely (error in validation, exception thrown, or halfway migrated)

Copy link
Contributor

@NicolasCwy NicolasCwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thank you for your work on this!

Copy link
Contributor

@FergusMok FergusMok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, especially on the more detailed parts of the logging and the cascade on users

@NicolasCwy NicolasCwy merged commit cd906cf into TEAMMATES:v9-course-migration Apr 22, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s.ToReview The PR is waiting for review(s)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants