CREATE TABLE device_attachments ( id uuid PRIMARY KEY, sender_device uuid NOT NULL REFERENCES devices(id) ON DELETE CASCADE, recipient_device uuid NOT NULL REFERENCES devices(id) ON DELETE CASCADE, ciphertext bytea NOT NULL CHECK (octet_length(ciphertext) BETWEEN 16 AND 8388624), created_at timestamptz NOT NULL DEFAULT now(), CHECK (sender_device <> recipient_device) ); CREATE INDEX device_attachments_expiry ON device_attachments(created_at);