Rideshare is the Rails application for the book "High Performance PostgreSQL for Rails", published by Pragmatic Programmers in 2024.
Prepare your development machine.
First, install Homebrew.
brew install graphviz
Before installing Ruby, install a Ruby version manager. The recommended one is Rbenv. Run:
brew install rbenv
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
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 is included when you install Ruby using Rbenv. You're ready to install gems. Run:
bundle install
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.
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!
The Rideshare repository has many README.md
files within subdirectories. Run find . -name 'README.md'
to see them all.
- For expanded installation and troubleshooting, navigate to the Development Guides go into greater depth for preparing your development machine.
- For PostgreSQL things: postgresql/README.md
- For Docker things: docker/README.md
- For DB things: db/README.md
- For database scripts: db/scripts/README.md
- For DB scrubbing: db/scrubbing/README.md
- For test environment details in Rideshare, check out: TESTING.md
- For Guides and Tasks in this repo, check out: Guides
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.