What are Sanity Migrations?
Sanity Migrations allow you to independently migrate content from Staging to different environments. You can therefore implement changes in Staging environment, test them, and afterwards push those changes to QA and Production.
All this is accomplished with some clicks in the User Interface of Sanity.
Overview
As our platforms continue to scale internationally, demand for sanity data migrations has increased and has put more pressure on the engineering side as this was previously a technical task.
...
Brand/region content teams are now able to create, test, and push their own data within Sanity.
Automatically pulls in all references documents and assets preventing failed data migrations due to missing children references.
More tactical than the current implementation wherein we need to move documents by type - meaning if we want to move a single offer, we currently need to move all offer documents and all possible child reference document types.
Time to move data is reduced tremendously. To move one static page to production or QA, it now takes 10 seconds, where it used to take up to 20 mins (depending on dataset size).
Content Managers
...
.
Burger King
...
Primary Owner
...
Secondary Owner
...
Region
...
...
...
US 🇺🇸
...
...
CA 🇨🇦
...
...
CH 🇨🇭
...
...
DE 🇩🇪
...
...
ZA 🇿🇦
...
...
GB 🇬🇧
Popeyes
...
Primary Owner
...
Secondary Owner
...
Region
...
...
...
US 🇺🇸
...
...
TBD
...
CA 🇨🇦
...
...
TBD
...
CH 🇨🇭
Tim Hortons
...
Primary Owner
...
Secondary Owner
...
Region
...
...
TBD
...
US 🇺🇸
...
...
...
CA 🇨🇦
Ground Rules
You need a write token in order to use this tool. If you need one, request it from Posk, Mitchell (Deactivated) in the #sanity-migrations-owners slack channel your RBI tech contact (save it locally on your computer so you can re-use it). DO NOT SHARE THIS TOKEN. There should be one primary point of contact that is in charge of migrations for each brand/region, and one additional fallback migration owner in case the primary owner is out of office.
Migrate data first to QA, validate the changes there, then move it from staging to production (the tool will only let you migrate from staging as staging is the source of truth).
...
When the migration is complete you will see a success message, if it errors, please reach out to Posk, Mitchell (Deactivated) in the #sanity-data-migration-owners slack channelyour RBI tech contact.
...
Using the Tool
The Migration tool allows you to migrate multiple documents using a GROQ query, as opposed to only moving the currently viewed document (both tools also move children references). In terms of functionality, the actual migration tool works the same as the document action.
...
If you are unfamiliar with GROQ queries, you can see some of the most used patterns here.
Example of Queries to use for specific circumstances:
MIGRATES WHOLE MENU BUT DOES NOT INCLUDE OFFERS (images do not go down):
*[_id in ["feature-menu-singleton"]][0..10000]
MIGRATES ALL OFFERS (images do not go down):
*[_id in ["feature-offers-singleton"]][0..10000]
MIGRATES ALL STATIC PAGES:
*[_type in ["staticPage"]][0..10000]
PUSHES WHAT WE SHOW ON THE HOMEPAGE
*[_id in ["feature-home-page-singleton"]][0.
...
Future Improvements
...
.10000]
UPDATES ONLY MARKETING TILES:
*[_type in ["marketingTile", "marketingTileGroup"]][0..10000]
MIGRATING BY TYPE OF DOCUMENT
*[_type in ["item"]][0..10000] -this migrates all items (all documents with type item)
*[_type in ["offers"]][0..10000] -this migrates all offers (all documents with type offer)
You can use the above query to query all types available. These are just a few examples.