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

Add and start populating spree_addresses.name field #3962

Merged

Conversation

spaghetticode
Copy link
Member

Description

In order to prepare apps for the Solidus 3.0 migration where firstname and lastname fields are completely removed from the DB, this PR introduces the field name and starts using it when creating new records, so backfilling will be required only for historical data prior to incorporating this change.

Also, this PR fixes a possible issue when comparing new addresses with double first names to historical records when the preference use_combined_first_and_last_name_in_address is set to true.

Checklist:

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

@spaghetticode spaghetticode self-assigned this Feb 26, 2021
core/app/models/spree/address.rb Outdated Show resolved Hide resolved
core/spec/models/spree/address_spec.rb Outdated Show resolved Hide resolved
core/spec/models/spree/address_spec.rb Outdated Show resolved Hide resolved
Rspec already provides `described_class`, so we don't need to
define that extra `subject`.
@spaghetticode spaghetticode force-pushed the spaghetticode/always-use-name-field branch from aff9765 to f24c008 Compare February 26, 2021 15:28
Given the field is there, and it's going to fully replace `firstname`
and `lastname` from Solidus 3.0, it makes sense to start using it
early so the migration process will be easier.
Even when the field `name` is not explicitly used yet (for example
when the preference `use_combined_first_and_last_name_in_address`
is set to false) we're going to backfill the DB when saving new
records starting from combining `firstname` and `lastname`, in order
to provide a smooth upgrade process to 3.0.
When comparing addresses, in order to be compatible with all
possible combinations, we should not use legacy attributes
such as `firstname` and `lastname` in the comparison, as they
may end up generating false negatives. Instead, using `name`
should be safer. For example:

  Spree::Address.new(name: 'Mary Jane Watson')

should be equal to:

  Spree::Address.new(firstname: 'Mary Jane', lastname: 'Watson')

This should happen only when the application has already started
moving towards the unique `name` field, i.e. when the preference
`Spree::Config.use_combined_first_and_last_name_in_address` is
set to `true`.

Differently, `firstname` and `lastname` should be accounted for
when checking equality, so that:

  Spree::Address.new(firstname: 'Mary Jane',  'Watson')

won't be equal to:

  Spree::Address.new(firstname: 'Mary',  'Jane Watson')
@spaghetticode spaghetticode force-pushed the spaghetticode/always-use-name-field branch from f24c008 to 7741d82 Compare February 26, 2021 15:39
@kennyadsl
Copy link
Member

@spaghetticode thanks! I tried this locally in a store with existing addresses in the old format and seems to work well, I just found one unrelated problem (already present in v2.11.4) that I documented here.

@kennyadsl kennyadsl added this to the 2.11 milestone Mar 1, 2021
Copy link
Member

@aldesantis aldesantis left a comment

Choose a reason for hiding this comment

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

I think this looks good, thanks @spaghetticode!

@kennyadsl kennyadsl merged commit 88ca1ce into solidusio:v2.11 Mar 5, 2021
@kennyadsl kennyadsl deleted the spaghetticode/always-use-name-field branch March 5, 2021 13:26
remove_index :spree_addresses, :name
remove_column :spree_addresses, :name
end
end
Copy link

Choose a reason for hiding this comment

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

Does it still count as a patch update if I need to run bin/rails railties:install:migrations?

Copy link
Member

Choose a reason for hiding this comment

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

Hey! Yes, unfortunately we had to do this change at a patch level because it is fixing the migration process for switching to the new addresses fields schema. We decided to consider this a patch instead of a new feature for this reason. Theoretically, a new migration doesn't always represent a new feature, although it's strange to have. We are sorry if this is causing issues and we are open to improving the documentation to help users upgrading. Let us know your thoughts.

Copy link

@schmijos schmijos Apr 9, 2021

Choose a reason for hiding this comment

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

I think having a more detailed CHANGELOG could have helped me to find the issue. I miss the gap between > 2.11.0 and < 3.0.0.

Copy link
Member

Choose a reason for hiding this comment

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

You are right. I'm preparing a PR that updates the Changelog here. Anyway, you can find details of each release in https://github.com/solidusio/solidus/releases.

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.

5 participants