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

Introduce MigrationType #897

Merged
merged 2 commits into from
Jul 13, 2023
Merged

Introduce MigrationType #897

merged 2 commits into from
Jul 13, 2023

Conversation

shtukas
Copy link
Contributor

@shtukas shtukas commented Jul 12, 2023

When we introduced the 2023 membership price migrations, we introduced the concept of parametrisation of basic functions with CohortSpecs. Back then we got away with if (cohort detections) then ... else (else if ...) the existing code, but with more of such customised migrations coming, it was time for a refactoring.

For this we introduce sealed trait MigrationType, leading to a much cleaner and more readable code.

MigrationType does not identity a migration (Sometime several migrations map to a unique migration type, for instance both Membership 2023 Batch 1 and Batch 2 both map to type Membership2023Monthlies, whereas Membership 2023 Batch 3 identifies with Membership2023Annuals. It simply helps identify common code used by possibly more than one migration.

All pre 2023 migrations map to type Legacy.

Copy link
Member

@kelvin-chappell kelvin-chappell left a comment

Choose a reason for hiding this comment

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

This is a great idea and makes much more readable code. 👍
I had a trivial suggestion for one piece of code, which you can ignore if you think it doesn't help.

Comment on lines +162 to +166
forceEstimated = MigrationType(cohortSpec) match {
case Membership2023Monthlies => true
case Membership2023Annuals => true
case _ => false
}
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if this is an improvement or not:

Suggested change
forceEstimated = MigrationType(cohortSpec) match {
case Membership2023Monthlies => true
case Membership2023Annuals => true
case _ => false
}
forceEstimated = MigrationType(cohortSpec) == Membership2023Monthlies || MigrationType(cohortSpec) == Membership2023Annuals

Comment on lines +84 to +88
val forceEstimated = MigrationType(cohortSpec) match {
case Membership2023Monthlies => true
case Membership2023Annuals => true
case _ => false
}
Copy link
Member

Choose a reason for hiding this comment

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

This is same as above. Could possibly be extracted

@shtukas
Copy link
Contributor Author

shtukas commented Jul 13, 2023

@kelvin-chappell
Amazing! Thanks!

I had a trivial suggestion for one piece of code

I am going to leave it as it is, because I am just about to add a new migration type, and will refactor (make those simplifications) once the new one is in :)

@shtukas shtukas merged commit 90a4827 into main Jul 13, 2023
1 check passed
@shtukas shtukas deleted the ph-20230709-refactoring branch July 13, 2023 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants