Skip to content

Instantly share code, notes, and snippets.

@christopherafbjur
christopherafbjur / migrateIconName.md
Last active May 30, 2023 19:32
Migration script example for sanity-plugin-icon-picker

Here's an example of a migration script using the utility function migrateIconName to migrate the icon name using the default options.outputFormat to using options.outputFormat: 'react'. If you want to migrate from default to react, pass react as the third argument. If you want to do it the other way around, simply skip passing a third argument.

IMPORTANT! Be sure to create a backup of your dataset before running migrations, so you can roll back in case something goes wrong. Before you run any migrations, you should know what you are doing. You can read more on migrations here.

In this example I'm migrating an object field icon that is a field of document type icons. The structure most likely looks different in your project, so tweak the script and use with caution.

import { createClient } from '@sanity/client'
import { migrateIconName } from 'sanity-plugin-icon-picker'
  1. Install airbnb-base npx install-peerdeps --dev eslint-config-airbnb-base

  2. Install required dependencies npm i -D typescript eslint prettier prettier-eslint-cli eslint-config-prettier eslint-plugin-prettier eslint-config-node eslint-plugin-node @typescript-eslint/eslint-plugin @typescript-eslint/parser

  3. Add .eslintrc.json with the following code:

{
  "root": true,