Created
February 9, 2020 17:21
-
-
Save good-idea/1abc5429c0c2a0be760d3a318468c750 to your computer and use it in GitHub Desktop.
Remove all shopifyProducts and shopifyCollections from sanity dataset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
WARNING: THIS DELETES DATA | |
Run this within your Sanity project directory with: | |
yarn sanity exec --with-user-token removeSaneShopifyDocuments.js | |
**/ | |
import client from 'part:@sanity/base/client' | |
const query = | |
'*[_type == "shopifyProduct" || _type == "shopifyCollection"]{ _id }' | |
const fetchDocuments = async () => client.fetch(query) | |
const sleep = (ms) => new Promise((r) => setTimeout(r, ms)) | |
const createTransaction = (patches) => | |
patches.reduce( | |
(tx, patch) => tx.patch(patch.id, patch.patch), | |
client.transaction(), | |
) | |
const commitTransaction = (tx) => tx.commit() | |
const run = async () => { | |
const docs = await fetchDocuments() | |
const patches = docs.map((doc) => ({ | |
id: doc._id, | |
patch: { | |
unset: ['collections', 'products'], | |
}, | |
})) | |
const unsetTx = createTransaction(patches) | |
const r = await unsetTx.commit() | |
const d = await client.delete({ query }) | |
} | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment