Templates/Operations & logistics
Fleet management database schema
Vehicles and drivers, trips, maintenance records and fuel logs.
5 tables, 5 relationships
Opens as a new diagram you can change. Free.
Tables
vehicles
- iduuid not null
- registrationtext not null
- maketext not null
- modeltext not null
- odometer_kminteger not null
- created_attimestamptz not null
drivers
- iduuid not null
- full_nametext not null
- licence_numbertext not null
- created_attimestamptz not null
trips
- iduuid not null
- vehicle_id> vehiclesuuid not null
- driver_id> driversuuid not null
- started_attimestamptz not null
- ended_attimestamptz
- distance_kmnumeric(8,1)
- created_attimestamptz not null
maintenance_records
- iduuid not null
- vehicle_id> vehiclesuuid not null
- kindtext not null
- costnumeric(10,2) not null
- serviced_ondate not null
- created_attimestamptz not null
fuel_logs
- iduuid not null
- vehicle_id> vehiclesuuid not null
- driver_id> driversuuid
- litresnumeric(6,2) not null
- costnumeric(8,2) not null
- filled_attimestamptz 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,
"licence_number" TEXT NOT NULL UNIQUE,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "fuel_logs" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"vehicle_id" UUID NOT NULL,
"driver_id" UUID,
"litres" NUMERIC(6,2) NOT NULL,
"cost" NUMERIC(8,2) NOT NULL,
"filled_at" TIMESTAMPTZ NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "maintenance_records" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"vehicle_id" UUID NOT NULL,
"kind" TEXT NOT NULL,
"cost" NUMERIC(10,2) NOT NULL,
"serviced_on" DATE NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "trips" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"vehicle_id" UUID NOT NULL,
"driver_id" UUID NOT NULL,
"started_at" TIMESTAMPTZ NOT NULL,
"ended_at" TIMESTAMPTZ,
"distance_km" NUMERIC(8,1),
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "vehicles" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"registration" TEXT NOT NULL UNIQUE,
"make" TEXT NOT NULL,
"model" TEXT NOT NULL,
"odometer_km" INTEGER DEFAULT 0 NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
ALTER TABLE "trips" ADD CONSTRAINT "fk_trips_vehicle_id" FOREIGN KEY ("vehicle_id") REFERENCES "vehicles" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "trips" ADD CONSTRAINT "fk_trips_driver_id" FOREIGN KEY ("driver_id") REFERENCES "drivers" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "maintenance_records" ADD CONSTRAINT "fk_maintenance_records_vehicle_id" FOREIGN KEY ("vehicle_id") REFERENCES "vehicles" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "fuel_logs" ADD CONSTRAINT "fk_fuel_logs_vehicle_id" FOREIGN KEY ("vehicle_id") REFERENCES "vehicles" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "fuel_logs" ADD CONSTRAINT "fk_fuel_logs_driver_id" FOREIGN KEY ("driver_id") REFERENCES "drivers" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;More Operations & logistics templates
- Shipping & trackingShipments of packages between addresses, carriers and tracking events.
- ManufacturingProducts with bills of materials, work orders routed through machine operations.
- Field serviceCustomer sites, jobs dispatched to technicians, visits and parts used.
- IT asset managementHardware and licences assigned to employees, with a maintenance history.
- IoT telemetryDevices with sensors streaming readings, thresholds and alerts.
- Ride hailingRiders request trips, drivers with vehicles accept, then payments and ratings.
- ParkingCar parks with spaces, permits for vehicles and paid parking sessions.
- Construction projectsProjects on sites, contractors, tasks, change orders and inspections.
- Farm managementFields planted with crops, harvests, equipment and livestock.
- Sensor readings (Cassandra)Time series per device and day, newest first, with the latest reading kept in a table of its own.
Start with one diagram, free
One diagram with two branches, no card needed. Upgrade when your team needs more.