Unlock seamless workflows and faster delivery with our latest releases – get the details

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

Sanity is a 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.

Was this answer helpful?