Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(migrate): add dryRun to context #6816

Merged
merged 1 commit into from
May 31, 2024

Conversation

nkgentile
Copy link
Contributor

@nkgentile nkgentile commented May 30, 2024

Description

When running a migration, there may be side-effects like calling a third-party API, or using client to make Sanity requests. A developer may wish to log those effects rather than actually executing them in a dry run.

import { defineMigration } from "sanity/migrate";

/**
 * Run this migration with
 * `npx sanity migration run my-migration`
 */
export default defineMigration({
  title: "my-migration",

  // pass whether the migration is a dry-run as context
  async *migrate(documents, { dryRun }) {
    for await (const document of documents()) {
      if(dryRun) {
        // Only log the effect
        console.log(`Something happened`)
      } else {
        // Execute the side-effect
        await thirdPartyRequest();
      }
      // ... do something with the document, maybe yield patches
    }
  },
});

What to review

Testing

I manually tested that the flag comes through the context in both async generator and object definition formats

Notes for release

Adds a dryRun flag to the context argument in migration scripts

@nkgentile nkgentile requested a review from a team as a code owner May 30, 2024 16:15
@nkgentile nkgentile requested review from cngonzalez and removed request for a team May 30, 2024 16:15
Copy link

vercel bot commented May 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
page-building-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 31, 2024 8:45am
performance-studio ✅ Ready (Inspect) Visit Preview May 31, 2024 8:45am
test-compiled-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 31, 2024 8:45am
test-next-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 31, 2024 8:45am
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 31, 2024 8:45am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview May 31, 2024 8:45am

Copy link

vercel bot commented May 30, 2024

@nkgentile is attempting to deploy a commit to the Sanity Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Member

@bjoerge bjoerge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very useful – thanks @nkgentile!

@bjoerge bjoerge added this pull request to the merge queue May 31, 2024
Merged via the queue into sanity-io:next with commit 104162a May 31, 2024
24 of 32 checks passed
@nkgentile nkgentile deleted the feature/add-dry-run-flag branch May 31, 2024 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants