max / makenotwork
| 1 | -- Fileless items should be `clean`, not stuck `pending`. |
| 2 | -- |
| 3 | -- `items.scan_status` defaulted to 'pending' (migration 004) and is only ever |
| 4 | -- moved to a real verdict by the scan worker / `commit_upload` when an |
| 5 | -- item-level file (audio/video/cover) is uploaded. An item with no such file — |
| 6 | -- Text items (inline content), and items whose downloads live in `versions` |
| 7 | -- (which carry their own `scan_status`) — therefore stayed 'pending' forever. |
| 8 | -- |
| 9 | -- Run #21 tightened discovery to `scan_status = 'clean'` (from `!= 'quarantined'`), |
| 10 | -- which silently dropped every fileless item from `/discover` — including priced |
| 11 | -- Text items. There is nothing to scan on a fileless item, so 'clean' is the |
| 12 | -- correct resting state (this matches `media_files`, which already defaults to |
| 13 | -- 'clean'). Uploading an item-level file still flips the item to 'pending' via |
| 14 | -- `commit_upload`, and the scan worker writes the real verdict, so files are not |
| 15 | -- surfaced before they are scanned. Per-download safety is independently gated |
| 16 | -- by each version's own `scan_status` at download time. |
| 17 | items ALTER COLUMN scan_status SET DEFAULT 'clean'; |
| 18 | |
| 19 | -- Backfill existing fileless items that are stuck 'pending'. Items with an |
| 20 | -- item-level file present keep their real status (a genuinely-pending scan is |
| 21 | -- left pending; a quarantined/held item is untouched). |
| 22 | UPDATE items |
| 23 | SET scan_status = 'clean' |
| 24 | WHERE scan_status = 'pending' |
| 25 | AND audio_s3_key IS NULL |
| 26 | AND video_s3_key IS NULL |
| 27 | AND cover_s3_key IS NULL; |
| 28 |