Recommended way to run migration workflow
I was wondering if the recommended way to deploy to vercel if we add migrations to our
migrations.ts
file is the following:
npx convex deploy --cmd 'turbo run build && npx convex run migrations
wanna make sure I get the order right. Also I guess the --prod flag is not necessary if we have the right env variables set in vercel, and that way it'll work for other envs like staging as well
And if I have a migrations table I shouldn't be worried about a migration happening twice either I assume3 Replies
I think the above is correct based on https://stack.convex.dev/migrating-data-with-mutations#running-migrations-from-the-cli-or-dashboard
Stateful Migrations using Mutations
Online migrations in Convex using mutations. Including a helper to track migration state!
I can't actually tell where the end quote is supposed to be (after
build
or after migrations
.
Just to be clear about the ordering of things (based on https://docs.convex.dev/production/hosting/vercel#how-it-works):
If the full cmd
is 'turbo run build && npx convex run migrations
that command will run turbo run build
(building your frontend), then run the npx convex run migrations
(running the migrations
function you have against the previously deployed convex code), then push the new code to Convex. If this all succeeds, your hosting provider will then deploy your frontend code.
So migrations don't get run when they're pushed to production with this command, but rather immediately before the next push.
If the full cmd
is just turbo run build
, we'll build your frontend, then deploy your convex functions, and then run the migrations
function. One thing to watch out for is if npx convex run migrations
, your hosting provider will probably treat the whole build as failed and not update your frontend (even though your Convex functions were updated). You could consider catching errors in the npx convex run migrations
command in your build script and allowing the overall build to succeed even if there's some reason kicking off the migration failed.Using Convex with Vercel | Convex Developer Hub
Host your frontend on Vercel and your backend on Convex.
Thanks for adding all this color Sarah!