#seed functions only for preview
4 messages · Page 1 of 1 (latest)
Hi @merry moat. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
You can’t define a function that “doesn’t exist” in production, but you can:
-
Make the seed function internal-only
Define it as aninternalMutation(or internal action) so it’s never callable from clients, only from CLI / dashboard / other functions:// convex/init.ts import { internalMutation } from "./_generated/server"; const init = internalMutation({ args: {}, handler: async (ctx) => { // seed logic here }, }); export default init;This keeps it out of your public API while still usable with
--preview-runornpx convex run. [Internal funcs; internalMutation] -
Only run it on preview deployments
Configure your CI/build so that--preview-runis only used when deploying previews, not when deploying to prod. For example with Vercel/Netlify:npx convex deploy --cmd 'npm run build' --preview-run initThis
initfunction will run only for preview deployments created via a Preview Deploy Key; it’s ignored for normal production deploys. [Deploy CLI; Vercel previews; Netlify previews] -
Recommended workflow
The Convex team’s suggested pattern is exactly this: put your seed logic inconvex/init.tsas an internal mutation/action, and wire--preview-run initinto your preview deploy command. [Seeding summary; Workflow preference]