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

Fix remove code from promotions migration #3108

Merged

Conversation

kennyadsl
Copy link
Member

@kennyadsl kennyadsl commented Feb 18, 2019

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 named spree_activators in legacy spree versions. This table was used by many models with STI via the type column. After that, it was renamed into spree_promotions so having this type 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 to Spree::Promotion. This would raise an error while the migration runs:

StandardError:
       An error has occurred, this and all later migrations canceled:

       Invalid single-table inheritance type: Spree::Promotion is not a subclass of RemoveCodeFromSpreePromotions::Promotion

Promotions with empty string code (not nil)

code field could be both nil 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:

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have added tests to cover this change (if needed)

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.
@kennyadsl kennyadsl added the type:bug Error, flaw or fault label Feb 18, 2019
@kennyadsl kennyadsl self-assigned this Feb 18, 2019
@kennyadsl kennyadsl added the WIP label Feb 18, 2019
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.
@kennyadsl kennyadsl changed the title Fix remove code from promotions with type set Fix remove code from promotions migration Feb 18, 2019
@kennyadsl kennyadsl removed the WIP label Feb 18, 2019
Copy link
Contributor

@jacobherrington jacobherrington left a 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?

@seand7565
Copy link
Contributor

I was wondering why we had so many issues with this migration. Looks great, thanks for debugging this!

@kennyadsl
Copy link
Member Author

kennyadsl commented Feb 18, 2019

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.

Copy link
Member

@spaghetticode spaghetticode left a 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 ❤️👍

Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

Thank you 👏

@kennyadsl kennyadsl merged commit ea37b2a into solidusio:master Feb 20, 2019
@kennyadsl kennyadsl deleted the kennyadsl/fix-promotion-code-removal branch February 20, 2019 20:53
@kennyadsl kennyadsl mentioned this pull request Feb 21, 2019
2 tasks
@brchristian
Copy link
Contributor

@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 type column? And if so, should that be part of this migration?

@kennyadsl
Copy link
Member Author

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 code column. Probably it would have been to create that migration before, but it's too late now since this migration is already part of a release (v2.8). 😢

@kennyadsl
Copy link
Member Author

@jacobherrington

This might be something worth documenting on the Solidus blog?

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Error, flaw or fault
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants