All About Dat Base 🚀

A Rails generator that makes connecting your Rails application to Supabase database as easy as running one command!

Features

  • 🎯 Interactive environment selection (Development, Production, or Both)
  • 🔐 Uses Rails encrypted credentials (no dotenv needed)
  • 📝 Automatically configures database.yml
  • 🎨 Beautiful CLI with arrow key navigation
  • 📋 Clear step-by-step instructions
  • 🔄 Preserves multi-database setup for production

Installation

Add this line to your application's Gemfile:

gem 'all-about-dat-base'

And then execute:

bundle install

Usage

Run the generator in your Rails application:

bin/rails new-base:install

The generator will:

  1. Ask you which environments to configure - Use arrow keys to select:

    • Development only
    • Production only
    • Both development and production
  2. Update your database.yml with the appropriate Supabase configuration

  3. Provide clear instructions for setting up your Rails credentials

What it does

Database Configuration

The generator updates your config/database.yml to use Rails credentials:

development:
  <<: *default
  url: <%= Rails.application.credentials.database_url %>

production:
  primary: &primary_production
    <<: *default
    url: <%= Rails.application.credentials.database_url %>
  # ... preserves your multi-database setup

Credentials Setup

After running the generator, you'll get instructions to:

  1. Edit your Rails credentials:

    EDITOR="code --wait" rails credentials:edit
    
  2. Add your Supabase connection string:

    # Database configuration
    database_url: postgresql://postgres.your-ref:[YOUR-PASSWORD]@aws-0-region.pooler.supabase.com:6543/postgres
    

Getting Your Supabase Connection String

  1. Go to Supabase Dashboard
  2. Select your project
  3. Navigate to: Settings → Database
  4. Find "Connection string" section
  5. Select "Transaction pooler" (recommended)
  6. Copy the connection string

Benefits

  • No dotenv gem needed - Uses Rails built-in encrypted credentials
  • Same database everywhere - Perfect for development with production data
  • Regular Rails commands - No prefixes needed: rails g model, rails db:migrate
  • Secure - Credentials are encrypted and safe for version control
  • Multi-database support - Preserves your production cache/queue/cable databases

Testing Your Setup

After configuration, test your connection:

rails db:version
rails console
# Then: ActiveRecord::Base.connection.execute('SELECT version()').first

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/yourusername/all-about-dat-base.

License

The gem is available as open source under the terms of the MIT License.