Watch a live product demo 👀 See how Sanity powers richer commerce experiences

Can Multiple Datasets Have Different Schemas?

12 replies
Last updated: Jun 27, 2022
so if i have a project, with multiple datasets, can the datasets have different schemas?
is it as simple as having different branches in git for each dataset? or i guess even just different
studio
repos?
Jun 27, 2022, 9:06 PM
You can have as many Studios as you'd like for a given project and since the backend is schemaless different datasets can have completely different content models.
The issue arises when you try to have datasets with different schema shown in a single project. You need to do something like set up a conditional desk structure to only show schema relevant to the current active dataset. Note that your
schema.js
would need to have all possible schema defined in it though!
Jun 27, 2022, 9:09 PM
hmm k. so maybe i need to go refresh on all the different parts of how sanity is put together.
but what would be the point of multiple datasets if they all have the same schemas?

im trying to setup a project with my staging and production datasets.

but if i make a schema change and deploy it on staging to test. won't that break production dataset. i understand the data will be available without breaking, but if a content writer goes into the studio, they will see errors about the data not being correct, no?)
Jun 27, 2022, 9:53 PM
Speaking for myself, I think one point would be seeing what effects certain actions would have on the live data without the data being live.
Maybe you'd like to run a script that iterates over documents to substitute fields or change values before/after changing a schema in place, maybe you want to test locally writing new components that patch the data in a specific way but don't want the results to possibly botch everything if you don't get it perfect right out of the gate, etc.
Jun 27, 2022, 9:58 PM
but what would be the point of multiple datasets if they all have the same schemas?
Many reasons. Access control, separation of concerns, multi-tenant Studios.

but if i make a schema change and deploy it on staging to test. won't that break production dataset. i understand the data will be available without breaking, but if a content writer goes into the studio, they will see errors about the data not being correct, no?)
Publishing changes to a staging dataset wouldn't have any effect on a production dataset. They're separate datasets.
Jun 27, 2022, 9:58 PM
Publishing changes to a staging dataset wouldn't have any effect on a production dataset. They're separate datasets.
but if i run
sanity deploy
it will change the schema for both studios, right?
Jun 27, 2022, 10:02 PM
Ah, those are two different things. If you are using the same Studio for both staging and production, then yes, deploying your schema changes would effect production. However, if you're just changing content in a separate dataset, no, it will not effect the other dataset unless you migrate those changes.
Jun 27, 2022, 10:08 PM
right, ok thanks for clarifying
Jun 27, 2022, 10:08 PM
This guide will walk you through using spaces within a single Studio to switch between your production and staging datasets. That may be enough for your use case here!
Jun 27, 2022, 10:11 PM
so if i'm building a site for my company and we want
dev -> staging -> production datasets/schema

we will need multiple projects under our organization:


MyCompanySite - Dev

MyCompanySite - Staging

MyCompanySite - Prod

and then any schema changes would need a
sanity deploy
Jun 27, 2022, 10:11 PM
ok thanks, i will take a look
Jun 27, 2022, 10:11 PM
Got it! So you will want to use spaces to switch between datasets. In terms of your Studio, I would go ahead and use separate branches for each dataset so that you can merge changes as you see fit. Then I'd only run
sanity deploy
from the
prod
branch.
Jun 27, 2022, 10:16 PM
Note that you'd need to upgrade to the Team plan to get access to three datasets, though.
Jun 27, 2022, 10:17 PM

Sanity– build remarkable experiences at scale

The Sanity Composable Content Cloud is the modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Related answers

Get more help in the community Slack

TopicCategoriesFeaturedRepliesLast Updated
After adding the subtitle and running this code npm run graphql-deploy It does nothingSep 15, 2020
how to limit a reference to just one entry in Studio reference input side versus the default as-many-entries-as-you-fill-in-an-array...Sep 18, 2020
Is it possible to fetch more than one "_type" using GROQ?Nov 2, 2020
I want to add a view with the Structure builder (S.view.component) where I list similar documents based on the title. What...Sep 23, 2020
Is there a structure builder example where the format of each preview for the document list is modified?Feb 3, 2021
I have an array of references to a country schema type but it always just returns NULL values for meJan 30, 2021
Hi, I need help with a query for getting the url of an image asset. Here is what I've been trying, but I only get the _ref...Dec 1, 2020
Sanity UI looks brilliant :smiley: Is something like the current date picker possible at the moment? I’m not sure if anicon...Dec 21, 2020
Hey everyone. I have been coding and may have potentially accidentally deleted something. Does anyone know how to resolve...Dec 26, 2020
Hello everyone and happy new year :raised_hands::skin-tone-2:, I have a problem with outputting Portable Text :disappointed:...Jan 1, 2021

Related contributions

Clean Next.js + Sanity app
- Template

Official(made by Sanity team)

A clean example of Next.js with embedded Sanity ready for recomposition.

Cody Olsen
Go to Clean Next.js + Sanity app

Blog with Built-in Content Editing
- Template

Official(made by Sanity team)

A Sanity-powered blog with built-in content editing and instant previews.

Go to Blog with Built-in Content Editing