-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(migration): improve progress as migration is running (#5550)
- Loading branch information
Showing
7 changed files
with
146 additions
and
38 deletions.
There are no files selected for viewing
16 changes: 14 additions & 2 deletions
16
dev/test-studio/migrations/rename-location-to-address/index.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,24 @@ | ||
import {defineMigration} from '@sanity/migrate' | ||
import {at, patch, set} from '@sanity/migrate/mutations' | ||
import {at, patch, set, unset} from '@sanity/migrate/mutations' | ||
|
||
const addresses = [ | ||
{city: 'Oslo', country: 'Norway'}, | ||
{city: 'Stockholm', country: 'Sweden'}, | ||
{city: 'Copenhagen', country: 'Denmark'}, | ||
{city: 'Helsinki', country: 'Finland'}, | ||
{city: 'Reykjavik', country: 'Iceland'}, | ||
{city: 'Torshavn', country: 'Faroe Islands'}, | ||
] | ||
|
||
export default defineMigration({ | ||
name: 'Rename Location to Address', | ||
documentType: 'author', | ||
migrate: { | ||
document(doc) { | ||
return patch(doc._id, [at('address', set('Somehwere'))]) | ||
return patch(doc._id, [ | ||
at('address', set(addresses[Math.floor(Math.random() * addresses.length)])), | ||
at('location', unset()), | ||
]) | ||
}, | ||
}, | ||
}) |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export async function mapAsync<T, U>( | ||
it: AsyncIterableIterator<T>, | ||
project: (value: T) => Promise<U>, | ||
concurrency: number, | ||
): Promise<AsyncIterable<U>> { | ||
// todo: convert to top level import when we can | ||
const {pMapIterable} = await import('p-map') | ||
|
||
return pMapIterable(it, (v) => project(v), { | ||
concurrency: concurrency, | ||
}) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export async function* tap<T>(it: AsyncIterableIterator<T>, interceptor: (value: T) => void) { | ||
for await (const chunk of it) { | ||
interceptor(chunk) | ||
yield chunk | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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