Supercharge your dataset workflow with Advanced Dataset Management (ssr)

Written by Bryan Robinson

Missing Image!

Larger projects come with more sophisticated needs for continuous integration and handling of datasets. That's why we've created a set of tools to make this process more streamlined. We call these tools Advanced Dataset Management, and they're available today for enterprise customers.

Advanced Dataset Management launches with two new features: Cloud Clone and Dataset Hotswap. With these two features, much of the manual workflow with exports and imports can be automated away.

Hands-off dataset copying with Cloud Clone

Instead of manually exporting and then importing datasets, you can now run a CLI command or hit an HTTP API endpoint to clone a dataset directly in the Sanity infrastructure. This is perfect for testing data in Continuous Integration flows, testing migrations, or working from an up-to-date dataset for new feature development.

To run via the CLI, a new subcommand has been added to the sanity dataset command structure.

# Run from within a configured Sanity project
# Copy's first argument is the dataset to copy
# The second argument is the name of a new dataset to be created
sanity dataset copy production newDataset

By default the copy command will run the copy synchronously so that you can monitor the process, but if you're running it as part of a CI process, you can use the --detach flag to run it in the background.

Cloning can also be initiated and monitored via the HTTP API by sending a request to specific endpoints.

curl --location --request PUT 'https://api.sanity.io/v1/projects/<project-id>/datasets/<dataset-name>/copy' \
  -H 'Authorization: Bearer <token-here>' \
  -H 'Content-Type: application/json' \
  --data-raw '{
    "targetDataset": "production-copy"
  }'

For full usage, read the documentation for Cloud Clone.

Create aliases for datasets and Hot Swap what they reference on the fly

Dataset Hot Swapping allows a codebase to reference a single, named entity, which can then point to different datasets depending on the need of the project.

This feature is great for projects that need to make large amounts of edits to a dataset and put all those changes live at one time without making any changes to the front-end code.

The feature is included in the Sanity CLI as a subcommand of the sanity dataset command. With a series of commands, a developer can create an alias, link it to a dataset, and then when a new dataset is needed, hot swap the underlying dataset that the alias references.

# Create a new alias
sanity dataset alias create <new-alias> <dataset-to-alias>

# Change what dataset an alias points to
sanity dataset alias link <alias-to-point> <dataset-to-point-to>

Read up on all the Hot Swap commands and details in the official documentation.

Upgrade the Sanity CLI

If your project is on an enterprise plan, you can upgrade your Sanity CLI to take advantage of these powerful new features.

# Upgrade the Sanity CLI
npm install -g @sanity/cli

# Upgrade your project
sanity upgrade

These tools are only available on Enterprise plans. If your project needs Advanced Dataset Management, reach out to find out how to upgrade your plan.