vulcan-next icon indicating copy to clipboard operation
vulcan-next copied to clipboard

Move seeding outside of /api/graphql

Open eric-burel opened this issue 3 years ago • 1 comments

Describe the bug Seed logic doesn't belong to any endpoint. In a serverless approach, seeding should hapeen in a "predev" or "prestart" script that is run globally at application startup .

To Reproduce

On a fresh, empty database, try running /api/login before /api/graphql => admin user won't be seeded. This is because the seed happens only in /api/graphql.

Expected behavior Seeding should happen before "yarn dev", not inside API routes.

To fix:

  1. move seed code outside of "/api/graphql", into it's own independent script, in a "scripts" folder
  2. setup an environment that stills allows to use TS in this script (eg running the script with node-ts or whatever)
  3. run this script on "predev" in package.json (and maybe "prestart" for prod? we don't seed yet in production)

eric-burel avatar Apr 19 '21 18:04 eric-burel

In progress, thanks to the new ability to build TypeScript files as independant scripts. We already have introduced db:seed and db:reset. We could document them as scripts to run after app creation.

eric-burel avatar Sep 17 '21 16:09 eric-burel