Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: member_limit.sql
package db
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const countWorkspaceMemberSlots = `-- name: CountWorkspaceMemberSlots :one
SELECT
(SELECT count(*)
FROM member m
WHERE m.workspace_id = $1
AND m.role <> 'guest')::bigint AS members,
(SELECT count(*)
FROM workspace_invitation wi
WHERE wi.workspace_id = $1
AND wi.status = 'pending'
AND wi.expires_at > now()
AND wi.role <> 'guest')::bigint AS pending_invitations
`
type CountWorkspaceMemberSlotsRow struct {
Members int64 `json:"members"`
PendingInvitations int64 `json:"pending_invitations"`
}
// Members and live pending invitations that take a member slot. Guests take
// none.
func (q *Queries) CountWorkspaceMemberSlots(ctx context.Context, workspaceID pgtype.UUID) (CountWorkspaceMemberSlotsRow, error) {
row := q.db.QueryRow(ctx, countWorkspaceMemberSlots, workspaceID)
var i CountWorkspaceMemberSlotsRow
err := row.Scan(&i.Members, &i.PendingInvitations)
return i, err
}
const lockWorkspaceMemberAdmission = `-- name: LockWorkspaceMemberAdmission :exec
SELECT pg_advisory_xact_lock(hashtextextended($1::uuid::text || ':member_admission', 0))
`
// Member limit (entitlement gate "members").
// Serializes member-limit admissions within one workspace so the count and
// the write it guards see the same members and invitations.
func (q *Queries) LockWorkspaceMemberAdmission(ctx context.Context, workspaceID pgtype.UUID) error {
_, err := q.db.Exec(ctx, lockWorkspaceMemberAdmission, workspaceID)
return err
}