How to deploy Rails to with Supabase DB

How to deploy Rails to with Supabase DB


2 min read

Table of contents

No heading

No headings in the article.

  • Install flyctl command line utility as shown here

  • Sign in to by running fly auth login

  • Run flyctl launch from 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 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.

    • Go to database.yml and make sure the database URL for the production environment points to ENV['DATABASE_URL'] as shown below. We need to do this to make take the Supabase DB URL

      •   default: &default
            adapter: postgresql
            encoding: unicode
            <<: *default
            url: <%= ENV["DATABASE_URL"] %>
    • Now for the final step, we need to add the Supabase DB Connection string as a app secret. We do that as shown here

      •   flyctl secrets set DATABASE_URL=postgres://
    • The reason we're setting DATABASE_URL is that Rails Apps automatically connect to the Database specified in DATABASE_URL as mentioned here