Templates/Operations & logistics

Ride hailing database schema

Riders request trips, drivers with vehicles accept, then payments and ratings.

6 tables, 6 relationships

Opens as a new diagram you can change. Free.

Tables

riders

  • iduuid not null
  • full_nametext not null
  • phonetext not null
  • created_attimestamptz not null

drivers

  • iduuid not null
  • full_nametext not null
  • phonetext not null
  • onlineboolean not null
  • created_attimestamptz not null

vehicles

  • iduuid not null
  • driver_id> driversuuid not null
  • registrationtext not null
  • seatsinteger not null
  • created_attimestamptz not null

rides

  • iduuid not null
  • rider_id> ridersuuid not null
  • driver_id> driversuuid
  • vehicle_id> vehiclesuuid
  • pickuptext not null
  • dropofftext not null
  • statustext not null
  • farenumeric(8,2)
  • created_attimestamptz not null

ride_payments

  • iduuid not null
  • ride_id> ridesuuid not null
  • amountnumeric(8,2) not null
  • methodtext not null
  • created_attimestamptz not null

ride_ratings

  • iduuid not null
  • ride_id> ridesuuid not null
  • by_riderboolean not null
  • starsinteger not null
  • created_attimestamptz not null

As PostgreSQL

The same diagram exports to MySQL, MariaDB, SQLite, SQL Server and Oracle, and to Prisma, Drizzle, SQLAlchemy and Convex models.

CREATE TABLE "drivers" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "full_name" TEXT NOT NULL,
  "phone" TEXT NOT NULL UNIQUE,
  "online" BOOLEAN DEFAULT false NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "ride_payments" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "ride_id" UUID NOT NULL UNIQUE,
  "amount" NUMERIC(8,2) NOT NULL,
  "method" TEXT NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "ride_ratings" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "ride_id" UUID NOT NULL,
  "by_rider" BOOLEAN NOT NULL,
  "stars" INTEGER NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "riders" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "full_name" TEXT NOT NULL,
  "phone" TEXT NOT NULL UNIQUE,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "rides" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "rider_id" UUID NOT NULL,
  "driver_id" UUID,
  "vehicle_id" UUID,
  "pickup" TEXT NOT NULL,
  "dropoff" TEXT NOT NULL,
  "status" TEXT DEFAULT 'requested' NOT NULL,
  "fare" NUMERIC(8,2),
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "vehicles" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "driver_id" UUID NOT NULL,
  "registration" TEXT NOT NULL UNIQUE,
  "seats" INTEGER NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

ALTER TABLE "vehicles" ADD CONSTRAINT "fk_vehicles_driver_id" FOREIGN KEY ("driver_id") REFERENCES "drivers" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "rides" ADD CONSTRAINT "fk_rides_rider_id" FOREIGN KEY ("rider_id") REFERENCES "riders" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "rides" ADD CONSTRAINT "fk_rides_driver_id" FOREIGN KEY ("driver_id") REFERENCES "drivers" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "rides" ADD CONSTRAINT "fk_rides_vehicle_id" FOREIGN KEY ("vehicle_id") REFERENCES "vehicles" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "ride_payments" ADD CONSTRAINT "fk_ride_payments_ride_id" FOREIGN KEY ("ride_id") REFERENCES "rides" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "ride_ratings" ADD CONSTRAINT "fk_ride_ratings_ride_id" FOREIGN KEY ("ride_id") REFERENCES "rides" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

More Operations & logistics templates

Start with one diagram, free

One diagram with two branches, no card needed. Upgrade when your team needs more.