 
 ------ Generic > Trigger Functions ---------------------------------------------
 
+-- When updating a row, automatically update the modified column too.
 create or replace function sg_private.update_modified_column()
 returns trigger as $$
 begin new.modified = now();


------ 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.';



