sanity
Version:
Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches
29 lines (26 loc) • 592 B
text/typescript
export const renameField = ({
migrationName,
documentTypes,
}: {
migrationName: string
documentTypes: string[]
}) => `import {defineMigration, at, setIfMissing, unset} from 'sanity/migrate'
const from = 'oldFieldName'
const to = 'newFieldName'
export default defineMigration({
title: '${migrationName}',
${
documentTypes.length > 0
? ` documentTypes: [${documentTypes.map((t) => JSON.stringify(t)).join(', ')}],\n`
: ''
}
migrate: {
document(doc, context) {
return [
at(to, setIfMissing(doc[from])),
at(from, unset())
]
}
}
})
`