Files
Holzleitner---Backend--aktu…/migrations/0005_delivery_notes.sql
Dennis Nemec 438040acce Initial: Rust-Backend mit Clean Architecture (domain/application/infrastructure/api)
Vier-Crate-Workspace mit:
- Domain: Account, Car, Tour, Delivery, DeliveryItem, DeliveryNote, Customer,
  Article, Warehouse, ScanState, AuditAction — alle mit serde + feature-gated
  utoipa::ToSchema.
- Application: Ports (TourRepository, DeliveryRepository, ScanRepository,
  DeliveryNoteRepository, CarRepository, AuthService) und Use Cases.
- Infrastructure: Postgres-Adapter via sqlx (PgTourRepository etc.) +
  Keycloak-AuthService mit JWKS-Cache + OIDC-Discovery.
- API: Axum 0.8, utoipa-OpenAPI + Swagger-UI, JWT-Bearer-Middleware,
  AuthenticatedUser-Extractor.

Endpoints:
- GET /me/tours/today, /tours/{id}, /accounts/{pn}, /me/cars, /health
- POST /sync/tour, /scans (bulk + idempotent via clientScanId),
  /deliveries/{id}/{hold,resume,cancel,complete,notes}, /me/cars
- PUT /tours/{id}/delivery-order, /deliveries/{id}/assigned-car, /me/cars/{id}
- PATCH /me/cars/{id}

Datenmodell:
- 6 Migrationen (accounts, tours/deliveries/items + Stammdaten,
  scan_audit mit clientScanId-UNIQUE, state_reason refactor,
  delivery_notes, cars + FKs nachziehen).
- Business-stabile Beleg-Keys (belegart_id, belegnummer) für ERP-Sync.
- Append-only scan_audit + embedded scan_state als doppelte Wahrheit.

Dev-Setup:
- docker-compose mit Postgres 17 + Keycloak 26
- Keycloak-Realm 'holzleitner' mit Public-Client (PKCE), Testfahrer
  (PN 1001) + Audience-/Personalnummer-Mapper
2026-05-14 22:28:31 +02:00

22 lines
841 B
SQL

-- Notizen pro Lieferung. Eine Notiz ist entweder Text, ein Bild-Anhang
-- (Object-Storage-Key/URL) oder beides — aber nicht NULL/NULL.
--
-- Akteur: actor_personalnummer ist Pflicht (aus JWT). Das fachlich
-- gewünschte author_car_id bleibt optional, bis das Backend Fahrzeuge
-- selbst verwaltet.
CREATE TABLE delivery_notes (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
delivery_id UUID NOT NULL REFERENCES deliveries(id) ON DELETE CASCADE,
text TEXT,
image_attachment TEXT,
author_personalnummer BIGINT NOT NULL,
author_car_id UUID,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
CHECK (text IS NOT NULL OR image_attachment IS NOT NULL)
);
CREATE INDEX delivery_notes_delivery
ON delivery_notes (delivery_id, created_at);