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

Datamigration for new Fulfillment type feature #6544

Closed
wants to merge 7 commits into from

Conversation

sujithvn
Copy link
Contributor

@sujithvn sujithvn commented Oct 4, 2022

Resolves #6472
Impact: breaking
Type: feature

This PR is replaced by #6633

Issue

Migrate data to the new format required for the new FFT plugins

Solution

We have 3 stages in a single migration;

  • Copies over the existing Shipments & FlatRateFulfillmentRestrictions collections to Fulfillment & FulfillmentRestrictions collections respectively
  • Updates the Fulfillment collection with the newly introduced fields (fulfillmentType & fulfillmentMethod). Since the existing user base had only Shipping/Flatrate as the fulfillment type/method till date, we would be using those values to update collection
  • update the Groups collection with the new permissions

Breaking changes

The 2nd stage above handles the breaking change where we would be using the possible existing values as the values or newly introduced fields.

Testing

In an existing installation, perform the data-migration. Update the installation to use the new version having fulfillment types. All activities in admin/shop (related to Products/Orders/FF-types/Catalogs/Carts) should continue to work without issues

To test migration steps, install api-migrations package and include the below entry in the migrator.config.js file.

export default {
  tracks: [
    {
      namespace: "fulfillment",
      package: "../reaction/packages/api-plugin-fulfillment",
      version: 2
    }
  ]
};

Run the command:
MONGO_URL=mongodb://localhost:27017/reaction npx migrator migrate

Signed-off-by: Sujith <mail.sujithvn@gmail.com>
Signed-off-by: Sujith <mail.sujithvn@gmail.com>
Signed-off-by: Sujith <mail.sujithvn@gmail.com>
@changeset-bot
Copy link

changeset-bot bot commented Oct 4, 2022

⚠️ No Changeset found

Latest commit: 81bde07

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Signed-off-by: Sujith <mail.sujithvn@gmail.com>
@sujithvn sujithvn changed the base branch from trunk to sujith/monorepo October 6, 2022 12:11
@sujithvn sujithvn marked this pull request as ready for review October 10, 2022 03:40
packages/api-plugin-fulfillment/migrations/4.js Outdated Show resolved Hide resolved
packages/api-plugin-fulfillment/migrations/3.js Outdated Show resolved Hide resolved
Signed-off-by: Sujith <mail.sujithvn@gmail.com>
Signed-off-by: Sujith <mail.sujithvn@gmail.com>
Copy link
Collaborator

@zenweasel zenweasel left a comment

Choose a reason for hiding this comment

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

A few changes needed here

async function up({ db, progress }) {
progress(0);

await db.collection("Groups").updateMany({
Copy link
Collaborator

Choose a reason for hiding this comment

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

This just adds them to shop manager and owner which is fine if they used the Out of the Box permissions and made no changes, but what it actually should do is add it to any group that has the old equivalent permissions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zenweasel

When we say "any group that has the old equivalent permissions", does it mean any group which would have the same entries in the array as of shop-manager and owner?

If the user has made a minor add/remove of any entry, then how do we decide whether that groups has to be considered or not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zenweasel
As discussed, I have made the code change to update 'any' group that has the permissions.
As per the change, we are checking each group for any of the old permissions (related to shipping) and inserting the corresponding individual FFT permissions (using a mapper) in all of the impacted groups.

pnpm-lock.yaml Show resolved Hide resolved
Signed-off-by: Sujith <mail.sujithvn@gmail.com>
@aldeed aldeed removed their request for review December 8, 2022 19:21
@sujithvn
Copy link
Contributor Author

sujithvn commented Dec 9, 2022

This PR is replaced by 6633
#6633

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.

As an admin I want to be able to migrate my data to the new format required for the new FFT plugins
3 participants