-- Denormalized threadgate upsert: Update posts table directly
-- Threadgates control reply permissions - now stored in posts table
-- Parameters: $1=actor_id, $2=post_rkey, $3=allow[], $4=hidden_actor_ids[], $5=hidden_rkeys[]
--            $6=allowed_list_actor_ids[], $7=allowed_list_rkeys[]
-- Note: We update the post record ($1, $2) with threadgate data
-- The threadgate's own (actor_id, rkey, cid) are no longer stored separately

UPDATE posts
SET
    threadgate_allow = $3::text[]::threadgate_rule[],
    threadgate_hidden_actor_ids = $4::integer[],
    threadgate_hidden_rkeys = $5::bigint[],
    threadgate_allowed_list_actor_ids = $6::integer[],
    threadgate_allowed_list_rkeys = $7::text[]
WHERE actor_id = $1
  AND rkey = $2
