-- Photos in posts: resized in the browser, checked and stripped of their -- metadata by the forum, kept in the object storage (forum-photos/), with a -- square preview. Uploaded first (post_id NULL), attached when the post is -- sent; unattached ones go after a day. At most five a member a day. CREATE TABLE forum.photos ( id uuid PRIMARY KEY, owner_id uuid NOT NULL REFERENCES users ON DELETE CASCADE, post_id bigint REFERENCES forum.posts ON DELETE CASCADE, -- Files in the bucket's forum-photos/ folder: the picture and its preview. file text NOT NULL, thumb text NOT NULL, width integer NOT NULL, height integer NOT NULL, bytes integer NOT NULL, created_at timestamptz NOT NULL DEFAULT now() ); CREATE INDEX photos_post_idx ON forum.photos (post_id, created_at) WHERE post_id IS NOT NULL; CREATE INDEX photos_owner_idx ON forum.photos (owner_id, created_at DESC);