Re-resolve members absent after batch adds by forum user ID. Update renamed usernames and quarantine deleted users so they cannot block healthy group delivery. Align the fake with Discourse's partial-batch semantics.
48 lines
1.3 KiB
SQL
48 lines
1.3 KiB
SQL
-- name: CreateUserLink :one
|
|
INSERT INTO discourse.user_links (person_id, discourse_user_id, discourse_username, linked_via)
|
|
VALUES ($1, $2, $3, $4)
|
|
RETURNING *;
|
|
|
|
-- name: GetUserLinkByPersonID :one
|
|
SELECT * FROM discourse.user_links
|
|
WHERE person_id = $1;
|
|
|
|
-- name: GetUserLinkByDiscourseUserID :one
|
|
SELECT * FROM discourse.user_links
|
|
WHERE discourse_user_id = $1;
|
|
|
|
-- name: ListUserLinks :many
|
|
SELECT * FROM discourse.user_links
|
|
ORDER BY discourse_username ASC;
|
|
|
|
-- name: ListConflictedUserLinks :many
|
|
SELECT * FROM discourse.user_links
|
|
WHERE status = 'conflict'
|
|
ORDER BY discourse_username ASC;
|
|
|
|
-- name: SetUserLinkConflict :one
|
|
UPDATE discourse.user_links
|
|
SET status = 'conflict'
|
|
WHERE person_id = $1
|
|
RETURNING *;
|
|
|
|
-- name: SetUserLinkOrphaned :one
|
|
-- Quarantine: the linked Discourse user no longer resolves on the forum.
|
|
-- Orphaned links leave the convergence desired set (see migration 00003).
|
|
UPDATE discourse.user_links
|
|
SET status = 'orphaned'
|
|
WHERE person_id = $1
|
|
RETURNING *;
|
|
|
|
-- name: UpdateUserLinkUsername :one
|
|
-- Self-heal: forum-side rename detected — the id-keyed admin record is
|
|
-- authoritative for the username, which is only a delivery address.
|
|
UPDATE discourse.user_links
|
|
SET discourse_username = $2
|
|
WHERE person_id = $1
|
|
RETURNING *;
|
|
|
|
-- name: DeleteUserLinkByPersonID :execrows
|
|
DELETE FROM discourse.user_links
|
|
WHERE person_id = $1;
|