Skip to content

Set default group for signups #1662

Answered by wigman
wigman asked this question in Self Hosting
Nov 17, 2020 · 3 comments · 3 replies
Discussion options

You must be logged in to vote

Thanks for your reply!

For the meantime, do you recon this would work? I'm no SQL expert and especially not PostgreSQL so would appreciate a second opinion :)

CREATE OR REPLACE FUNCTION add_new_user_to_group()
  RETURNS trigger AS
$$
BEGIN
    INSERT INTO group_users
        ("userId",
        "groupId",
        "createdById",
        "createdAt",
        "updatedAt",
        "deletedAt")
    VALUES
        (NEW.id,
        (SELECT id from groups where name='readers'),
        (SELECT id from users where "isAdmin"='true'),
        NOW(),
        NOW(),
        null);
	
    RETURN NEW;
END
$$
  LANGUAGE plpgsql;


CREATE TRIGGER after_user_insert
    AFTER INSERT ON users
    FOR EACH ROW
…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@tommoor
Comment options

@wigman
Comment options

Answer selected by wigman
Comment options

You must be logged in to vote
1 reply
@tommoor
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants