Trash tracker
Marine trash that divers saw, filed against a place and a day at /trash, and moderated by shop staff before anything is published. Migration 20261129100000_trash_logs.sql. Switched by features.trashTracker in fundive.config.ts (on unless set to false; see configuration.md).
Each filed record is a log, which is why the code, the table (trash_logs) and the functions say "trash log". The feature is planned to move to a central database of its own, shared by every deployment; for now its table lives in each shop's database.
Why it is its own module
Trash started as three columns on almanac_records (20260827200000, banded in 20260905100000). It moved to its own table for two reasons:
- A shop picks its modules. The almanac, coral surveys, dive-site maps and the trash log are each switched on or off in config. A shop that runs cleanup dives but no almanac, or the reverse, needs the two to stand apart: an almanac form with no trash questions, or a trash log with no almanac behind it.
- It is a dataset of its own. A trash record is read and exported beside other marine-debris surveys. In its own table, keyed the same way (site, day, diver), it can be exported, released or handed to a cleanup organization without anybody's water temperature attached, and the almanac without the trash.
The migration copied every almanac record that answered either trash question into trash_logs, with its review state, reviewer and staff note, then dropped the trash columns from almanac_records and rebuilt the three almanac RPCs without them. A reading staff approved in the almanac stays approved.
What a log records
| Column | Type | Notes |
|---|---|---|
id | uuid PK | |
created_at / updated_at | timestamptz | |
diver_id | uuid → auth.users | The submitting diver |
site_id | uuid → dive_sites(id) | ON DELETE RESTRICT, as for the almanac |
obs_date | date | The day observed |
amount | text | none / minimal (1–10 pieces) / noticeable (11–50) / heavy (51–200) / severe (200+). NULL is "did not judge how much" |
kinds | text[] | plastic / fishing_gear / styrofoam / glass / metal / rubber / fabric / paper / other |
piece_count | integer | An exact tally, only where somebody really counted: rows carried over from the almanac's pre-band count, and cleanup dives |
notes | text | One short line (500 characters at most) a band and a checklist cannot say: a ghost net on the north wall at 15 m |
status, approved_by, approved_at, staff_notes | Moderation, exactly as the almanac |
Unique: (site_id, obs_date, diver_id) — one log per diver, site and day.
Three rules carry over from the almanac and are enforced in the table:
- Blank and
noneare different answers.noneis "looked, and it was clean", the reading a clean site exists to file. NULL is "did not judge". Stored as one thing, a pristine reef would be indistinguishable from an unsurveyed one, and every average would be taken over the dirty days only. nonehas no materials (trash_logs_none_has_no_kinds). The submit function drops a stale selection, and a count, rather than refusing it.- A log says something about trash (
trash_logs_has_a_reading): an amount, or at least one material. A note alone is a comment, not a reading.
The bands and the material list are the almanac's, unchanged. The materials follow the ICC cleanup datasheet split, so the shop's figures read beside everyone else's, with fishing gear on its own because nets, line and traps come from a different source than consumer litter and are what divers are best placed to see.
Writes and reads
authenticated has SELECT only. Every write is a SECURITY DEFINER function, so a diver cannot file an already-approved log:
submit_trash_log(site_id, obs_date, amount, kinds, piece_count, notes)files or revises the caller's own log for that site and day, always aspending. Fields are assigned outright (the form posts the whole log). The date may be at most a day ahead, which absorbs the shop-to-UTC offset, and a log staff have ruled on cannot be revised.withdraw_trash_log(log_id)deletes the caller's own pending log, and answers "no such log" and "not yours" identically.moderate_trash_log(log_id, status, staff_notes)is staff/admin only.trash_logs_in_range(from, to)returns approved logs with site name and contributor name. The page reads the last 90 days and groups them by site, since the question a trash record answers is where it collects.trash_pending_logs()is the staff review queue, oldest first.
RLS on the table: a diver reads their own logs (any status) and every approved log; staff and admin read all of them.
Turning it off
features.trashTracker: false removes the /trash route and its home-screen tile. The table and its functions stay in the database, because migrations are shared by every deployment: the flag takes the feature out of the app, not out of the database, so the app stops filing logs but a signed-in user calling the functions directly still could. Turning the module back on brings back everything filed before. The admin database backup includes the table whether the module is on or off.