-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Create migration files for upgrade from 1.0 to 1.5 #2962
Merged
Merged
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
49aef2f
Check for null on object references before using
impactmass 902124f
Migration - Set a primary shop needed in a multi-shop world
impactmass e5567cf
Migration - add / remove shopId on billing objects on orders and cart
impactmass e542836
Migration - add / remove shopId on shipping objects on orders and cart
impactmass 5eb7b01
Migration to rebuild search collections
impactmass 8419cec
Merge branch 'marketplace' into seun-migration-1.0-1.5
impactmass 52c95ae
Migration - Update cart schema to include all product data #2610
impactmass 7094c44
Reset changes on 1_rebuild_account_and_order_search_collections
impactmass 4fc866a
Check field references before using
impactmass 948074a
Add down migration for step 9
impactmass 547cdaf
Direct update on down to enable restore to previous data state
impactmass 0b062fb
Merge branch 'marketplace' into seun-migration-1.0-1.5
impactmass b0b4998
Add Array.isArray checks
impactmass 0c99835
Merge branch 'marketplace' into seun-migration-1.0-1.5
impactmass 5236509
Merge branch 'seun-migration-1.0-1.5' of github.com:reactioncommerce/…
impactmass a7dfb46
Check currency before using
impactmass 843f824
Add up migration to update shipping status to workflow
impactmass 5da6373
Add down() for shipping status and fix typo on new status
impactmass 0b27b43
Merge branch 'marketplace' into seun-migration-1.0-1.5
impactmass 2fc56b0
Add Array.isArray check before calling reduce
impactmass 585abd6
Merge branch 'marketplace' into seun-migration-1.0-1.5
spencern 7cdc7c9
Merge branch 'marketplace' into seun-migration-1.0-1.5
spencern 6c5d774
Merge branch 'marketplace' into seun-migration-1.0-1.5
spencern File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
imports/plugins/core/versions/server/migrations/10_set_primary_shop.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Migrations } from "meteor/percolate:migrations"; | ||
import { Reaction } from "/server/api/"; | ||
import { Shops } from "/lib/collections"; | ||
|
||
Migrations.add({ | ||
// moving to multi-shop setup requries a primary shop to be set. | ||
// Updates a shop marked active, that has associated email for domain as the primary shop | ||
version: 10, | ||
up() { | ||
Shops.update({ | ||
"status": "active", | ||
"domains": Reaction.getDomain(), | ||
"emails.0.address": { $exists: true } | ||
}, { | ||
$set: { shopType: "primary" } | ||
}); | ||
}, | ||
down() { | ||
Shops._collection.update({ shopType: "primary" }, { | ||
$unset: { shopType: "" } | ||
}); | ||
} | ||
}); |
51 changes: 51 additions & 0 deletions
51
imports/plugins/core/versions/server/migrations/11_add_product_to_cart_items.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Migrations } from "meteor/percolate:migrations"; | ||
import { Cart, Orders, Products } from "/lib/collections"; | ||
|
||
Migrations.add({ | ||
version: 11, | ||
up() { | ||
// Add whole product object to all cart items in all Cart documents if the cart has an item added | ||
Cart.find().forEach((cart) => { | ||
if (Array.isArray(cart.items) && cart.items.length) { | ||
cart.items.forEach((item) => { | ||
item.product = Products.findOne({ _id: item.productId }); | ||
}); | ||
Cart.update({ _id: cart._id }, { | ||
$set: { items: cart.items } | ||
}); | ||
} | ||
}); | ||
|
||
// Add whole product object to all order items in all order documents | ||
Orders.find().forEach((order) => { | ||
order.items.forEach((item) => { | ||
item.product = Products.findOne({ _id: item.productId }); | ||
}); | ||
Orders.update({ _id: order._id }, { | ||
$set: { items: order.items } | ||
}); | ||
}); | ||
}, | ||
// Going down, we remove the product object on each item in cart and order | ||
down() { | ||
Cart.find().forEach((cart) => { | ||
if (Array.isArray(cart.items) && cart.items.length) { | ||
cart.items.forEach((item) => { | ||
delete item.product; | ||
}); | ||
Cart._collection.update({ _id: cart._id }, { | ||
$set: { items: cart.items } | ||
}); | ||
} | ||
}); | ||
|
||
Orders.find().forEach((order) => { | ||
order.items.forEach((item) => { | ||
delete item.product; | ||
}); | ||
Orders._collection.update({ _id: order._id }, { | ||
$set: { items: order.items } | ||
}); | ||
}); | ||
} | ||
}); |
37 changes: 37 additions & 0 deletions
37
imports/plugins/core/versions/server/migrations/12_add_shopId_on_billing.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Migrations } from "meteor/percolate:migrations"; | ||
import { Cart, Orders } from "/lib/collections"; | ||
import { Reaction } from "/server/api/"; | ||
|
||
Migrations.add({ | ||
version: 12, | ||
up() { | ||
// moving to multi-shop setup requires each billing objects to be marked by shopId | ||
// This adds shopId field to each billing object in orders and carts. | ||
const shopId = Reaction.getShopId(); | ||
|
||
Orders.update({}, { | ||
$set: { "billing.0.shopId": shopId } | ||
}, { | ||
multi: true | ||
}); | ||
|
||
Cart.update({}, { | ||
$set: { "billing.0.shopId": shopId } | ||
}, { | ||
multi: true | ||
}); | ||
}, | ||
down() { | ||
Orders.update({}, { | ||
$unset: { "billing.0.shopId": "" } | ||
}, { | ||
multi: true | ||
}); | ||
|
||
Cart.update({}, { | ||
$set: { "billing.0.shopId": "" } | ||
}, { | ||
multi: true | ||
}); | ||
} | ||
}); |
37 changes: 37 additions & 0 deletions
37
imports/plugins/core/versions/server/migrations/13_add_shopId_on_shipping.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Migrations } from "meteor/percolate:migrations"; | ||
import { Cart, Orders } from "/lib/collections"; | ||
import { Reaction } from "/server/api/"; | ||
|
||
Migrations.add({ | ||
version: 13, | ||
up() { | ||
// moving to multi-shop setup requires each shipping objects to be marked by shopId | ||
// This adds shopId field to each shipping object in orders and carts. | ||
const shopId = Reaction.getShopId(); | ||
|
||
Orders.update({}, { | ||
$set: { "shipping.0.shopId": shopId } | ||
}, { | ||
multi: true | ||
}); | ||
|
||
Cart.update({}, { | ||
$set: { "shipping.0.shopId": shopId } | ||
}, { | ||
multi: true | ||
}); | ||
}, | ||
down() { | ||
Orders.update({}, { | ||
$unset: { "shipping.0.shopId": "" } | ||
}, { | ||
multi: true | ||
}); | ||
|
||
Cart.update({}, { | ||
$set: { "shipping.0.shopId": "" } | ||
}, { | ||
multi: true | ||
}); | ||
} | ||
}); |
18 changes: 18 additions & 0 deletions
18
imports/plugins/core/versions/server/migrations/14_rebuild_order_search_collection.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Migrations } from "meteor/percolate:migrations"; | ||
import { OrderSearch } from "/lib/collections"; | ||
import { buildOrderSearch } from "/imports/plugins/included/search-mongo/server/methods/searchcollections"; | ||
|
||
Migrations.add({ | ||
// Migrations 12 and 13 introduced changes on Orders, so we need to rebuild the search collection | ||
version: 14, | ||
up: function () { | ||
OrderSearch.remove({}); | ||
buildOrderSearch(); | ||
}, | ||
down: function () { | ||
// whether we are going up or down we just want to update the search collections | ||
// to match whatever the current code in the build methods are. | ||
OrderSearch.remove({}); | ||
buildOrderSearch(); | ||
} | ||
}); |
78 changes: 78 additions & 0 deletions
78
imports/plugins/core/versions/server/migrations/15_update_shipping_status_to_workflow.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { Migrations } from "meteor/percolate:migrations"; | ||
import { Orders } from "/lib/collections"; | ||
|
||
Migrations.add({ | ||
version: 15, | ||
// Reaction v1.0 had 3 shipping boolean states (packed, shipped, delivered). Shipping workflow is not managed with a | ||
// workflow object that keeps track of previous state. | ||
up: function () { | ||
Orders.find().forEach((order) => { | ||
const currentShipping = order.shipping[0]; | ||
currentShipping.workflow = {}; | ||
|
||
if (currentShipping.packed) { | ||
currentShipping.workflow.status = "coreOrderWorkflow/packed"; | ||
currentShipping.workflow.workflow = ["coreOrderWorkflow/notStarted", "coreOrderWorkflow/packed"]; | ||
} | ||
|
||
if (currentShipping.shipped) { | ||
currentShipping.workflow.status = "coreOrderWorkflow/shipped"; | ||
currentShipping.workflow.workflow = [ | ||
"coreOrderWorkflow/notStarted", "coreOrderWorkflow/packed", "coreOrderWorkflow/shipped" | ||
]; | ||
} | ||
|
||
if (currentShipping.delivered) { | ||
currentShipping.workflow.status = "coreOrderWorkflow/delivered"; | ||
currentShipping.workflow.workflow = [ | ||
"coreOrderWorkflow/notStarted", | ||
"coreOrderWorkflow/packed", | ||
"coreOrderWorkflow/shipped", | ||
"coreOrderWorkflow/delivered" | ||
]; | ||
} | ||
|
||
// If none of the 3 v1.0 states is true, set as unstarted. | ||
// Note: In case of customized workflow status, modify here to capture the added status(es) before running the migration | ||
currentShipping.workflow.status = "new"; | ||
currentShipping.workflow.workflow = ["coreOrderWorkflow/notStarted"]; | ||
|
||
delete currentShipping.packed; | ||
delete currentShipping.shipped; | ||
delete currentShipping.delivered; | ||
|
||
Orders.update({ _id: order._id }, { | ||
$set: { "shipping.0": currentShipping } | ||
}); | ||
}); | ||
}, | ||
down: function () { | ||
Orders.find().forEach((order) => { | ||
const currentShipping = order.shipping[0]; | ||
const workflow = currentShipping.workflow; | ||
|
||
currentShipping.packed = false; | ||
currentShipping.shipped = false; | ||
currentShipping.delivered = false; | ||
|
||
if (workflow && workflow.status === "coreOrderWorkflow/packed") { | ||
currentShipping.packed = true; | ||
} | ||
|
||
if (workflow && workflow.status === "coreOrderWorkflow/shipped") { | ||
currentShipping.shipped = true; | ||
} | ||
|
||
if (workflow && workflow.status === "coreOrderWorkflow/delivered") { | ||
currentShipping.delivered = true; | ||
} | ||
|
||
delete currentShipping.workflow.workflow; | ||
|
||
Orders.update({ _id: order._id }, { | ||
$set: { "shipping.0": currentShipping } | ||
}); | ||
}); | ||
} | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should this be the hard-coded first shipping object or the shipping object associated with the current active shop?
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 did that to staying consistent with 1.0 (or below 1.5) codebase. It's all x[0] in there. Since this migration file is interacting with data created from such code, I referenced it that way.
I think it's more recently that we started referencing shipping it by shopId (i.e marketplace).