Database does not exist error on deploy, despite database already attached and live.

I am trying to deploy a new version on my rails app (with postgres database). At the release stage of the deploy, I get the following error:

ActiveRecord::NoDatabaseError: FATAL: database "my-app-db" does not exist
/app/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.3.1/lib/active_record/connection_adapters/postgresql_adapter.rb:81:in `rescue in new_client'

This, despite my app having a set DATABASE_URL secret, the my-app-db existing and seemingly attached to the app as I can log on and use the currently deployed version of my app.

I can also connect to the database and view the current production data:

flyctl postgres connect -a my-app-db 

The release command is standard in fly.rake:

  # RELEASE step:
  #  - changes to the filesystem made here are DISCARDED
  #  - full access to secrets, databases
  #  - failures here prevent deployment
  task :release => 'db:migrate'

I’m at a loss as to what could be missing here.

I’ll agree this makes no sense.

Suggestion on how to make progress, comment out the db:migrate for now:

task :release # => 'db:migrate'

If you don’t have pending migrations, you should deploy just fine. And if you don’t deploy just fine, the problem isn’t with the release step, but something to do with your secret or application.

If you do have pending migrations, you will deploy but requests will fail. You can run the migrations using:

flyctl ssh console -C '/app/bin/rails db:migrate'

To be clear, I am not suggesting this as a fix, but as a way to determine what is going on as clearly something is not as it seems.