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 clarification about Data Migrations and updated example #1358

Merged
merged 3 commits into from
Sep 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions website/docs/10_going-deeper/data-migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ Data migrations are not run automatically, you need to invoke the `BoosterDataMi

Take into account that, depending on your cloud provider implementation, data migrations are executed in the context of a lambda or function app, so it's advisable to design these functions in a way that allow to re-run them in case of failures (i.e. lambda timeouts). In order to tell Booster that your migration has been applied successfully, at the end of each `DataMigration.start` method, you must emit a `BoosterDataMigrationFinished` event manually.

Inside your `@DataMigration` classes, you can use the `Booster.migrateEntity` method to update the data for a specific entity. This method takes the old entity name, the old entity ID, and the new entity data as arguments. It will also generate an internal `BoosterEntityMigrated` event before performing the migration.
Inside your `@DataMigration` classes, you can use the `BoosterDataMigrations.migrateEntity` method to update the data for a specific entity. This method takes the old entity name, the old entity ID, and the new entity data as arguments. It will also generate an internal `BoosterEntityMigrated` event before performing the migration.

Here is an example of how you might use the `@DataMigration` decorator and the `Booster.migrateEntity` method to update the quantity of the first item in a cart:
**Note that Data migrations are only available in the Azure provider at the moment.**

Here is an example of how you might use the `@DataMigration` decorator and the `Booster.migrateEntity` method to update the quantity of the first item in a cart (**Notice that at the time of writing this document, the method `Booster.entitiesIDs` used in the following example is only available in the Azure provider, so you may need to approach the migration differently in AWS.**):

```typescript
@DataMigration({
Expand All @@ -129,7 +131,7 @@ export class CartIdDataMigrateV2 {
carts.map(async (cart) => {
cart.cartItems[0].quantity = 100
const newCart = new Cart(cart.id, cart.cartItems, cart.shippingAddress, cart.checks)
await Booster.migrateEntity('Cart', validCart.id, newCart)
await BoosterDataMigrations.migrateEntity('Cart', validCart.id, newCart)
return validCart.id
})
)
Expand Down
Loading