Cloud Best Practices: Update Medusa Application
In this guide, you'll learn how to update your Medusa application that is deployed on Cloud.
Why Update Your Medusa Application?#
Medusa regularly releases new versions of the core application with bug fixes, performance improvements, and new features.
It's highly recommended to always keep your Medusa application up to date. You'll benefit from the latest improvements and security patches.
Update Your Deployed Medusa Application#
This section provides best practices for updating your Medusa application on Cloud and how to update your application in a safe manner.
Don't Push Directly to Production#
It's strongly discouraged to push a new update directly to your production branch. While Medusa updates are generally safe and stable, it's always a good practice to test the update in a separate environment before deploying it to production.
By using a separate environment, you mitigate any unexpected issues that may arise during the update process. This way, you ensure that your customizations and configurations work correctly with the new version of Medusa.
The recommended approach is to create a long-lived environment, such as Staging. You can push the new update and test it thoroughly in a production-like environment before deploying it to production.
Alternatively, you can open a pull request to the production branch, which will create a preview environment. The preview environment allows you to test the update before merging it into the production branch.
Ensure Custom Migrations Have Rollback Methods#
When creating custom migrations, it's important to include both up
and down
methods. The up
method should define the changes to be made to the database schema, while the down
method should reverse those changes.
By including both methods, you can easily roll back database changes if you need to revert the application's update.
If you use the db:generate command to generate migrations, it will automatically create both up
and down
methods for you. If you're creating the migrations manually, you can learn more in the Migrations guide.
Update Your Medusa Application#
To update your Medusa application deployed on Cloud:
- Update your Medusa application locally either on the long-lived environment's branch (for example, Staging) or in a new branch that will be used to create a pull request.
- To learn how to update your Medusa application, refer to the Update guide. It includes all the details you need to update the Medusa application locally.
- Once you're done updating your application locally, push the changes in
package.json
, lock file (for example,yarn.lock
), and any other affected files to the branch.- If you're using a long-lived environment, Cloud will automatically deploy the changes to the branch's environment.
- If you're using a new branch to create a pull request, open the pull request to the production branch. This will create a preview environment that you can use to test the update before merging it into the production branch.
Then, you can access the environment's live deployment to test the update. You can also use the build and runtime logs of the environment to debug any issues that occur during the update process or testing.
Push Update to Production#
Once you've thoroughly tested the update in your long-lived or preview environment, you can merge the changes into your production branch.
Cloud will automatically deploy the changes to the production environment. This will update the production's code and database.
Rollback Medusa Application Update#
If you encounter any issues after updating your deployed Medusa application, you can redeploy a previous deployment to roll back the code changes made by the update.
However, redeploying a previous deployment will not roll back the database changes made by the update. If you need to roll back the database changes, contact support for assistance.