Seeding in Production at Heroku

Locally, my seeding works fine running this script from my package.json file

“seed1”: “adonis seed --force --files UserSeeder.js”

However, I get the following error when trying to run this script below for production.
“heroku-postbuild”: “npm run production && npm run seed1”

Error: ENOENT: no such file or directory, open '/tmp/build_e21559bb4d5a80d45f8cf95569fd3e11/.env'

I have also tried to change the script to

“node ace seed --force --files UserSeeder.js”

but I get the same error

1 Like

I ended up creating a migration and putting the logic inside the up() method. Worked fine.

I’m not sure if this is ok or not though.

1 Like

If you look at the error message it’s telling you it cannot find the .env file.

I doubt you’d want it to work in a postbuild script anyway, as that would rerun the seeder every deploy… seeding really only ought to happen once, right at the start of a project, for initial data.

Presumably you could also, manually, post-deploy simply do something like:
heroku run node ace seed --force

Haven’t used heroku in ages… but this seems accurate :slight_smile:

2 Likes

I’m having the same problem trying to run ace commands on Heroku but the error message is:
Error: ENOENT: no such file or directory, open '/app/.env'
…which seems weird since this file does not exist for local dev either.

Any pointers?

Set your env variables when you run the script
ENV_SILENT=true FOO=bar node ace seed
ENV_SILENT disables .env file loading and then you can pass in all other env variables required for given command

1 Like