I have been trying to deploy my Ruby on Rails app to fly.io, and while I have got the database credentials sorted out, I seem to be having a problem with my database.
Whenever I try deploying there is an error, which says “ActiveRecord::NoDatabaseError: FATAL: database “e_recepti_production” does not exist”. That makes sense, since you usually have to run rake db:create, to create the databases. In fly.io’s case though, the deploy is fully automatic, and when it tries to start up the app it throws the NoDatabase error. The problem is that if the deploy fails the server doesn’t start, I cannot ssh to it and just run db:create manually, and I also can not connect to the db server to create the database.
Does anyone have any possible fixes for this, or any way I could make it run ‘rake db:create’ before trying to start the rails server?
Assuming you are using Fly Postgres, and the database exists, you will need to set a secret. Type fly secrets list and see if DATABASE_URL is set. If not, you can use flyctl postgres attach · Fly Docs to set it.
If you are using a different Postgres, can you describe your setup?
If you want to use a different postgres, and are using Rails 6 or later, you can change task :release => 'db:migrate' to task :release => 'db:prepare' in lib/tasks/fly.rake.
But without knowing more of what you want, it will be difficult to help you further.