# MVP Platform Vehicles Service

## Schema Bootstrapping (Docker-First)
- Database: PostgreSQL, service `mvp-platform-vehicles-db`.
- On first start, schema files from `mvp-platform-services/vehicles/sql/schema` are executed automatically because the folder is mounted to `/docker-entrypoint-initdb.d` in `docker-compose.yml`.
- Files run in lexicographic order:
  - `001_schema.sql` – creates `vehicles` schema and tables
  - `002_constraints_indexes.sql` – adds uniques and indexes
  - `003_seed_minimal.sql` – seeds minimal dropdown data for sanity checks

## When Do Files Run?
- Only on the initial database initialization (i.e., when the Postgres data volume is empty).
- Subsequent `make start` runs will not reapply these files unless you reset the volume.

## Applying Schema Changes
- Option 1 (fresh reset):
  1. `make clean` to remove volumes
  2. `make start` (the `.sql` files will be reapplied)
- Option 2 (manual apply to existing DB):
  - Exec into the DB container and run the SQL files in order:
    ```bash
    docker compose exec mvp-platform-vehicles-db bash -lc "psql -U mvp_platform_user -d vehicles -f /docker-entrypoint-initdb.d/001_schema.sql"
    docker compose exec mvp-platform-vehicles-db bash -lc "psql -U mvp_platform_user -d vehicles -f /docker-entrypoint-initdb.d/002_constraints_indexes.sql"
    docker compose exec mvp-platform-vehicles-db bash -lc "psql -U mvp_platform_user -d vehicles -f /docker-entrypoint-initdb.d/003_seed_minimal.sql"
    ```

## Quick Start
```bash
make start
make logs-platform-vehicles   # View API + DB logs
```

## Endpoint Summary (Auth Required: Authorization: Bearer <API_KEY>)
- `GET /api/v1/vehicles/years` → `[number]`
- `GET /api/v1/vehicles/makes?year=YYYY` → `{ makes: [{id,name}] }`
- `GET /api/v1/vehicles/models?year=YYYY&make_id=ID` → `{ models: [...] }`
- `GET /api/v1/vehicles/trims?year=YYYY&make_id=ID&model_id=ID` → `{ trims: [...] }`
- `GET /api/v1/vehicles/engines?year=YYYY&make_id=ID&model_id=ID&trim_id=ID` → `{ engines: [...] }`

## Notes
- Transmissions and performance tables exist for future use; no endpoints yet.
- VIN decode endpoints are pending rebuild and not documented here.
