 grant select on table sg_public.suggest to sg_anonymous, sg_user, sg_admin;
 
 -- Insert suggest: any via function.
--- TODO insert, when I insert a suggest, add a suggest_follower too
+grant insert (name, body) on table sg_public.suggest to sg_anonymous, sg_user, sg_admin;
 
 -- Update suggest: admin.
 grant update on table sg_public.suggest to sg_admin;


------ Suggests, Suggest Followers > Triggers ----------------------------------

create trigger update_suggest_modified
  before update on sg_public.suggest
  for each row execute procedure sg_private.update_modified_column();

end;
$$ language 'plpgsql';
comment on function sg_private.update_modified_column()
  is 'Whenever the row changes, update the `modified` column.';

-- When inserting a row, automatically set the user_id field.
create or replace function sg_private.insert_user_id_column()
returns trigger as $$
begin new.user_id = current_setting('jwt.claims.user_id')::uuid;
  return new;
end;
$$ language 'plpgsql';
comment on function sg_private.insert_user_id_column()
  is 'When inserting a row, automatically set the `user_id` field.';



