-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2962 from reactioncommerce/seun-migration-1.0-1.5
Create migration files for upgrade from 1.0 to 1.5
- Loading branch information
Showing
15 changed files
with
279 additions
and
14 deletions.
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