mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-29 14:21:34 +00:00
Update triggers.sql
This commit is contained in:
parent
28fafdde9b
commit
5be7daf72a
1 changed files with 83 additions and 2 deletions
|
@ -564,8 +564,10 @@ BEGIN
|
||||||
IF NOT (NEW.path ~ ('*.' || id)::lquery) THEN
|
IF NOT (NEW.path ~ ('*.' || id)::lquery) THEN
|
||||||
NEW.path = NEW.path || id;
|
NEW.path = NEW.path || id;
|
||||||
END IF;
|
END IF;
|
||||||
-- Set `ap_id`
|
-- Set local apub URLs
|
||||||
NEW.ap_id = coalesce(NEW.ap_id, r.local_url('/comment/' || id));
|
IF NEW.local THEN
|
||||||
|
NEW.ap_id = coalesce(NEW.ap_id, r.local_url('/comment/' || id));
|
||||||
|
END IF;
|
||||||
RETURN NEW;
|
RETURN NEW;
|
||||||
END
|
END
|
||||||
$$;
|
$$;
|
||||||
|
@ -575,3 +577,82 @@ CREATE TRIGGER change_values
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
EXECUTE FUNCTION r.comment_change_values ();
|
EXECUTE FUNCTION r.comment_change_values ();
|
||||||
|
|
||||||
|
CREATE FUNCTION r.community_change_values ()
|
||||||
|
RETURNS TRIGGER
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $$
|
||||||
|
BEGIN
|
||||||
|
-- Set local apub URLs
|
||||||
|
IF NEW.local THEN
|
||||||
|
NEW.actor_id = coalesce(NEW.actor_id, r.local_url('/c/' || NEW.id::text));
|
||||||
|
NEW.followers_url = coalesce(NEW.followers_url, NEW.actor_id || '/followers');
|
||||||
|
NEW.inbox_url = coalesce(NEW.inbox_url, NEW.actor_id || '/inbox');
|
||||||
|
NEW.moderators_url = coalesce(NEW.moderators_url, NEW.actor_id || '/moderators');
|
||||||
|
NEW.featured_url = coalesce(NEW.featured_url, NEW.actor_id || '/featured');
|
||||||
|
NEW.shared_inbox_url = coalesce(NEW.shared_inbox_url, r.local_url('/inbox');
|
||||||
|
END IF;
|
||||||
|
RETURN NEW;
|
||||||
|
END
|
||||||
|
$$;
|
||||||
|
|
||||||
|
CREATE TRIGGER change_values
|
||||||
|
BEFORE INSERT OR UPDATE ON community
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION r.community_change_values ();
|
||||||
|
|
||||||
|
CREATE FUNCTION r.person_change_values ()
|
||||||
|
RETURNS TRIGGER
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $$
|
||||||
|
BEGIN
|
||||||
|
-- Set local apub URLs
|
||||||
|
IF NEW.local THEN
|
||||||
|
NEW.actor_id = coalesce(NEW.actor_id, r.local_url('/u/' || NEW.id::text));
|
||||||
|
NEW.inbox_url = coalesce(NEW.inbox_url, NEW.actor_id || '/inbox');
|
||||||
|
NEW.shared_inbox_url = coalesce(NEW.shared_inbox_url, r.local_url('/inbox');
|
||||||
|
END IF;
|
||||||
|
RETURN NEW;
|
||||||
|
END
|
||||||
|
$$;
|
||||||
|
|
||||||
|
CREATE TRIGGER change_values
|
||||||
|
BEFORE INSERT OR UPDATE ON person
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION r.person_change_values ();
|
||||||
|
|
||||||
|
CREATE FUNCTION r.post_change_values ()
|
||||||
|
RETURNS TRIGGER
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $$
|
||||||
|
BEGIN
|
||||||
|
-- Set local apub URLs
|
||||||
|
IF NEW.local THEN
|
||||||
|
NEW.ap_id = coalesce(NEW.ap_id, r.local_url('/post/' || NEW.id::text));
|
||||||
|
END IF;
|
||||||
|
RETURN NEW;
|
||||||
|
END
|
||||||
|
$$;
|
||||||
|
|
||||||
|
CREATE TRIGGER change_values
|
||||||
|
BEFORE INSERT OR UPDATE ON post
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION r.post_change_values ();
|
||||||
|
|
||||||
|
CREATE FUNCTION r.private_message_change_values ()
|
||||||
|
RETURNS TRIGGER
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $$
|
||||||
|
BEGIN
|
||||||
|
-- Set local apub URLs
|
||||||
|
IF NEW.local THEN
|
||||||
|
NEW.ap_id = coalesce(NEW.ap_id, r.local_url('/private_message/' || NEW.id::text));
|
||||||
|
END IF;
|
||||||
|
RETURN NEW;
|
||||||
|
END
|
||||||
|
$$;
|
||||||
|
|
||||||
|
CREATE TRIGGER change_values
|
||||||
|
BEFORE INSERT OR UPDATE ON private_message
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION r.private_message_change_values ();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue