Tips on migrating a Ruby on Rails app from Heroku to

The fact that this is my first post after two years says a lot about the intricacies of this process and how much accomplishment I feel figuring it out. Fly has a migration guide which is great, but I ran into some issues I felt the need to document for future self and possibly others.

Don't use Turboku

Fly provides a migration assistant that claims to easily move your app. It's cool and it works but leaves you without a key component in the ecosystem - their CLI connection. You need the CLI for many crucial tasks and as far as I know, there's no way to connect to an existing app after you deploy via Turboku.

Turboku also leaves your Postgres and Redis on Heroku, so you have to create those services and move your data manually either way. Even their migration guide doesn't use Turboku.

Accessing secrets

Fly encrypts the secrets and doesn't expose a command to show them. The docs mention only setting, removing, and listing secrets (which shows only the digests).

For security reasons, we do not allow read access to the plain-text values of secrets.

But there's a way. They even mention it in the docs for Sidekiq.

fly ssh console -C "printenv | grep REDIS_URL" -a appname

Connecting to the Postgres database

If you examine the Postgres connection URL closely, you'll see the host part has a .internal suffix. You can't use that to connect to the db from outside Fly. Luckily, they provide a way to proxy the connection.

fly proxy 15432:5432 -a appname

Now, you can connect to your Fly database from your machine using localhost as host and 15432 as port. Neat!

Migrating data

We can use the knowledge from the previous section to easily migrate the data from Heroku Postgres to Postgres. Create and download a manual backup (or use pg_dump) from your Heroku database. Then,

PGPASSWORD="password" pg_restore --verbose --clean --no-acl --no-owner -h localhost -U postgres -d [dbname] --port=15432 [path_to_dump]

That's it for now. I consider this post living public notes. Please reach out if you stumbled upon anything not covered here or have any suggestions.

Heroku really spoiled us, but it's time to move out of the parent's house.