-- name: UpsertProjectMember :one
INSERT INTO project_members (project_id, user_id, role, added_by)
VALUES ($1, $2, $3, $4)
ON CONFLICT (project_id, user_id)
DO UPDATE SET role = EXCLUDED.role
RETURNING project_id, user_id, role, created_at, added_by;

-- name: DeleteProjectMember :execrows
DELETE FROM project_members
WHERE project_id = $1 AND user_id = $2;

-- name: GetProjectMember :one
SELECT project_id, user_id, role, created_at, added_by
FROM project_members
WHERE project_id = $1 AND user_id = $2;

-- name: ListProjectMembers :many
SELECT project_id, user_id, role, created_at, added_by
FROM project_members
WHERE project_id = $1
ORDER BY created_at ASC;
