Skip to main content
The Fleet Management System uses PostgreSQL 16 as its database, managed via Prisma. A Docker Compose file is included to run PostgreSQL (and Mailpit for email) locally with a single command.

Starting the database

1

Start the Docker services

From the repository root, start the PostgreSQL container in the background:
docker compose up -d db
This starts a postgres:16-alpine container that:
  • Listens on localhost:5432
  • Creates a database named fleet_management
  • Uses credentials postgres / postgres
Data is persisted in the named volume postgres_data so it survives container restarts.
2

Configure the connection URL

Make sure DATABASE_URL in packages/backend/.env matches your running instance:
DATABASE_URL=postgresql://postgres:postgres@127.0.0.1:5432/fleet_management?schema=public
The URL format is:
postgresql://<DB_USER>:<DB_PASSWORD>@<DB_HOST>:<DB_PORT>/<DB_NAME>?schema=public
3

Sync the schema

Push the Prisma schema to the database. This is safe to run on a fresh database:
yarn workspace backend db:sync
db:sync calls prisma db push, which applies the current schema without creating migration files. It is intended for initial setup and development. Use migrations for incremental changes (see below).
4

Run migrations

To apply pending migration files in order, use:
yarn workspace backend db:migrate
This calls prisma migrate deploy, which is safe to run in CI and production.
5

Seed the database

Set DB_SEED=true in packages/backend/.env and start (or restart) the backend server. The seed script runs automatically on startup and populates the database with initial users, fleets, and maintenance types.Alternatively, you can trigger a one-off seed run without restarting the server by setting the variable inline:
DB_SEED=true yarn workspace backend start
The seed script creates user accounts using DEFAULT_LOGIN_PASSWORD. Change this value in .env before seeding in any environment that is accessible over a network.

Schema overview

The following tables are defined in packages/backend/prisma/schema.prisma.
TableDescription
UsersPlatform users. Role is either admin (fleet manager) or technician (field worker). Stores profile details, driver licence info, and hashed passwords.
FleetsNamed groups of vehicles, each owned by an admin user.
VehiclesIndividual vehicles belonging to a fleet. Tracks licence plate, odometer unit, insurance expiry, and maintenance interval.
AssignmentsLinks a technician to a vehicle for a period of time. Status is active or returned.
InspectionsVehicle inspection records submitted by technicians. Stores mileage, damage notes, four photo URLs, and a generated PDF report URL.
MaintenanceTypesLookup table of named maintenance tasks (e.g. oil change, tyre rotation).
VehicleMaintenanceMaintenance events linked to a vehicle and a maintenance type. Records last-performed date/mileage, next-due date/mileage, and completion notes.

Enums

EnumValuesUsed on
Roleadmin, technicianUsers.role
AssignmentStatusactive, returnedAssignments.status
LicenseStatusactive, expiredVehicles.licenseStatus
OdometerUnitkm, miVehicles.odometerUnit

Stopping and resetting

To stop the database container without deleting data:
docker compose stop db
To remove the container and all data (full reset):
docker compose down -v

Build docs developers (and LLMs) love