How to seed production database

I’ve followed the tutorial and browsed the example-blog in the RedwoodJS repo. I’ve seeded my app locally with yarn rw db seed, but I’m wondering how I could run a similar command in production.

Thanks!

I can think of two ways to do this today (we’ll probably come up with a more Redwood-way eventually):

  1. Change over your provider and database URL in your local dev environment to your production database. Then when you run the seed it’ll run there instead.
  2. Append the seed command to the build script. If you look in netlify.toml you’ll see the commands that run to build the site. You could add a && yarn rw db seed in there, to make the line: yarn rw db up --no-db-client && yarn rw db seed && yarn rw build

If you go this path just make sure that your seeds are idempotent, meaning you can run them on every deploy and not have anything bad happen (like create a new Admin user every time), or make sure you take that line out of netlify.toml after you deploy the first time!

3 Likes

Update
As of RedwoodJS version >=0.25.0 the seed command has been replaced with yarn rw prisma db seed.

Patch notes: Release v0.25.0 · redwoodjs/redwood · GitHub
Prisma cli in Redwood: Docs - CLI Commands : RedwoodJS Docs

1 Like