lakki
November 29, 2022, 6:43pm
1
Hi,
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,
# fly.rake
namespace :db do
task seed: :environment do
sh 'bin/rails db:recreate:seed'
end
end
And added the following to Dockerfile
generated by fly
,
#Dockerfile
ARG DB_SEED_COMMAND="bin/rails fly:db:seed RAILS_ENV=production"
RUN ${DB_SEED_COMMAND}
Question: After deployment is done, I don’t see the changes in Postgres. Where i am doing wrong,
Here is my database.yml
file
# config/database.yml
production:
<<: *default
database: db/production.sqlite3
I’m not sure how fly
will pick up postgres
without modifying the configuration in database.yml
.
rubys
November 29, 2022, 7:20pm
2
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"
1 Like
lakki
November 30, 2022, 4:05am
3
Thank you @rubys , Can I use this command in GitHub actions? Is that a good idea?
rubys
November 30, 2022, 3:01pm
4
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.
lakki
December 12, 2022, 5:20am
5
It worked, Thank you @rubys
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"
system
Closed
May 4, 2024, 12:28am
8
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.