November 29, 2022, 6:43pm
I have a rails app, and I have deployed the application using
fly deploy. I want to add some seed data like categories or tags in database tables.
I have added the following
task definition to
fly.rake file to create seed data in Postgres database,
namespace :db do
task seed: :environment do
sh 'bin/rails db:recreate:seed'
And added the following to
Dockerfile generated by
ARG DB_SEED_COMMAND="bin/rails fly:db:seed RAILS_ENV=production"
Question: After deployment is done, I don’t see the changes in Postgres. Where i am doing wrong,
Here is my
I’m not sure how
fly will pick up
postgres without modifying the configuration in
November 29, 2022, 7:20pm
The builder does not have access to the database. While this can be done as a part of every release, you generally only want this to be done once. Try removing those lines from your Dockerfile and after you have deployed (i.e., without seed data), try running:
flyctl ssh console -C "/app/bin/rails db:seed"
November 30, 2022, 4:05am
@rubys , Can I use this command in GitHub actions? Is that a good idea?
November 30, 2022, 3:01pm
Yes, and as long as you trust github (and I don’t see why you shouldn’t). The only caution is that the more places you have your API token available, the greater the chances of it leaking.
December 12, 2022, 5:20am
It worked, Thank you
This works for me, but only for my first 10 or so seeds, out of 100s…
fly ssh console -C "rails/bin/rails db:seed"