Files

78 lines
5.0 KiB
Markdown

# Car Service Database
PostgreSQL database and web dashboard for a car service workshop, managed with Docker Compose.
## Start
```powershell
docker compose up -d
```
Open the web dashboard at [http://localhost:3011](http://localhost:3011).
The dashboard's **Vehicles** view provides a dedicated vehicle register containing make, model, model year, engine, transmission, fuel type, color, VIN, license plate, mileage, owner, and service-record count. The **Service records** form stores these vehicle details and can autofill them, along with the customer, when an existing VIN or license plate is entered. Customer contact information can also be autofilled by customer email or by a unique customer name. Names are not unique, so duplicate names are allowed; when a name matches multiple customers, the form asks for an email instead of choosing one incorrectly. It supports adding, listing, and editing service records with service date, VIN, license plate number, car mileage, customer, technician, complaint, and status. Adding a record creates or updates the linked customer and vehicle, technician, and service order in one transaction.
Service records can also include optional used parts and labor lines. Parts support a part number, quantity, and unit price. Labor supports used time in hours and an hourly price. Line totals and the service-record total are calculated automatically and stored with the service order.
The **Settings** view provides complete JSON data backup and restore. **Download backup** exports all customers, employees, vehicles, appointments, service records, service-order items, invoices, and user accounts. **Choose backup file** imports a backup after confirmation; importing replaces the current database contents in one transaction, so a failed import leaves the existing data unchanged. Keep exported backup files secure because they contain all workshop data.
The dashboard supports user sign-in and permission-based access. Without signing in, all views are read-only. Administrators can manage user accounts, add and modify workshop data, restore backups, and delete data. Technicians and service advisors can add and modify workshop data but cannot delete anything. Viewer accounts are read-only. The **Accounts** view is visible to everyone, but only administrators can manage accounts.
A default `admin` account is created automatically. Its initial password is `change-me-in-production`, unless `ADMIN_PASSWORD` is set in `.env` before the web container starts. Sign in at the top of the dashboard and change the initial password by editing the administrator account. Do not use the default password outside local development.
## Move to another server
The Docker image contains the application code, but PostgreSQL data is stored in the named Docker volume `car_service_data`. The volume is not included when copying `docker-compose.yml`, `Dockerfile`, or the source files. Also, `init.sql` runs only when a new PostgreSQL volume is initialized; editing it does not overwrite an existing database.
To move both the application changes and the current data:
1. On the old server, sign in as an administrator, open **Settings**, and select **Download backup**. Copy the downloaded JSON file to the new server.
2. Copy the complete project folder, including `docker-compose.yml`, `Dockerfile`, `server.js`, `init.sql`, `package.json`, `package-lock.json`, and the `public` folder.
3. On the new server, place the backup JSON where it can be selected in the browser, then run:
```powershell
docker compose up -d --build --force-recreate
```
4. Open [http://localhost:3011](http://localhost:3011), sign in as an administrator, open **Settings**, choose the backup JSON, confirm the restore, and wait for the import confirmation.
For a code-only update on a server that already has the correct database volume, copy the changed project files and run `docker compose up -d --build --force-recreate`. Do not run `docker compose down -v` unless you intentionally want to delete the database volume and all stored data.
Check that the database is ready:
```powershell
docker compose ps
docker compose exec car-service-db pg_isready -U car_service_app -d car_service
```
Connect with `psql` inside the container:
```powershell
docker compose exec car-service-db psql -U car_service_app -d car_service
```
The default connection values are:
- Host: `localhost`
- Port: `5432`
- Database: `car_service`
- User: `car_service_app`
- Password: `change-me-in-production`
To use different values, create a `.env` file next to `docker-compose.yml`:
```dotenv
POSTGRES_DB=car_service
POSTGRES_USER=car_service_app
POSTGRES_PASSWORD=use-a-strong-password
POSTGRES_PORT=5432
```
The schema is loaded from `init.sql` the first time the named volume is created. To recreate the database from scratch, including all data:
```powershell
docker compose down -v
docker compose up -d
```
Do not use the default password in production. Restrict the published port or place the database on a private Docker network when an application is added.