11/* eslint-disable no-console */
22
3+ import { randomKey } from '@sanity/util/content'
34import { getCliClient } from 'sanity/cli'
45
56const client = getCliClient ( { apiVersion : '2023-06-30' } )
@@ -15,8 +16,8 @@ const client = getCliClient({apiVersion: '2023-06-30'})
1516
1617// To:
1718// "greeting": [
18- // { "_key": "en", "value": "hello" },
19- // { "_key": "fr", "value": "bonjour" },
19+ // { "_key": "abcdefghijkl", "language":" en", "value": "hello" },
20+ // { "_key": "zxyvwxrstqpo", "language":" fr", "value": "bonjour" },
2021// ]
2122
2223// This will migrate documents in batches of 100 and continue patching until no more documents are
@@ -44,6 +45,7 @@ const client = getCliClient({apiVersion: '2023-06-30'})
4445
4546const TYPE = `presenter`
4647const FIELD_NAME = `title`
48+ const ARRAY_ITEM_TYPE = `internationalizedArrayStringValue`
4749
4850// 3. Run this script with:
4951// `npx sanity@latest exec ./migrations/transformObjectToArray.ts --with-user-token`
@@ -66,7 +68,9 @@ const buildPatches = (docs: any[]) =>
6668 [ FIELD_NAME ] : Object . keys ( doc [ FIELD_NAME ] )
6769 . filter ( ( key ) => key !== '_type' )
6870 . map ( ( key ) => ( {
69- _key : key ,
71+ _key : randomKey ( ) ,
72+ _type : ARRAY_ITEM_TYPE ,
73+ language : key ,
7074 value : doc [ FIELD_NAME ] [ key ] ,
7175 } ) ) ,
7276 } ,
0 commit comments