How to deploy Rails to Fly.io with Supabase DB
Table of contents
No headings in the article.
flyctlcommand line utility as shown here
Sign in to Fly.io by running
fly auth login
flyctl launchfrom the rails app directory as shown here
- Remember to answer No when flyctl launch wizard asks if you want to spin up a Postgres DB as part of the launch process since we plan on using Supabase for that.
Your app should be would be up, you can verify that in the Fly.io dashboard.
Go to Supabase and spin up a database if you've not already done that. Once that DB is up, go to the Database Section of Project Settings, and get the connection String we'll need that later. It'll look something like this:
Once you have this we've to make two changes to our current setup.
database.ymland make sure the database URL for the production environment points to
ENV['DATABASE_URL']as shown below. We need to do this to make Fly.io take the Supabase DB URL
default: &default adapter: postgresql encoding: unicode production: <<: *default url: <%= ENV["DATABASE_URL"] %>
flyctl secrets set DATABASE_URL=postgres://postgres:YOUR-PASSWORD@db.soemthing.supabase.co:66543/mydbname
The reason we're setting DATABASE_URL is that Rails Apps automatically connect to the Database specified in DATABASE_URL as mentioned here