🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Deleting a schema in Sanity does not delete related documents, but they can be deleted in batch using the CLI. The discussion also provides an explanation of how Sanity's...

9 replies
Last updated: Jul 10, 2023
Hello. Sanity internal working question.
Does removing schema delete related documents?
Jun 17, 2023, 9:06 PM
Hi! No, deleting a schema does not impact your documents. If you have 30
post
documents and delete the
post
schema, those 30 documents will remain.
Jun 17, 2023, 11:33 PM
Thank you, (Removed Name). Can I delete them in batch then? Rather than individually. (from Studio, for e.g)
Jun 18, 2023, 6:11 AM
Just cripted the deletion of the latest document I removed
Jun 18, 2023, 6:16 AM
Two questions now:
• Can list existing documents?
• Does deleting all documents of a schema enough to delete get rid of that schema?
Jun 18, 2023, 6:17 AM
allo?
Jun 22, 2023, 7:53 AM
ping
Jul 10, 2023, 3:04 PM
Hi (Removed Name),
• You can list all of your existing documents using the
Vision plugin• You can
bulk delete documents with the cli, but that will not remove the schema
Jul 10, 2023, 5:07 PM
user T
, you have good answers from Sanity persons, but it's probably helpful to gain understanding of the system involved.
Sanity's Data Lake, where your data is stored, is a database -- built on the very capable globally high speed Google Cloud and BigQuery. This is not a SQL database, and is automatic as far as keeping track of its internal data schemas.

When you delete a schema original definition in your Studio source, the data and internal picture remain in the Data Lake -- you might still want to query it, so this is safe.

If you later write another version of that local Studio schema definition, then use it to enter data from the Studio, your fresh schema will be taken as the shape for the fresh data -- I am pretty confident without any need for extra actions by yourself.

This is provided you did your full delete of all prior data, as you have using sanity-cli (
sanity
calls from your terminal). If you forgot to do this, then you'd see alerts in the Studio pane where mismatched data would go, offering to delete that field entry, or if it can, to transform what doesn't fit.
At this point, you'd realize your mistake, stop the Studio, and do the full delete of that schema's documents, then return with your fresh schema. So you are safe to have things work according to your intentions.

The best way to be confident of understanding is to try your own experiments -- it's the kind of thing we do.

Add a test schema that you won't care about to your project. Put some simple data in it, a couple of records. Then modify the schema, and try entering data for this, so that you see the warnings come up for mismatches. Afterwards, use your
sanity
ccommand to delete the documents entirely. Now try entering from Studio again. Your new schema should be obeyed, and with no warnings. Now you are sure.
Good fortune,
(Removed Name)
Jul 10, 2023, 6:16 PM
This is an excellent explanation,
user Q
! Thank you!
Jul 10, 2023, 6:21 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?