Using paths to handle data separation in Sanity.io datasets
39 replies
Last updated: Mar 1, 2023
A
Is there any way to pay for additional datasets without going for the Enterprise plan? I think we’d need 12 at work to migrate from Contentful.
Feb 28, 2023, 11:32 PM
No, datasets are unfortunately not available a la carte. However, it’s very unlikely that you actually need 12 datasets, since there are methods of separating data within a single dataset. What do you need the datasets for?
Feb 28, 2023, 11:59 PM
A
6 countries prod and the same for a testing/dev/staging env
Feb 28, 2023, 11:59 PM
A
Each country has different data handled by different teams
Mar 1, 2023, 12:00 AM
A
It’s not localization
Mar 1, 2023, 12:00 AM
You won’t need to separate the countries. You can get away with three datasets (testing/dev/staging) and use paths and a custom desk structure to handle the different data from different countries.
Mar 1, 2023, 12:01 AM
A
I looked a little bit at that before. Would we need to add the “country/market” as a field on every schema type?
Mar 1, 2023, 12:01 AM
A
Our merch teams can’t be picking that option when creating/editing things, so jt would have to be hidden and auto-selected.
Mar 1, 2023, 12:02 AM
No, you could handle that with the paths you set up and possibly initial values (unlikely if you have the paths set up correctly, though).
Mar 1, 2023, 12:03 AM
A
paths?
Mar 1, 2023, 12:04 AM
Mar 1, 2023, 12:04 AM
A
ah so prefixing ids with the country
Mar 1, 2023, 12:05 AM
A
can you query a collection where the ids contain x then as well?
Mar 1, 2023, 12:05 AM
A
say I want all of SchemaType for Country
Mar 1, 2023, 12:07 AM
We do similar things with the source of tickets in Support here:
ticket.sla.<id>or
ticket.community.<id>when it comes time to query we can use the
path()function to separate things (
_id in path('ticket.community.**')). You can then add other filters to limit it to a certain schema type. Putting it all together, this would get me all of the products under the French market:
*[_type == 'product' && _id in path('fr.**')]
Mar 1, 2023, 12:11 AM
A
Cool
Mar 1, 2023, 12:11 AM
A
And a reference in the sanity UI, can I make that only show, say the fr. tags for a product in fr.?
Mar 1, 2023, 12:12 AM
A
If would be good if that kind of thing wasn’t completely manual for each field, Querying is easier because you start from the top
Mar 1, 2023, 12:14 AM
Do you mean translation of the Studio’s UI (like headings and field names) or tag data in your dataset? If it’s the former, unfortunately, the Studio cannot have different translations. If it’s the latter you sure can!
Mar 1, 2023, 12:14 AM
A
There’s no translations. Here’s the senario. Assuming we have a Product schema type and a Tag schema type (like vegan, gluten-free, whatever):
Mar 1, 2023, 12:16 AM
A
Then we have a team who only cares about the fr. data
Mar 1, 2023, 12:16 AM
A
Can they view the studio in a way that they by default only see fr. Products, and if they were to add a reference to a Tag on a Product, the dropdown of available Tags also only show fr. tags.
Mar 1, 2023, 12:17 AM
A
Awesome, might go with sanity then!
Mar 1, 2023, 12:22 AM
A
I will tell my colleague about this functionality. It was the main blocker.
Mar 1, 2023, 12:22 AM
A
Except for migrating ofc
Mar 1, 2023, 12:23 AM
A
But I’m loving the embedded studio and the schema-driven development on my personal site already.
Mar 1, 2023, 12:23 AM
A
Thank you for answering my questions!
Mar 1, 2023, 12:24 AM
Of course! When it comes time to migrate, you can make it a bit easier for yourself using this repo.
Mar 1, 2023, 12:24 AM
A
Awesome! I suspect we’d need to tweak a bit given what we currently have
Mar 1, 2023, 12:26 AM
A
But should be helpful to start.
Mar 1, 2023, 12:26 AM
S
Paths are great if only creating via the api but there is no real way ive found to setup initial _id values. We have a couple sites setup with reference fields to a ‘site/language’ field that is hidden for editors and autofilled by initial value templates based on the current desk structure context. Happy to send you some examples Alvar
Mar 1, 2023, 5:15 AM
S
And this dataset limitation is pretty annoying. You could also have multiple projects with the same schema
Mar 1, 2023, 5:17 AM
A
Please do send!
user A
Mar 1, 2023, 6:06 AM
A
user M
How does ID generation work? The Sanity Studio automatically generates a random UUID for new documents (e.g. 189bc292-e41b-42a0-91b5-bfaa33a34af2), and does not allow you to specify an ID yourself, but you are free to use your own ID scheme for documents that you create using the HTTP API.
Mar 1, 2023, 11:40 AM
A
Do I have to call an API instead of using the UI to create?
Mar 1, 2023, 11:40 AM
S
Mar 1, 2023, 12:00 PM
You can use an initial value and a custom publish action to preserve your paths.
Mar 1, 2023, 5:34 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.