Fly.ioTutorial
Migrating Heroku Database Apps To Fly
Summary
Migrating a Heroku application to Fly requires attention to database connectivity because Heroku Postgres must be accessed over SSL from outside Heroku. The post uses the DATABASE_URL environment variable, parses it with pg-connection-string, and passes a configured connector to Massive.js, setting sslmode to require and rejectUnauthorized to false to accommodate self-signed certificates in Heroku Postgres’s certificate chain. It also shows a local-development fallback that uses a non-SSL localhost Postgres connection when DATABASE_URL is undefined. With these changes, Turboku can migrate the app and convert DATABASE_URL into a Fly secret, while the application retains its database connection and can use Fly’s region and scaling controls. Database latency still depends on proximity to Heroku’s US or European database regions, so caching within Fly regions may matter for mission-critical performance.
Context
The migration must handle changes in how Heroku and the Postgres driver manage connections. Heroku Postgres requires SSL when accessed from outside Heroku, and its certificate chain can include a self-signed certificate.
Approach / What changed
Read DATABASE_URL from the environment, parse it with pg-connection-string, and configure the connector with sslmode set to require and rejectUnauthorized set to false before passing it to Massive.js. When DATABASE_URL is undefined, use a non-SSL localhost Postgres fallback for local testing. Turboku then migrates the app and stores DATABASE_URL as a Fly secret.
Takeaways
Heroku Postgres connections from outside Heroku need SSL configuration rather than an unmodified connection string.
Setting rejectUnauthorized to false avoids certificate verification errors caused by a self-signed certificate in Heroku Postgres’s server certificate chain.
A Fly deployment keeps the Heroku database connection, but latency is tied to the database’s US or European region; regional caching may help mission-critical workloads.
Source and freshness
- Source
- fly.io
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.