Dataset vs Studio: Do I need separate Sanity projects for each environment?
we have set up our Sanity Studio like this, companyname.sanity.studio - 4 datasets:
Dev
QA
Stag
Prod
But we found out that when doing changes to the studio in one dataset it changes to all datasets in the same Studio.
Now
user H tells me we need 4 different environments and studios to avoid this, is this how Sanity has built this?
We only use this for one website, so I think it is a bit strange to have 4 different projects.
Please explain how you have built this. Thanks
You don't need four projects. Keep one project with one dataset per environment, and deploy a separate Studio for each environment from the same codebase. Schema and Studio configuration are code, not data, so a change only reaches an environment when you deploy that environment's Studio. That lets QA test a schema change on the dev/QA Studio before it goes to production.
Why the change showed up everywhere
If all four datasets sit in one Studio deployment (for example as workspaces you switch between from a dropdown), every sanity deploy ships the whole Studio. That means all workspaces get the new code at the same moment. Workspaces work well for switching datasets, but they don't let you stage schema changes.
One Studio per environment
Sanity projects are no longer tied to a single Studio. You can deploy several studios that talk to the same project and datasets (details). Sanity hosting supports multiple studios for different environments under the same project.
1. Configure the Studio from environment variables
Studio environment variables need the SANITY_STUDIO_ prefix. Use them for project, dataset and deployment settings in sanity.cli.ts, and read the same variables for projectId/dataset in sanity.config.ts:
// sanity.cli.ts
import {defineCliConfig} from 'sanity/cli'
export default defineCliConfig({
api: {
projectId: process.env.SANITY_STUDIO_PROJECT_ID,
dataset: process.env.SANITY_STUDIO_DATASET,
},
deployment: {
appId: process.env.SANITY_STUDIO_APP_ID,
autoUpdates: true,
},
})Give each environment its own values: dataset dev/qa/stag/prod and its own app ID. build and deploy run in production mode by default. Setting SANITY_ACTIVE_ENV selects another mode, for example SANITY_ACTIVE_ENV=development loads .env and then .env.development (course). Don't put secrets in committed .env files.
2a. Host each one on Sanity
SANITY_ACTIVE_ENV=development npx sanity@latest deploy # e.g. companyname-dev.sanity.studio
npx sanity@latest deploy # companyname.sanity.studioOn the first deploy of each environment you pick a hostname and are offered an appId. Save it in that environment's variables. studioHost is deprecated in favor of deployment.appId (hosting docs). In CI, set SANITY_AUTH_TOKEN to a deploy token created in Manage.
2b. Or self-host (for example on Vercel)
This gives you branch and PR preview deployments, with each environment's variables set per branch:
- Build with
npx sanity@latest build. Your host must use single-page-app routing. - Add each Studio URL as a CORS origin with credentials allowed.
- Register each Studio and deploy its schema so Dashboard, Media Library, Canvas and similar features can find it:
npx sanity@latest deploy --external --url https://qa.example.com/studioIf you serve the Studio under a subpath, set project.basePath in sanity.cli.ts (or SANITY_STUDIO_BASEPATH) and include it in --url.
Workflow
Develop the schema on a branch, deploy it to the dev Studio, promote it to the QA and staging Studios, and deploy the production Studio only after it passes. Content stays separated by dataset. Keeping schema and configuration in source control and promoting them like this is the approach Sanity recommends.
Show original thread18 replies
Was this answer helpful?
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.