This commit is contained in:
Michael committed 2026-08-06 18:59:38 +12:00
1 parent b6014c6ffc
commit f7037a6780
6 files changed
+11 -5

No files matched your search

+1
View File
@@ -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"},
}
+5 -5
View File
@@ -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) {
+2
View File
@@ -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"`
@@ -0,0 +1 @@
ALTER TABLE cars DROP COLUMN name;
@@ -0,0 +1 @@
ALTER TABLE cars ADD COLUMN name TEXT;
+1
View File
@@ -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,