Get a peek at our latest innovations at Sanity Product Day on Dec 8th →

Migrating Data and Export/Import to Remake Schemas

8 replies
Last updated: Jun 28, 2021

Hey! I have a scenario that I'm not sure of. Lets say I have two schemas, each containing one document. One named startPage and one named newPages. I now want to "remake" the startPage in to a NewPages, (move all the content and be able to remove schema startPage). They schemas look exactly the same, but startPage wasn't deletable. How do I accomplish that? Been reading about migrating data and export/import, but I'm not sure. Any suggestions?

Jun 18, 2021, 7:38 AM

Why was the document not deletable? I had a problem where one document crashed the desk and I couldn’t open it so I used a delete script to delete that document using it’s _id, save this file as delete.js and run using sanity exec delete.js. But backup your data first using sanity dataset export [your dataset name]

import sanityClient from 'part:@sanity/base/client'

const client = sanityClient.withConfig({apiVersion: '2019-05-28'})

client

.delete({query: '*[_type == "product" && _id == "YOUR ID HERE"][0]'})

.then(console.log)

.catch(console.error)

Jun 18, 2021, 10:36 PM

Either that or export the original dataset, import into the new dataset then rename the fields using this script https://www.sanity.io/schemas/rename-a-field-across-documents-5cd6f5f0

Jun 18, 2021, 10:37 PM

It is deletable, but for this schema I used the:

  __experimental_actions: [/*'create',*/ 'update', /*'delete',*/ 'publish']
Can I export/import just one schema, or do I have to export the whole original dataset? I've already done that when creating a Staging dataset. It's more that I want to move all the content from startPage and create a newPages instead (with that content) and then be able to delete the old startPage schema. So that all my pages (now with diffrent names) is converted in to newPages, so that I can have only one schema for all pages.

Jun 21, 2021, 6:53 AM

It is deletable, but for this schema I used the:

  __experimental_actions: [/*'create',*/ 'update', /*'delete',*/ 'publish']
Can I export/import just one schema, or do I have to export the whole original dataset? I've already done that when creating a Staging dataset. It's more that I want to move all the content from startPage and create a newPages instead (with that content) and then be able to delete the old startPage schema. So that all my pages (now with diffrent names) is converted in to newPages, so that I can have only one schema for all pages. The two schemas are identical

Jun 21, 2021, 6:58 AM

Thank you!!

Jun 22, 2021, 9:03 AM

Let us know if you run into any more issues!

Jun 22, 2021, 5:45 PM

Hey! Can I change _type? So, lets say I have a _type called removablePage and I want to make it into a _type called staticPage. Is that duable and should I use mutation?

Jun 28, 2021, 8:18 AM

Yep! It’s doable and the Mutations API would be the way to go.

Jun 28, 2021, 5:17 PM

Sanity.io: Get the most out of your content

Sanity.io is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Free to get started, and pay-as-you-go on all plans. Find out more.