Git Product home page Git Product logo

rideshare's Introduction

CircleCI

Rideshare

Rideshare is a Rails API app that implements a portion of a fictional Ridesharing service.

High Performance PostgreSQL for Rails

This repo started as a side project back in 2019 to demonstrate good practices.

In 2022, it took on a new purpose as the Rails application for exercises and examples in High Performance PostgreSQL for Rails.

Rideshare proudly runs on PostgreSQL. ๐Ÿ˜

Local Development

To set up Rideshare for development, please read the Prerequisites and Installation Steps sections below.

These steps involve setting up your development machine with all the runtime dependencies, and then setting up your local PostgreSQL instance.

Prerequisites

Ruby

For Rideshare, you'll need Ruby and PostgreSQL. First, work on Ruby.

  • Ruby 3.2.2 (check .ruby-version)
    • Use a Ruby version manager like rbenv
  • Bundler. After installing Ruby, run gem install bundler.
  • (optional) To generate a DB image Install graphiz brew install graphviz

Front-end technologies were removed because this is an API only app.

PostgreSQL

  • On macOS, Postgres.app is the recommended way to install it
  • Currently on PostgreSQL 16 (2023)
  • run export RIDESHARE_DB_PASSWORD=<secret value here> before running setup scripts (see below)
  • Configures PostgreSQL following My GOTO Postgres Configuration for Web Services
  • Configuration uses a series of SQL scripts in db directory, run from psql via a shell script (see next step)
  • Run sh db/setup.sh
  • expects DATABASE_URL is set
  • Migrations will first run SET role = owner to run Migrations as owner, which will own the tables, check lib/tasks/migration_hooks.rake

Installation Steps (Development)

  1. Install the Prerequisites

  2. cd into your source code directory e.g.: ~/Projects

  3. From there, clone the repo: git clone https://github.com/andyatkinson/rideshare.git

  4. cd rideshare

    Install all the Rideshare gems by running bundle install

  5. If all gems were installed, you're ready to set up the database.

    You should have PostgreSQL installed but no database for the app created yet.

    Normally you'd run bin/rails db:create to create databases, but Rideshare has a custom setup.

    On macOS run, for a brand new installation:

    export RIDESHARE_DB_PASSWORD=$(openssl rand -hex 12)

    For existing credentials (upgrades), set RIDESHARE_DB_PASSWORD using the password defined in ~/.pgpass.

    This sets an environment variable with a value like '2C6uw3LprgUMwSLQ' that will be used when creating roles.

    Create the file ~/.pgpass and refer to the sample file in the postgresql directory of this project, filling in your details.

    Once that's set, run the following script to set up the databases, roles, grants, and more.

    sh db/setup.sh

    DATABASE_URL should be set, which is used locally in config/database.yml. Use the owner role which is a readwrite role, and should have permissions to modify the schema, creating tables in the rideshare PostgreSQL schema.

    export DATABASE_URL="postgres://owner:@localhost:5432/rideshare_development"

    Try connecting with psql $DATABASE_URL and run \dn from psql. You should see the rideshare schema and all the tables created in that schema.

    Run pending migrations. You may need to install graphviz (see above) to update the ERD.

    bin/rails db:migrate

~/.pgpass

Below is sample ~/.pgpass file.

cat ~/.pgpass

localhost:5432:rideshare_development:owner:HSTnDDgFtyW9fyFI
localhost:5432:rideshare_development:app:HSTnDDgFtyW9fyFI

Authenticate without the password (supplied from from ~/.pgpass)

psql $DATABASE_URL

Or:

psql -U owner -d rideshare_development

Installation Steps (Test)

For development, you'll use some good practices in PostgreSQL like a custom app schema and app user, with reduced explicitly granted privileges.

For the test database, you'll keep it simpler. Use the postgres superuser and the public schema. The test configuration is also used for Circle CI.

  1. Run sh db/setup_test_database.sh to set up rideshare_test

  2. Run bin/rails test

Refer to .circleci/config.yml for the Circle CI config.

Development Guides

In addition to this Readme, Development Guides go into greater depth for setting up your machine for Rideshare development.

For Guides specific to this repo, check Guides.

UI

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

Rideshare proudly runs PgHero, which can be reached at http://localhost:3000/pghero

Screenshot of PgHero for Rideshare

rideshare's People

Contributors

andyatkinson avatar dependabot[bot] avatar momer avatar drnic avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.