How to use an mutation in a preview deployment setup
Thanks - ok - so i would write something like api.mutations.myFunctionName? And how would that fit into a deploy integration where I am importing data to preview first? I.e. where would it go in the deploy command:
npx convex deploy --cmd 'npm run build' && if [ "$VERCEL_ENV" == "preview" ]; then npx convex import --preview-name "$VERCEL_GIT_COMMIT_REF" ./data/mock-data/rtp_preview_snapshot.zip; fi
12 Replies
Close, but
That looks good, is that not working?
I will test it out - but where would i include it in the deploy command so it runs after the import?
Your script:
You want to run this command after the import?
yes
just write it out or do i have to prefix it with --preview-run
Are you familiar with shell? this is an if statment. Commands are separated by semicolons if you want the next one to run regardless.
Hm what is your goal?
yes just wondering if I need to use the --preview-run prefix and if it would work even though in the docs --preview-run is listed as part of the convex deploy command
yea when i added --preview-run and the function name it says --preview-run command not found
Ah check out the help for
convex run
npx convex run --help
there's a --preview-name
flagi tried with and without the --preview-run but it says command not found
Can you help me with exactly what the full command would be?
npx convex deploy --cmd 'npm run build' && if [ "$VERCEL_ENV" == "preview" ]; then npx convex import --preview-name "$VERCEL_GIT_COMMIT_REF" ./data/mock-data/rtp_preview_snapshot.zip; migrations:mutateOrgIdForPreview; fi
This does not work
you want to run the command
npx convex run --preview-name "$VERCEL_GIT_COMMIT_REF" migration:mutateOrgIdForPreview '{"foo": 123}'
that's what should run where you have written migrations:mutateOrgIdForPreview
i tried with and without the --preview-run but it says command not foundCheck out the help for
run
by running npx convex run --help
in a terminal, it tells you which flags are allowedThank you, that seems to work but for some reason the function I wrote is failing with an error I dont understand.
Here's my function it's calling:
Oh, I take it back, it seems to work now
Thank you for your help