Starting the database
Start the Docker services
From the repository root, start the PostgreSQL container in the background:This starts a
postgres:16-alpine container that:- Listens on
localhost:5432 - Creates a database named
fleet_management - Uses credentials
postgres/postgres
postgres_data so it survives container restarts.Configure the connection URL
Make sure The URL format is:
DATABASE_URL in packages/backend/.env matches your running instance:Sync the schema
Push the Prisma schema to the database. This is safe to run on a fresh database:
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).Run migrations
To apply pending migration files in order, use:This calls
prisma migrate deploy, which is safe to run in CI and production.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:Schema overview
The following tables are defined inpackages/backend/prisma/schema.prisma.
| Table | Description |
|---|---|
Users | Platform users. Role is either admin (fleet manager) or technician (field worker). Stores profile details, driver licence info, and hashed passwords. |
Fleets | Named groups of vehicles, each owned by an admin user. |
Vehicles | Individual vehicles belonging to a fleet. Tracks licence plate, odometer unit, insurance expiry, and maintenance interval. |
Assignments | Links a technician to a vehicle for a period of time. Status is active or returned. |
Inspections | Vehicle inspection records submitted by technicians. Stores mileage, damage notes, four photo URLs, and a generated PDF report URL. |
MaintenanceTypes | Lookup table of named maintenance tasks (e.g. oil change, tyre rotation). |
VehicleMaintenance | Maintenance events linked to a vehicle and a maintenance type. Records last-performed date/mileage, next-due date/mileage, and completion notes. |
Enums
| Enum | Values | Used on |
|---|---|---|
Role | admin, technician | Users.role |
AssignmentStatus | active, returned | Assignments.status |
LicenseStatus | active, expired | Vehicles.licenseStatus |
OdometerUnit | km, mi | Vehicles.odometerUnit |