I’m using a cronjob to run a rake task in my rails app, but it’s failing, with this error:
ActiveRecord::DatabaseConnectionError: There is an issue connecting to your database with your username/password, username: rails_authentication
Please check your database configuration to ensure the username/password are valid.
/path/to.rake:17:in `block (2 levels) in <main>'
PG::ConnectionBad: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL: role "rails_authentication" does not exist
/rails-authentication/lib/tasks/newspaper.rake:17:in `block (2 levels) in <main>'
Tasks: TOP => newspaper:new_images
(See full trace by running task with --trace)
I have set up the postgres secrets, and my database.yml production config looks like this:
However I had to start over with a PG database, so do I need to manually update the database.yml file manually? The latest database is not ‘newsguessr_production’, it has a different name generated by Fly.io.
I did some more digging, and I might not have been connected to the right database. When I connect to the database I set up (and set secrets for) with Fly.io, and list the databases and users, I get this:
I don’t know why I have four databases listed there, and which one I should be connecting to - or if I’m trying to connect to it in the correct way. Thanks!
Another clue perhaps - echo $DATABASE_URL returns a blank line. I’ve added env :DATABASE_URL, ENV[‘DATABASE_URL’] to my schedule.rb file and the error is now ‘rake aborted!
Database URL cannot be empty’.
Is it possible that I’ve not set the secrets properly for the database?
After going round in circles on this all day, I think you were right all along
I started from scratch with a new postgres cluster just to make sure that the secrets weren’t somehow out of sync. So now I’m just struggling with how to pass them to Whenever gem / schedule.rb. Thanks so much!