Skip to content

JeremyDwayne/rideshare_rails

Repository files navigation

CircleCI

📚 High Performance PostgreSQL for Rails

Rideshare is the Rails application for the book "High Performance PostgreSQL for Rails", published by Pragmatic Programmers in 2024.

Installation

Prepare your development machine.

Homebrew Packages

First, install Homebrew.

Graphviz

brew install graphviz

Ruby Version Manager

Before installing Ruby, install a Ruby version manager. The recommended one is Rbenv. Run:

brew install rbenv

PostgreSQL

If you've installed version 16 of PostgreSQL via Homebrew, that's ok, although the recommended method is below.

  • Install Postgres.app
  • From the Menu Bar app, click "+" to create a PostgreSQL 16 server

PostgreSQL configuration is based on My GOTO Postgres Configuration for Web Services

Ruby Version

Run cat .ruby-version to find the version of Ruby that's needed

For example, for 3.2.2 run:

rbenv install 3.2.2

Run rbenv versions to confirm the correct version is being used. The current will have an asterisk.

  system
* 3.2.2 (set by /Users/andy/Projects/rideshare/.ruby-version)

Running into trouble? Review Learn how to load rbenv in your shell using rbenv init.

Bundler and Gems

Bundler is included when you install Ruby using Rbenv. You're ready to install gems. Run:

bundle install

Rideshare development database

Normally in Rails, you'd run bin/rails db:create to create your database. Rideshare uses a custom script.

To create the database and initial objects, you'll run the db/setup.sh script.

Before running it, ensure the following environment variables are set:

  • RIDESHARE_DB_PASSWORD
  • DB_URL

Review the db/setup.sh script header section for details on the expected values for those environment variables.

Once both are set, run the script using the command below. This method captures output to the output.log file.

sh db/setup.sh 2>&1 | tee -a output.log

Since you set RIDESHARE_DB_PASSWORD earlier, create or update the ~/.pgpass file with the password value.

Refer to postgresql/.pgpass.sample for a sample entry.

When you've updated it, ~/.pgpass should have an entry like the one below. Replace the last segment, for example 2C6uw3LprgUMwSLQ is shown below, with the password value that you generated.

localhost:5432:rideshare_development:owner:2C6uw3LprgUMwSLQ

Run chmod 0600 ~/.pgpass.

Finally, run export DATABASE_URL=<value from .env>, setting the value from the .env file for the DATABASE_URL environment variable.

Once that's set, verify you're able to connect by running: psql $DATABASE_URL. Once connected, run this:

SELECT current_user;

Confirm you're connected as the owner user. Then run the describe namespace meta-command:

\dn

Verify the rideshare schema is displayed. Run the describe table meta command next: \dt. You should see the Rideshare tables.

Run Migrations

Migrations in Rideshare are preceded by SET role = owner, so that they run as the owner user, which owns the objects.

See lib/tasks/migration_hooks.rake for more details.

Run migrations the standard way:

bin/rails db:migrate

If migrations ran successfully, you're good to go!

Development Guides and Documentation

Troubleshooting

The Rideshare repository has many README.md files within subdirectories. Run find . -name 'README.md' to see them all.

UI

Although Rideshare is an API-only app, there are some UI elements.

Rideshare runs PgHero which has a UI.

Connect to it:

bin/rails server

Once that's running, visit http://localhost:3000/pghero in your browser to see it.

Screenshot of PgHero for Rideshare

About

test app for learning scaling with postgres & rails

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published