From f7037a6780f495d830dc12a4d15ea4b5947ea3ca Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 6 Aug 2026 18:59:38 +1200 Subject: [PATCH] c --- backend/internal/db/sqlite_migrate.go | 1 + backend/internal/handlers/cars.go | 10 +++++----- backend/internal/models/models.go | 2 ++ backend/migrations/postgres/0004_car_name.down.sql | 1 + backend/migrations/postgres/0004_car_name.up.sql | 1 + backend/migrations/sqlite/schema.sql | 1 + 6 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 backend/migrations/postgres/0004_car_name.down.sql create mode 100644 backend/migrations/postgres/0004_car_name.up.sql diff --git a/backend/internal/db/sqlite_migrate.go b/backend/internal/db/sqlite_migrate.go index 416908a..53ba4d4 100644 --- a/backend/internal/db/sqlite_migrate.go +++ b/backend/internal/db/sqlite_migrate.go @@ -21,6 +21,7 @@ var sqliteColumnAdditions = []struct { {"cars", "share_token", "TEXT"}, {"cars", "service_interval_km", "INTEGER"}, {"cars", "service_interval_months", "INTEGER"}, + {"cars", "name", "TEXT"}, {"service_entries", "is_service", "BOOLEAN NOT NULL DEFAULT 0"}, } diff --git a/backend/internal/handlers/cars.go b/backend/internal/handlers/cars.go index 7d46fdc..5b2f9bc 100644 --- a/backend/internal/handlers/cars.go +++ b/backend/internal/handlers/cars.go @@ -60,10 +60,10 @@ func (h *Handlers) CreateCar(w http.ResponseWriter, r *http.Request) { var car models.Car err = h.dbGet(r.Context(), &car, ` - INSERT INTO cars (id, user_id, rego, make, model, year, color, odometer, rego_expiry, wof_expiry, service_interval_km, service_interval_months) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + INSERT INTO cars (id, user_id, rego, name, make, model, year, color, odometer, rego_expiry, wof_expiry, service_interval_km, service_interval_months) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING * - `, uuid.New().String(), userID, in.Rego, in.Make, in.Model, in.Year, in.Color, in.Odometer, regoExpiry, wofExpiry, in.ServiceIntervalKM, in.ServiceIntervalMonths) + `, uuid.New().String(), userID, in.Rego, in.Name, in.Make, in.Model, in.Year, in.Color, in.Odometer, regoExpiry, wofExpiry, in.ServiceIntervalKM, in.ServiceIntervalMonths) if err != nil { if isUniqueConstraintErr(err) { writeError(w, http.StatusConflict, "could not create car (rego may already exist in your garage)") @@ -117,12 +117,12 @@ func (h *Handlers) UpdateCar(w http.ResponseWriter, r *http.Request) { var updated models.Car err = h.dbGet(r.Context(), &updated, ` UPDATE cars - SET rego = ?, make = ?, model = ?, year = ?, color = ?, + SET rego = ?, name = ?, make = ?, model = ?, year = ?, color = ?, odometer = ?, rego_expiry = ?, wof_expiry = ?, service_interval_km = ?, service_interval_months = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ? RETURNING * - `, in.Rego, in.Make, in.Model, in.Year, in.Color, in.Odometer, regoExpiry, wofExpiry, + `, in.Rego, in.Name, in.Make, in.Model, in.Year, in.Color, in.Odometer, regoExpiry, wofExpiry, in.ServiceIntervalKM, in.ServiceIntervalMonths, car.ID) if err != nil { if isUniqueConstraintErr(err) { diff --git a/backend/internal/models/models.go b/backend/internal/models/models.go index 5d19815..97e4b75 100644 --- a/backend/internal/models/models.go +++ b/backend/internal/models/models.go @@ -17,6 +17,7 @@ type Car struct { ID string `db:"id" json:"id"` UserID string `db:"user_id" json:"userId"` Rego string `db:"rego" json:"rego"` + Name *string `db:"name" json:"name"` Make *string `db:"make" json:"make"` Model *string `db:"model" json:"model"` Year *int `db:"year" json:"year"` @@ -38,6 +39,7 @@ type Car struct { // really "car info" the way these fields are. type CarInput struct { Rego string `json:"rego"` + Name *string `json:"name"` Make *string `json:"make"` Model *string `json:"model"` Year *int `json:"year"` diff --git a/backend/migrations/postgres/0004_car_name.down.sql b/backend/migrations/postgres/0004_car_name.down.sql new file mode 100644 index 0000000..347c525 --- /dev/null +++ b/backend/migrations/postgres/0004_car_name.down.sql @@ -0,0 +1 @@ +ALTER TABLE cars DROP COLUMN name; diff --git a/backend/migrations/postgres/0004_car_name.up.sql b/backend/migrations/postgres/0004_car_name.up.sql new file mode 100644 index 0000000..bb526d9 --- /dev/null +++ b/backend/migrations/postgres/0004_car_name.up.sql @@ -0,0 +1 @@ +ALTER TABLE cars ADD COLUMN name TEXT; diff --git a/backend/migrations/sqlite/schema.sql b/backend/migrations/sqlite/schema.sql index ebcd977..699d68c 100644 --- a/backend/migrations/sqlite/schema.sql +++ b/backend/migrations/sqlite/schema.sql @@ -28,6 +28,7 @@ CREATE TABLE IF NOT EXISTS cars ( id TEXT PRIMARY KEY, user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE, rego TEXT NOT NULL, + name TEXT, make TEXT, model TEXT, year INTEGER,