29 lines
1.2 KiB
SQL
29 lines
1.2 KiB
SQL
-- Nullable, unique when set: NULL means sharing is off for that car. A
|
|
-- random opaque token (not the car's own id) so a share link can't be
|
|
-- guessed and doesn't leak the car's real UUID.
|
|
ALTER TABLE cars ADD COLUMN share_token TEXT UNIQUE;
|
|
|
|
-- Either/both may be set; whichever comes first triggers the synthesized
|
|
-- "service due" reminder (computed from the most recent is_service entry).
|
|
ALTER TABLE cars ADD COLUMN service_interval_km INT;
|
|
ALTER TABLE cars ADD COLUMN service_interval_months INT;
|
|
|
|
-- Marks a service_entries row as "this was a full service" — i.e. the
|
|
-- baseline the next service-due reminder counts forward from. Most entries
|
|
-- (oil top-up, tyre rotation, etc.) won't set this.
|
|
ALTER TABLE service_entries ADD COLUMN is_service BOOLEAN NOT NULL DEFAULT false;
|
|
|
|
CREATE TABLE fuel_entries (
|
|
id UUID PRIMARY KEY,
|
|
car_id UUID NOT NULL REFERENCES cars(id) ON DELETE CASCADE,
|
|
entry_date DATE NOT NULL,
|
|
litres DOUBLE PRECISION NOT NULL,
|
|
cost DOUBLE PRECISION NOT NULL,
|
|
odometer INT,
|
|
location TEXT,
|
|
notes TEXT,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
);
|
|
CREATE INDEX idx_fuel_entries_car_id ON fuel_entries(car_id);
|
|
CREATE INDEX idx_fuel_entries_date ON fuel_entries(entry_date);
|