-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Fix remove code from promotions migration #3108
Fix remove code from promotions migration #3108
Conversation
spree_promotions table used to be named spree_activators in legacy spree versions. This table was used by many models with STI via the type column. After it has been renamed into spree_promotions, having this type field does not make sense anymore.
Promotions could have code nil, but also an empty string. This commit takes into account this scenario since we don't want to take any action on promotions with code nil or empty.
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.
I am okay with this.
This might be something worth documenting on the Solidus blog?
I was wondering why we had so many issues with this migration. Looks great, thanks for debugging this! |
Yes, it's my fault not considering all the possible scenarios behind removing a simple/unused field. Lesson learned. We need more caution while removing fields from the database and probably even some tests on real stores database before merging. |
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.
@kennyadsl thank you for the fix, it's very much appreciated ❤️👍
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.
Thank you 👏
@kennyadsl Thank you for looking into this! We were just running into this issue ourselves last week. Does it make sense for legacy stores to drop the |
I think it makes sense to remove that column but I think it's better to do this into another PR/migration since it's not really related to the |
👍 |
This PR fixes two issues with the migration introduced into #3028.
Ref #2979
Please note that both issues are quite rare and we've found them by upgrading Solidus on very long-lived stores (previously on Spree).
I think it's better to backport these fixes into
v2.8
as well since the migration could fail and some custom change to it could be required.Promotions with type column set
spree_promotions
table used to be namedspree_activators
in legacy spree versions. This table was used by many models with STI via thetype
column. After that, it was renamed intospree_promotions
so having thistype
field does not make sense anymore.The issue here is that if you run this migration on stores that were created before the rename there will be that
type
field automatically set toSpree::Promotion
. This would raise an error while the migration runs:Promotions with empty string code (not nil)
code
field could be bothnil
and an empty string. If multiple empty string codes are present the migration would fail since it's not possible to have more than one code with an empty string in the database.Checklist: