Serves an attachment only to those who may see what it was pasted into, and deletes it once that is gone. It adds attachments.resource_type, the kind of thing an attachment's resource_id names. Without it, an attachment couldn't tell whose it was: one pasted into a private dump was served to anyone with its URL, and one whose dump, comment or message was deleted was kept for good.

Functions

f
up(db: DatabaseSync): void

Run once by runMigrations. Existing bound attachments get the type of the table that holds their resource; one whose resource is gone gets none, and the startup purge deletes it. A database made from schema.sql already has the column.

Usage

import * as mod from "api/db/migrations/0018_attachment_resource_type.ts";