store

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package store is the Postgres metadata store: principals, repos, branches, efforts, workspaces, changesets and the operation log. File contents and trees live in the blob store; this package holds everything else.

Index

Constants

View Source
const (
	JobQueued     = "queued"
	JobLeased     = "leased"
	JobDone       = "done"
	JobFailed     = "failed"
	JobSuperseded = "superseded"
)

Job states.

View Source
const (
	CheckPass    = "pass"
	CheckFail    = "fail"
	CheckNeutral = "neutral"
	CheckPending = "pending"
)

Check result statuses.

View Source
const (
	CheckSourceReport = "report" // vx check report (agents, CI, people)
	CheckSourceLand   = "land"   // a vx land --run command
	CheckSourceReview = "review" // a person approved a review under a human [[policy]]
)

Where a check result came from.

View Source
const DefaultOrg = "default"

DefaultOrg is the organization repositories without an owner part were put in when organizations arrived, and where CreateRepo puts a repo whose OrgID is not set.

View Source
const TokenPrefix = "vxt_"

TokenPrefix starts every vx token, so leaked tokens are easy to spot.

Variables

View Source
var ErrAmbiguous = errors.New("ambiguous")

ErrAmbiguous is returned when an id prefix matches more than one row.

View Source
var ErrCycle = errors.New("dependency cycle")

ErrCycle is returned when a task dependency would make tasks wait for each other.

View Source
var ErrExists = errors.New("already exists")

ErrExists is returned when a unique row already exists.

View Source
var ErrLeaseLost = errors.New("lease lost")

ErrLeaseLost is returned when leasing a job that is no longer queued, or renewing or releasing one whose lease the caller no longer holds.

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when a row does not exist.

View Source
var ErrPurgeStarted = errors.New("its purge has started")

ErrPurgeStarted is returned when restoring an organization whose purge has begun.

View Source
var PurgeBatch = 5000

PurgeBatch is how many rows one purge transaction deletes.

Functions

func BlobLockKey added in v0.6.0

func BlobLockKey(h hash.Hash) int64

BlobLockKey is the advisory lock key of one object's hash, shared by the purge (exclusive, while it checks and deletes) and recording (shared, while it checks an object a purge marked).

func NewID

func NewID() uuid.UUID

NewID returns a new random UUID.

func OrderPair added in v0.3.0

func OrderPair(a, b uuid.UUID) (uuid.UUID, uuid.UUID, bool)

OrderPair returns a and b in the order effort_overlaps stores them.

func Slugify

func Slugify(name string) string

Slugify turns an effort name into a short URL-safe slug.

func ValidateHandle

func ValidateHandle(kind PrincipalKind, handle string) error

ValidateHandle checks a handle: lowercase name, and for agents "owner/name".

func ValidateRepoName

func ValidateRepoName(name string) error

ValidateRepoName checks names like "shop-api" or "acme/shop-api".

Types

type AccessFact added in v0.2.0

type AccessFact struct {
	Principal Principal
	Role      string // read, write or admin
	Via       string // "org owner", "org admin", "org default", "user:alice", "team:acme/backend"
}

AccessFact is one source of a principal's role on a repository, for listing who has access and why.

type AgentScope added in v0.4.0

type AgentScope struct {
	AgentID        uuid.UUID
	Allow          []string // globs; empty: every path the agent's person may change
	Deny           []string // globs; win over Allow
	MaxLandsPerDay int
	MaxLines       int // changed lines (added + deleted) per land
	MaxFiles       int // changed files per land
	MaxWorkspaces  int // open workspaces at once
	UpdatedBy      *uuid.UUID
	UpdatedAt      time.Time
}

AgentScope limits what an agent may change and how much (agent_scopes). The zero value has no limits; zero budgets mean no limit.

func (AgentScope) Unlimited added in v0.4.0

func (s AgentScope) Unlimited() bool

Unlimited reports whether the scope limits nothing.

type AuditEntry added in v0.5.0

type AuditEntry struct {
	ID      int64
	At      time.Time
	Op      string
	Target  string
	RepoID  *uuid.UUID
	Repo    string // repository name, "" for server-level entries
	Org     string // the repository's organization, or the organization an org-level entry is about
	ActorID *uuid.UUID
	Actor   string // principal ref; "" for the server itself
	Before  json.RawMessage
	After   json.RawMessage
}

AuditEntry is one operation log entry with the names of what it refers to.

type AuditFilter added in v0.5.0

type AuditFilter struct {
	// Org limits to the organization's repositories and to the
	// organization-level entries about it (org.*, team.*, github.org.*
	// with the organization as target). OrgHandle must be its handle.
	Org       *uuid.UUID
	OrgHandle string
	Repo      *uuid.UUID
	Actor     *uuid.UUID
	Since     time.Time // at >= Since
	Until     time.Time // at < Until
	AfterID   int64     // id > AfterID, for paging
	Limit     int
	Desc      bool // newest first
	// Payload also reads before and after. Without it they stay nil and
	// never leave the database. With ServerPayloadOnly, only those of
	// entries without a repository are read.
	Payload           bool
	ServerPayloadOnly bool
}

AuditFilter selects operation log entries for an export. Zero fields do not filter.

type Branch

type Branch struct {
	RepoID   uuid.UUID
	Name     string
	Head     hash.Hash // changeset
	GitSHA   string
	SyncedAt time.Time
}

Branch is an upstream branch that vx follows.

type CIToken added in v0.7.0

type CIToken struct {
	ID          uuid.UUID
	RepoID      uuid.UUID
	Name        string
	PrincipalID uuid.UUID
	TokenID     uuid.UUID
	Checks      []string // empty: every check
	CreatedBy   *uuid.UUID
	CreatedAt   time.Time
	RevokedAt   *time.Time
	RepoName    string
	Handle      string // the service principal's handle
}

CIToken is a CI token of a repository (ci_tokens): a service principal that may only report results on it and read its jobs' inputs.

type CLILogin added in v0.2.0

type CLILogin struct {
	DeviceHash   []byte
	UserCode     string
	ClientName   string
	Status       string // pending, approved, denied, used
	PrincipalID  *uuid.UUID
	ClientIP     string
	ExpiresAt    time.Time
	CreatedAt    time.Time
	LastPolledAt *time.Time
	DecidedAt    *time.Time
	// HasSecret is true when token_secret_enc is set; vx never sets it (the
	// token is created when the CLI collects it).
	HasSecret bool
}

CLILogin is a browser login of the CLI (table cli_logins). The device code is known only by its sha256.

type CachedRole added in v0.2.0

type CachedRole struct {
	Role      string
	CheckedAt time.Time
}

CachedRole is what GitHub said, and when.

type ChangesetRow

type ChangesetRow struct {
	Hash     hash.Hash
	RepoID   uuid.UUID
	EffortID *uuid.UUID
	*object.Changeset
	// Warnings the server found in the tree when the change landed. They
	// are not part of the changeset's encoding or hash.
	Warnings []Warning
}

ChangesetRow is a changeset with the metadata vx keeps beside it.

type ChangesetTrees added in v0.2.0

type ChangesetTrees struct {
	Hash         hash.Hash
	FirstParent  hash.Hash
	Tree         hash.Hash
	SnapshotTree hash.Hash // the uploaded snapshot of a merged land, else zero
}

ChangesetTrees is the tree information of one changeset, for walking every tree in a repo.

type CheckArtifact added in v0.7.0

type CheckArtifact struct {
	Name        string
	ContentType string
	Hash        hash.Hash
	Size        int64
}

CheckArtifact is a file attached to a check result: a blob of the repository.

type CheckJob added in v0.7.0

type CheckJob struct {
	ID              uuid.UUID
	RepoID          uuid.UUID
	EffortID        uuid.UUID
	Check           string
	Runner          string // agent:KIND, ci or human
	Reporter        string // the check's reporter rule when the job was made
	AllowSamePerson bool
	Trigger         string // land, ship or manual
	ChangeID        string
	Changeset       hash.Hash // zero before the change landed (a land gate's job)
	Intent          string
	BaseTree        hash.Hash
	Tree            hash.Hash
	AuthorPrincipal string // ref of who made the change
	AuthorPerson    string // ref of their person
	Inputs          []string
	Values          map[string]string
	State           string
	Attempts        int
	MaxAttempts     int
	Timeout         time.Duration
	LeaseOwner      *uuid.UUID
	LeaseExpiresAt  *time.Time
	LeasedAt        *time.Time
	Reason          string
	ResultID        string
	RequestedBy     *uuid.UUID
	SupersededBy    *uuid.UUID
	CreatedAt       time.Time
	UpdatedAt       time.Time
	RepoName        string
	EffortSlug      string
}

CheckJob is one check to run on one tree of an effort, by a runner that is not the landing agent (check_jobs). RepoName and EffortSlug are read from the job's repository and effort.

func (CheckJob) Pending added in v0.7.0

func (j CheckJob) Pending() bool

Pending reports whether the job still waits for a result.

type CheckJobFilter added in v0.7.0

type CheckJobFilter struct {
	RepoIDs  []uuid.UUID
	EffortID *uuid.UUID
	States   []string
	Runners  []string
	Limit    int
}

CheckJobFilter selects jobs for ListCheckJobs. Empty fields do not filter; RepoIDs must not be empty.

type CheckResult added in v0.7.0

type CheckResult struct {
	ID         uuid.UUID
	RepoID     uuid.UUID
	EffortID   *uuid.UUID
	ChangeID   string
	Tree       hash.Hash
	CheckName  string // "" for a vx land --run command no check names
	Status     string
	Summary    string
	LogHash    hash.Hash // zero: no log
	LogSize    int64
	Data       json.RawMessage // nil: no data
	DataName   string
	ReporterID *uuid.UUID
	Reporter   string // principal ref
	OnBehalfOf string
	Model      string
	CITokenID  *uuid.UUID
	How        string // the command of a run check
	Source     string
	StartedAt  *time.Time
	FinishedAt *time.Time
	CreatedAt  time.Time
	Artifacts  []CheckArtifact
}

CheckResult is one result of a check, bound to a change and the exact tree it describes (migration 036).

type CheckResultFilter added in v0.7.0

type CheckResultFilter struct {
	RepoID   uuid.UUID
	EffortID uuid.UUID
	ChangeID string
	Tree     hash.Hash
	Trees    []hash.Hash // any of these trees
	Check    string
	Limit    int
}

CheckResultFilter selects check results of one repository. Zero fields do not filter.

type Claim added in v0.2.0

type Claim struct {
	ID          uuid.UUID
	RepoID      uuid.UUID
	EffortID    uuid.UUID
	OwnerID     uuid.UUID
	WorkspaceID *uuid.UUID
	Targets     []string
	Reason      string
	CreatedAt   time.Time
	ExpiresAt   time.Time
	ReleasedAt  *time.Time
	RepoName    string
	EffortSlug  string
	// WorkspaceOpen is read from the workspace the claim is tied to.
	WorkspaceOpen bool
	// MovingTo is where the claimed code is being moved (vx claim
	// --moving pkg.Func --to path); empty for other claims.
	MovingTo string
}

Claim is a stored claim. RepoName and EffortSlug are read from the claim's repo and effort. A claim is active while ReleasedAt is nil and either ExpiresAt is after now or the workspace it is tied to is open: a workspace's claims last as long as the workspace.

func (Claim) Active added in v0.2.0

func (c Claim) Active(now time.Time) bool

Active reports whether the claim is neither released nor expired at now.

type Effort

type Effort struct {
	ID         uuid.UUID
	RepoID     uuid.UUID
	Slug       string
	Name       string
	Goal       string
	BaseBranch string
	Base       hash.Hash // upstream changeset the effort sits on
	Head       hash.Hash
	Version    int64
	State      EffortState
	OwnerID    uuid.UUID
	CreatedAt  time.Time
	UpdatedAt  time.Time
}

Effort is a shared line of work that agents land changes into.

type EffortOverlap added in v0.3.0

type EffortOverlap struct {
	RepoID      uuid.UUID
	EffortA     uuid.UUID
	EffortB     uuid.UUID
	Status      string // clean, overlap, conflict
	SharedFiles []string
	Conflicts   []string
	Warnings    []Warning
	AHead       string // changeset hashes the forecast was computed for
	BHead       string
	TargetHead  string // the base branch head both were replayed onto
	ANote       *uuid.UUID
	BNote       *uuid.UUID
	CheckedAt   time.Time
}

EffortOverlap is a stored forecast of what happens when two open efforts of one repository both ship. EffortA < EffortB (byte order of the ids).

type EffortState

type EffortState string

EffortState is the lifecycle state of an effort.

const (
	EffortOpen      EffortState = "open"
	EffortShipping  EffortState = "shipping"
	EffortMerged    EffortState = "merged"
	EffortAbandoned EffortState = "abandoned"
)

type FileChange

type FileChange struct {
	object.Change
	Added   int
	Deleted int
}

FileChange is a changed path recorded with a changeset, with line counts.

type GitHubApp added in v0.2.0

type GitHubApp struct {
	AppID            int64
	Slug             string
	HTMLURL          string
	ClientID         string
	ClientSecretEnc  []byte
	PrivateKeyEnc    []byte
	WebhookSecretEnc []byte
	CreatedBy        *uuid.UUID
	CreatedAt        time.Time
}

GitHubApp is the row of this server's GitHub App. The _Enc fields hold ciphertext sealed with the server key (internal/secret), never plaintext.

type GitHubAppGap added in v0.4.0

type GitHubAppGap struct {
	What   string // e.g. "checks:write"
	Detail string
	SeenAt time.Time
}

GitHubAppGap is a permission or event the App lacks.

type GitHubCacheScope added in v0.2.0

type GitHubCacheScope struct {
	RepoID         *uuid.UUID
	GitHubRepoID   int64
	GitHubOrgID    int64
	GitHubUserID   int64
	InstallationID int64
}

GitHubCacheScope selects cached GitHub answers to drop. Every set field adds its own rows (the fields are OR-ed): RepoID or GitHubRepoID that repository's roles; GitHubOrgID the roles on every repository of installations on that account and memberships in it; GitHubUserID every row of the person linked to that GitHub user; InstallationID the roles on every repository of that installation and memberships in its account.

type GitHubCheckRunRow added in v0.7.0

type GitHubCheckRunRow struct {
	ShipmentID uuid.UUID
	CheckName  string
	HeadSHA    string
	GitHubID   int64
	State      string // what was last published
	UpdatedAt  time.Time
}

GitHubCheckRunRow is the GitHub check run vx keeps for one check on one pull request head.

type GitHubInstallationRow added in v0.2.0

type GitHubInstallationRow struct {
	ID                  int64
	AccountID           int64
	AccountLogin        string
	AccountType         string // Organization or User
	OrgID               *uuid.UUID
	RepositorySelection string
	SuspendedAt         *time.Time
}

GitHubInstallationRow is an installation of the App as vx records it.

type GitHubLink struct {
	PrincipalID uuid.UUID
	UserID      int64
	Login       string
}

GitHubLink is the GitHub account a person signs in with.

type GitObject

type GitObject struct {
	GitHash string
	VXHash  hash.Hash
	Kind    string // blob or tree
}

GitObject maps a git object to the vx object with the same content.

type Identity added in v0.5.0

type Identity struct {
	Issuer, Subject string
	PersonID        uuid.UUID
	Email           string
	CreatedAt       time.Time
	LastUsedAt      *time.Time
}

Identity is a person's account at an identity provider.

type MergeStats added in v0.5.0

type MergeStats struct {
	Tokens, Agents, Orgs, Teams, Grants, Identities int
	GitHub                                          bool
}

MergeStats is what MergePeople moved.

type Note added in v0.2.0

type Note struct {
	ID         uuid.UUID
	Seq        int64 // insertion order; breaks ties between equal created_at
	RepoID     uuid.UUID
	EffortID   uuid.UUID
	ThreadID   uuid.UUID // the root note; equals ID for a root
	Kind       string
	Targets    []string
	AuthorID   uuid.UUID
	ToID       *uuid.UUID
	Body       string
	State      string // open, answered, closed; "escalated" is computed by readers
	AnswerBy   *time.Time
	CreatedAt  time.Time
	RepoName   string
	EffortSlug string
	// Supersedes is the earlier note this one replaces. SupersededBy is read
	// from the newest note that replaced this one.
	Supersedes   *uuid.UUID
	SupersededBy *uuid.UUID
	System       bool // posted by vx itself
	// CCID is the person a question was copied to because the agent it is
	// addressed to was not working when it was asked.
	CCID *uuid.UUID
	// SimilarTo is the open question this question closely matched when it
	// was asked. Similar is read from the later questions that matched this
	// one, oldest first.
	SimilarTo *uuid.UUID
	Similar   []uuid.UUID
}

Note is a stored board note. RepoName and EffortSlug are read from the note's repo and effort.

func (Note) Cursor added in v0.2.0

func (n Note) Cursor() *NoteCursor

Cursor returns the position right after n.

type NoteCursor added in v0.2.0

type NoteCursor struct {
	CreatedAt time.Time
	Seq       int64
}

NoteCursor is a position in a newest-first listing: the listing continues with notes older than it.

type NoteFilter added in v0.2.0

type NoteFilter struct {
	EffortID uuid.UUID
	Kinds    []string
	Since    time.Time // created at or after
	ThreadID uuid.UUID
	Before   *NoteCursor
	Limit    int // 0: 100
	// Current leaves out notes a newer note superseded.
	Current bool
}

NoteFilter selects an effort's notes. Zero fields do not filter.

type ObjectSize added in v0.5.0

type ObjectSize struct {
	Hash  hash.Hash
	Bytes int64
}

ObjectSize is the bytes one object takes in the blob store.

type Op

type Op struct {
	ID      int64
	RepoID  *uuid.UUID
	ActorID *uuid.UUID
	Op      string
	Target  string
	Before  json.RawMessage
	After   json.RawMessage
	At      time.Time
}

Op is one entry in the operation log.

type Org added in v0.2.0

type Org struct {
	ID              uuid.UUID
	Handle          string
	DisplayName     string
	DefaultRepoRole string // none, read or write
	Personal        bool
	CreatedAt       time.Time
	// GitHubOrgID and GitHubLogin are set for an organization linked to a
	// GitHub organization: its membership follows GitHub.
	GitHubOrgID *int64
	GitHubLogin string
}

Org is an organization. Every repository belongs to one.

func (Org) GitHubLinked added in v0.2.0

func (o Org) GitHubLinked() bool

GitHubLinked reports whether o follows a GitHub organization.

type OrgAgreement added in v0.6.0

type OrgAgreement struct {
	ID            uuid.UUID
	OrgID         uuid.UUID
	VersionID     string
	SHA256        string // of the text as accepted, hex
	AcceptedBy    *uuid.UUID
	AcceptedByRef string // "user:alice", kept when the person is merged or removed
	AcceptedAt    time.Time
	IP            string
}

OrgAgreement is one acceptance of a version of the data processing agreement for an organization.

type OrgCheckVersion added in v0.7.0

type OrgCheckVersion struct {
	OrgID      uuid.UUID
	Version    int
	Source     string          // the [[check]] tables as written
	Checks     json.RawMessage // the parsed definitions, a JSON list
	CreatedBy  *uuid.UUID
	CreatedRef string // "user:alice", kept when the person is removed
	CreatedAt  time.Time
}

OrgCheckVersion is one saved version of an organization's checks.

type OrgDeletion added in v0.6.0

type OrgDeletion struct {
	OrgID        uuid.UUID
	Handle       string
	RequestedBy  string // principal ref
	DeletedAt    time.Time
	PurgeAfter   time.Time
	PurgeStarted *time.Time
	PurgedAt     *time.Time
	PurgedBy     string // "schedule" or "console"
	Step         string
	Counts       map[string]int64
}

OrgDeletion is the record of an organization's deletion. It names no repository and holds no content.

type OrgMember added in v0.2.0

type OrgMember struct {
	Person Principal
	Role   string
	Teams  []string
}

OrgMember is a person in an organization, with their teams.

type OrgQuota added in v0.5.0

type OrgQuota struct {
	OrgID       uuid.UUID
	Repos       *int64
	StoredBytes *int64
	ImportBytes *int64
	PushBytes   *int64
	OpenEfforts *int64
	UpdatedBy   *uuid.UUID
	UpdatedAt   time.Time
}

OrgQuota is an organization's override of the server's quotas. A nil field keeps the server's default; 0 means no limit.

func (OrgQuota) Empty added in v0.5.0

func (o OrgQuota) Empty() bool

Empty reports whether the override changes nothing.

type OrgSSO added in v0.5.0

type OrgSSO struct {
	OrgID           uuid.UUID
	Issuer          string
	ClientID        string
	ClientSecretEnc []byte
	AllowedDomains  []string
	RequireSSO      bool
	UpdatedBy       *uuid.UUID
	UpdatedAt       time.Time
}

OrgSSO is an organization's identity provider configuration.

type OrgWithRole added in v0.2.0

type OrgWithRole struct {
	Org
	Role string
}

OrgWithRole is an organization and a person's role in it ("" when not a member).

type Principal

type Principal struct {
	ID          uuid.UUID
	Kind        PrincipalKind
	Handle      string // "alice" or "alice/claude-backend"
	ParentID    *uuid.UUID
	DisplayName string
	Email       string
	SiteAdmin   bool // may manage people and every organization (humans only)
	CreatedAt   time.Time
}

Principal is a human, an agent acting for a human, or a service account.

func (Principal) Ref

func (p Principal) Ref() string

Ref is the principal's reference string, as recorded on changesets: "user:alice", "agent:alice/claude-backend" or "service:ci".

type PrincipalKind

type PrincipalKind string

PrincipalKind is the type of an identity.

const (
	KindHuman   PrincipalKind = "human"
	KindAgent   PrincipalKind = "agent"
	KindService PrincipalKind = "service"
)

type Provider

type Provider string

Provider is where a repo's upstream lives.

const (
	ProviderGitHub Provider = "github" // remote is "owner/name"
	ProviderGit    Provider = "git"    // remote is a git URL or path
	ProviderNone   Provider = "none"   // vx only, nothing to sync or ship to
	// Hosts with a pull request API besides GitHub; remote is the path on
	// the host ("group/project", "owner/repo", "workspace/repo") and
	// BaseURL the host's web address.
	ProviderGitLab    Provider = "gitlab"
	ProviderGitea     Provider = "gitea"
	ProviderForgejo   Provider = "forgejo"
	ProviderBitbucket Provider = "bitbucket"
)

func (Provider) HostName added in v0.4.0

func (p Provider) HostName() string

HostName is the provider as people call it: "GitHub", "GitLab", ...

func (Provider) Hosted added in v0.4.0

func (p Provider) Hosted() bool

Hosted reports whether p is a host with a pull request API other than GitHub: GitLab, Gitea, Forgejo or Bitbucket Cloud.

func (Provider) PRName added in v0.4.0

func (p Provider) PRName() string

PRName is what the host calls a pull request.

type PurgeOrgRow added in v0.6.0

type PurgeOrgRow struct {
	Org
	Deletion OrgDeletion
	Repos    []uuid.UUID
}

PurgeOrgRow is a deleted organization as the purge sees it.

type PushKey added in v0.5.0

type PushKey struct {
	PrivateKeyEnc []byte // sealed 32-byte P-256 scalar
	PublicKey     string // base64url uncompressed point
	CreatedAt     time.Time
}

PushKey is the server's VAPID key (push_keys).

type PushSubscription added in v0.5.0

type PushSubscription struct {
	ID          uuid.UUID
	PrincipalID uuid.UUID
	Endpoint    string
	P256dh      string
	Auth        string
	Device      string
	CreatedAt   time.Time
	LastSentAt  *time.Time
	LastError   string
}

PushSubscription is a browser that receives a person's notifications.

type Q

type Q struct {
	// contains filtered or unexported fields
}

Q holds the query methods. Store and Tx both embed it, so every query can run on its own or inside a transaction.

func (Q) AcceptOrgAgreement added in v0.6.0

func (q Q) AcceptOrgAgreement(ctx context.Context, a OrgAgreement, text []byte) (out OrgAgreement, created bool, err error)

AcceptOrgAgreement records an acceptance and keeps the text it was for. Accepting a version the organization accepted before returns that acceptance unchanged, with created false.

func (Q) AcceptedAgreementHashes added in v0.6.0

func (q Q) AcceptedAgreementHashes(ctx context.Context) (map[string][]string, error)

AcceptedAgreementHashes returns, for every version id anyone accepted, the hashes of the texts accepted under it (one, unless the operator changed a published text).

func (Q) ActiveClaims added in v0.2.0

func (q Q) ActiveClaims(ctx context.Context, effortID uuid.UUID, now time.Time) ([]Claim, error)

ActiveClaims lists an effort's claims active at now, oldest first.

func (Q) ActiveRebase added in v0.2.0

func (q Q) ActiveRebase(ctx context.Context, effortID uuid.UUID) (Rebase, error)

ActiveRebase returns the effort's running or stopped rebase.

func (Q) AddGitHubAppGap added in v0.4.0

func (q Q) AddGitHubAppGap(ctx context.Context, what, detail string) error

AddGitHubAppGap records that GitHub refused a call for want of what.

func (Q) AddOrgCheckVersion added in v0.7.0

func (q Q) AddOrgCheckVersion(ctx context.Context, v OrgCheckVersion) (OrgCheckVersion, error)

AddOrgCheckVersion saves a new version of an organization's checks, one more than the newest. Two saves at once get different versions (the second waits for the first's lock on the organization).

func (Q) AddPurgeCounts added in v0.6.0

func (q Q) AddPurgeCounts(ctx context.Context, orgID uuid.UUID, add map[string]int64) error

AddPurgeCounts adds to what a purge removed.

func (Q) AddRepoObjects added in v0.2.0

func (q Q) AddRepoObjects(ctx context.Context, repoID uuid.UUID, hashes []hash.Hash) error

AddRepoObjects records that the objects are part of the repo. Recording an object twice is a no-op. Only membership is per repo: the bytes are stored once in the blob store.

func (Q) AddServerNotice added in v0.5.0

func (q Q) AddServerNotice(ctx context.Context, key string) error

AddServerNotice opens a notice (tests and future upgrades); an existing one is left as it is.

func (Q) AddTaskDeps added in v0.2.0

func (q Q) AddTaskDeps(ctx context.Context, task uuid.UUID, deps []uuid.UUID) error

AddTaskDeps makes task wait for each of deps. It returns ErrCycle, adding nothing, when one of deps already waits (directly or not) for task. Callers run it in a transaction with the task's other changes.

func (Q) AddTeamMember added in v0.2.0

func (q Q) AddTeamMember(ctx context.Context, t Team, person uuid.UUID) error

AddTeamMember adds person to team. The person must be a member of the team's organization (ErrNotFound otherwise).

func (Q) AdoptChangesets added in v0.2.0

func (q Q) AdoptChangesets(ctx context.Context, repoID, effortID uuid.UUID, hs []hash.Hash) error

AdoptChangesets marks changesets as part of an effort; a rebase stores its replayed changes without an effort until it finishes.

func (Q) AdvanceEffort

func (q Q) AdvanceEffort(ctx context.Context, id uuid.UUID, seenVersion int64, newHead hash.Hash) (bool, error)

AdvanceEffort moves the effort head with a compare-and-swap on version. It reports false when another writer moved the head first.

func (Q) AgentRunnerKinds added in v0.7.0

func (q Q) AgentRunnerKinds(ctx context.Context, agentID uuid.UUID) ([]string, error)

AgentRunnerKinds returns the runner kinds an agent declared; none when it declared none.

func (Q) AgentScope added in v0.4.0

func (q Q) AgentScope(ctx context.Context, agentID uuid.UUID) (AgentScope, error)

AgentScope returns the scope of an agent; the zero value (with AgentID set) when none was ever set.

func (Q) AgreementText added in v0.6.0

func (q Q) AgreementText(ctx context.Context, sha256 string) ([]byte, error)

AgreementText returns an accepted text by its SHA-256.

func (Q) AnswersToQuestionsBy added in v0.2.0

func (q Q) AnswersToQuestionsBy(ctx context.Context, author uuid.UUID, since time.Time, limit int) ([]Note, error)

AnswersToQuestionsBy returns answers created at or after since in threads whose root is a question asked by author, newest first.

func (Q) AnyOrgSSO added in v0.5.0

func (q Q) AnyOrgSSO(ctx context.Context) (bool, error)

AnyOrgSSO reports whether any organization has single sign-on.

func (Q) Authenticate

func (q Q) Authenticate(ctx context.Context, secret string) (Principal, error)

Authenticate resolves a token to its principal.

func (Q) AuthenticateToken added in v0.2.0

func (q Q) AuthenticateToken(ctx context.Context, secret string) (Principal, uuid.UUID, error)

AuthenticateToken resolves a token to its principal and also returns the token's id, so callers know which token a request was made with.

func (Q) CITokenOf added in v0.7.0

func (q Q) CITokenOf(ctx context.Context, principalID uuid.UUID) (CIToken, error)

CITokenOf returns the active CI token whose service principal is principalID. Revoked tokens and repositories of deleted organizations are not found.

func (Q) CLILoginApprover added in v0.5.0

func (q Q) CLILoginApprover(ctx context.Context, deviceHash []byte) (uuid.UUID, error)

CLILoginApprover is the token that approved a CLI login (uuid.Nil when unknown).

func (Q) CLILoginByDevice added in v0.2.0

func (q Q) CLILoginByDevice(ctx context.Context, deviceHash []byte) (CLILogin, error)

CLILoginByDevice returns a login by device hash, locked for update when run in a transaction.

func (Q) CLILoginByUserCode added in v0.2.0

func (q Q) CLILoginByUserCode(ctx context.Context, userCode string) (CLILogin, error)

CLILoginByUserCode returns a login by user code, locked for update when run in a transaction.

func (Q) Chain

func (q Q) Chain(ctx context.Context, repoID uuid.UUID, head, stop hash.Hash, limit int) ([]ChangesetRow, error)

Chain returns changesets from head back along first parents, stopping before stop (exclusive) or after limit rows. Newest first.

func (Q) ChainLength added in v0.2.0

func (q Q) ChainLength(ctx context.Context, repoID uuid.UUID, head, stop hash.Hash, limit int) (int, error)

ChainLength counts the changesets Chain would return, without loading them: from head back along first parents, stopping before stop or after limit.

func (Q) ChangesetByGitSHA

func (q Q) ChangesetByGitSHA(ctx context.Context, repoID uuid.UUID, sha string) (ChangesetRow, error)

ChangesetByGitSHA finds the changeset imported from a git commit.

func (Q) CheckJobByID added in v0.7.0

func (q Q) CheckJobByID(ctx context.Context, id uuid.UUID) (CheckJob, error)

CheckJobByID returns one job.

func (Q) CheckJobsByPrefix added in v0.7.0

func (q Q) CheckJobsByPrefix(ctx context.Context, repoIDs []uuid.UUID, prefix string) ([]CheckJob, error)

CheckJobsByPrefix returns the jobs of the given repositories whose id starts with prefix (hex digits of the id, dashes ignored).

func (Q) CheckResultByPrefix added in v0.7.0

func (q Q) CheckResultByPrefix(ctx context.Context, prefix string, repos []uuid.UUID) (CheckResult, error)

CheckResultByPrefix resolves a check result id or a prefix of at least 8 hex characters among the results of the given repositories (nil: any).

func (Q) ClaimByID added in v0.2.0

func (q Q) ClaimByID(ctx context.Context, id uuid.UUID) (Claim, error)

ClaimByID loads a claim, active or not.

func (Q) ClaimByPrefix added in v0.2.0

func (q Q) ClaimByPrefix(ctx context.Context, prefix string) (Claim, error)

ClaimByPrefix finds the one claim whose id starts with prefix (lowercase hex and dashes). It returns ErrNotFound or ErrAmbiguous otherwise.

func (Q) ClaimPush added in v0.5.0

func (q Q) ClaimPush(ctx context.Context, principalID uuid.UUID, item string, at time.Time) (bool, error)

ClaimPush records that item is pushed to a principal and reports whether this caller is the first: only the first sends.

func (Q) ClearGitHubAppGap added in v0.4.0

func (q Q) ClearGitHubAppGap(ctx context.Context, what string) error

ClearGitHubAppGap forgets a gap (a call that needed it succeeded); an empty what forgets them all (a new App).

func (Q) CloseShipments added in v0.3.0

func (q Q) CloseShipments(ctx context.Context, effortID uuid.UUID, state string) error

CloseShipments sets the state of an effort's open shipments (merged when the effort was merged, closed when it was abandoned).

func (Q) CopyTokenSSO added in v0.5.0

func (q Q) CopyTokenSSO(ctx context.Context, from, to uuid.UUID) error

CopyTokenSSO gives token to the sign-on marks of token from.

func (Q) CountCLILoginsSince added in v0.2.0

func (q Q) CountCLILoginsSince(ctx context.Context, ip string, since time.Time) (int, error)

CountCLILoginsSince counts logins started from ip since t.

func (Q) CountLands added in v0.4.0

func (q Q) CountLands(ctx context.Context, ref string, from, to time.Time) (int, error)

CountLands counts the changes a principal (by ref, "agent:alice/backend") landed in [from, to): distinct change ids of vx changesets it authored in an effort, so rebased copies of a change do not count again.

func (Q) CountObjectBackfills added in v0.5.0

func (q Q) CountObjectBackfills(ctx context.Context) (int64, error)

CountObjectBackfills is how many repositories wait for their objects to be indexed.

func (Q) CountObjectsWithoutSize added in v0.5.0

func (q Q) CountObjectsWithoutSize(ctx context.Context) (int64, error)

CountObjectsWithoutSize counts objects of repositories whose size is not recorded yet.

func (Q) CountOrgsPendingPurge added in v0.6.0

func (q Q) CountOrgsPendingPurge(ctx context.Context) (int64, error)

CountOrgsPendingPurge counts deleted organizations not purged yet.

func (Q) CountOwners added in v0.2.0

func (q Q) CountOwners(ctx context.Context, org uuid.UUID) (int, error)

CountOwners returns how many owners org has.

func (Q) CountPendingCLILogins added in v0.2.0

func (q Q) CountPendingCLILogins(ctx context.Context, now time.Time) (int, error)

CountPendingCLILogins counts logins nobody decided yet that have not expired, across all addresses.

func (Q) CountRepoObjects added in v0.2.0

func (q Q) CountRepoObjects(ctx context.Context, repoID uuid.UUID) (int, error)

CountRepoObjects returns how many objects are recorded for the repo.

func (Q) CreateCLILogin added in v0.2.0

func (q Q) CreateCLILogin(ctx context.Context, l CLILogin) error

CreateCLILogin stores a new pending login. ErrExists means the user code is taken; the caller picks another.

func (Q) CreateEffort

func (q Q) CreateEffort(ctx context.Context, e Effort) (Effort, error)

CreateEffort inserts an effort with a unique slug derived from its name.

func (Q) CreateInvite added in v0.2.0

func (q Q) CreateInvite(ctx context.Context, login string, by *uuid.UUID, note string, siteAdmin bool) (SignupInvite, error)

CreateInvite invites a GitHub login, or updates the note of an open invite. It returns ErrExists when the invite was already used.

func (Q) CreateLoginCode added in v0.5.0

func (q Q) CreateLoginCode(ctx context.Context, codeHash []byte, principal uuid.UUID, expires, now time.Time) error

CreateLoginCode stores a one-time web sign-in code by its hash and drops expired ones.

func (Q) CreateOrg added in v0.2.0

func (q Q) CreateOrg(ctx context.Context, handle, displayName string, owner uuid.UUID) (Org, error)

CreateOrg inserts an organization and makes owner its owner.

func (Q) CreateOrgWithoutOwner added in v0.2.0

func (q Q) CreateOrgWithoutOwner(ctx context.Context, handle, displayName string) (Org, error)

CreateOrgWithoutOwner inserts an organization nobody owns yet: one that mirrors a GitHub organization, whose members come from GitHub.

func (Q) CreatePrincipal

func (q Q) CreatePrincipal(ctx context.Context, p Principal) (Principal, error)

CreatePrincipal inserts a principal. A person (KindHuman) also gets their personal organization, named like them and owned by them, in the same statement; SiteAdmin is only kept for people.

func (Q) CreateRepo

func (q Q) CreateRepo(ctx context.Context, r Repo) (Repo, error)

CreateRepo inserts a repo and its upstream. The repo belongs to r.OrgID; without one it goes to the "default" organization, created on demand (the service always sets OrgID; this keeps low-level callers working).

func (Q) CreateTeam added in v0.2.0

func (q Q) CreateTeam(ctx context.Context, org Org, name string) (Team, error)

CreateTeam inserts a team.

func (Q) CreateToken

func (q Q) CreateToken(ctx context.Context, principalID uuid.UUID, name string) (string, error)

CreateToken issues a new token for a principal and returns the secret. Only its hash is stored, so the secret cannot be shown again.

func (Q) CreateWorkspace

func (q Q) CreateWorkspace(ctx context.Context, w Workspace) (Workspace, error)

CreateWorkspace inserts an open workspace.

func (Q) DecideReview added in v0.4.0

func (q Q) DecideReview(ctx context.Context, id uuid.UUID, state ReviewState, by uuid.UUID, reason string, landed hash.Hash, at time.Time) (bool, error)

DecideReview moves a pending review to approved or rejected. It reports false when the review was not pending any more.

func (Q) DeleteCLILoginsBefore added in v0.2.0

func (q Q) DeleteCLILoginsBefore(ctx context.Context, t time.Time) error

DeleteCLILoginsBefore removes logins that expired before t.

func (Q) DeleteClosedOverlaps added in v0.3.0

func (q Q) DeleteClosedOverlaps(ctx context.Context, effortID uuid.UUID) error

DeleteClosedOverlaps removes the forecasts of an effort with efforts that are no longer open (or of the effort itself when it closed).

func (Q) DeleteGitHubInstallation added in v0.2.0

func (q Q) DeleteGitHubInstallation(ctx context.Context, id int64) error

DeleteGitHubInstallation forgets an installation (removed from GitHub). Its repositories stay linked to it, so they stay GitHub-backed and nobody but service principals and support grants has a role on them until they are linked again.

func (Q) DeleteInvite added in v0.2.0

func (q Q) DeleteInvite(ctx context.Context, login string) (ok bool, err error)

DeleteInvite withdraws an open invite; ok is false when there is none.

func (Q) DeleteOpsBefore added in v0.5.0

func (q Q) DeleteOpsBefore(ctx context.Context, t time.Time, batch int) (int64, error)

DeleteOpsBefore deletes up to batch operation log entries older than t and returns how many it deleted.

func (Q) DeleteOrgSSO added in v0.5.0

func (q Q) DeleteOrgSSO(ctx context.Context, org uuid.UUID) (bool, error)

DeleteOrgSSO removes an organization's configuration and the sign-on marks of its tokens.

func (Q) DeletePushSubscription added in v0.5.0

func (q Q) DeletePushSubscription(ctx context.Context, principalID uuid.UUID, endpoint string) (bool, error)

DeletePushSubscription removes a principal's subscription by endpoint; it reports whether one was there.

func (Q) DeletePushSubscriptionByID added in v0.5.0

func (q Q) DeletePushSubscriptionByID(ctx context.Context, id uuid.UUID) error

DeletePushSubscriptionByID removes a subscription the push service reported gone.

func (Q) DeleteRepoGrant added in v0.2.0

func (q Q) DeleteRepoGrant(ctx context.Context, repo uuid.UUID, principal, team *uuid.UUID) (string, error)

DeleteRepoGrant removes the grant to principal or team on repo and returns the role it had ("" when there was none).

func (Q) DeleteSupportGrant added in v0.5.0

func (q Q) DeleteSupportGrant(ctx context.Context, repo, person uuid.UUID) (SupportGrant, error)

DeleteSupportGrant removes person's support grant on repo and returns it (ErrNotFound when there is none).

func (Q) DeleteTeam added in v0.2.0

func (q Q) DeleteTeam(ctx context.Context, team uuid.UUID) error

DeleteTeam deletes a team, its members and its grants.

func (Q) DeletedOrgByHandle added in v0.6.0

func (q Q) DeletedOrgByHandle(ctx context.Context, handle string, forUpdate bool) (Org, error)

DeletedOrgByHandle returns a deleted organization that is not purged yet, locking it inside transactions (forUpdate).

func (Q) DeletedOrgGitHub added in v0.6.0

func (q Q) DeletedOrgGitHub(ctx context.Context, installationID, accountID int64) (string, bool, error)

DeletedOrgGitHub reports whether a deleted organization holds the GitHub installation installationID or the GitHub account accountID (0: do not check that), so syncing it stops.

func (Q) DeletedOrgsOwnedBy added in v0.6.0

func (q Q) DeletedOrgsOwnedBy(ctx context.Context, person uuid.UUID) ([]Org, []OrgDeletion, error)

DeletedOrgsOwnedBy lists the deleted, not yet purged organizations person owns, with their deletion records, soonest purge first.

func (Q) DropGitHubCache added in v0.2.0

func (q Q) DropGitHubCache(ctx context.Context, s GitHubCacheScope) (int64, error)

DropGitHubCache deletes the cached roles and memberships in scope and reports how many rows went.

func (Q) EffortByID

func (q Q) EffortByID(ctx context.Context, id uuid.UUID) (Effort, error)

EffortByID finds an effort by id.

func (Q) EnqueueCheckJob added in v0.7.0

func (q Q) EnqueueCheckJob(ctx context.Context, j CheckJob, now time.Time) (CheckJob, bool, error)

EnqueueCheckJob stores a job and supersedes the pending jobs of the same check and effort for other trees. When a pending job for the same check and tree exists, no new one is made: j's values are merged into it (new values win) and it comes back with created false. For triggers other than manual, any earlier job for the tree that was not superseded comes back unchanged instead.

func (Q) ExistingRepoIDs added in v0.6.0

func (q Q) ExistingRepoIDs(ctx context.Context, ids []uuid.UUID) (map[uuid.UUID]bool, error)

ExistingRepoIDs reports which of ids are repositories (of live or deleted organizations).

func (Q) FileChanges

func (q Q) FileChanges(ctx context.Context, repoID uuid.UUID, h hash.Hash) ([]FileChange, error)

FileChanges returns the recorded file list of a changeset.

func (Q) FinishCheckJobs added in v0.7.0

func (q Q) FinishCheckJobs(ctx context.Context, effortID uuid.UUID, check string, tree hash.Hash, resultID string, now time.Time) ([]CheckJob, error)

FinishCheckJobs marks the pending jobs of a check on a tree of an effort done with the result that finished them, and returns them.

func (Q) FinishObjectBackfill added in v0.2.0

func (q Q) FinishObjectBackfill(ctx context.Context, repoID uuid.UUID) error

FinishObjectBackfill removes the repo from the backfill queue.

func (Q) FinishWorkspace

func (q Q) FinishWorkspace(ctx context.Context, id uuid.UUID, state WorkspaceState, landedAs hash.Hash) error

FinishWorkspace marks a workspace landed (with its changeset) or abandoned.

func (Q) FinishedRebaseHeads added in v0.2.0

func (q Q) FinishedRebaseHeads(ctx context.Context, effortID uuid.UUID) ([]hash.Hash, error)

FinishedRebaseHeads returns, newest first, the old-chain heads of the effort's finished rebases: what open workspaces may still be based on.

func (Q) ForgetGitHubDelivery added in v0.2.0

func (q Q) ForgetGitHubDelivery(ctx context.Context, id string) error

ForgetGitHubDelivery removes a recorded delivery, so GitHub's redelivery of a delivery that failed to apply is applied.

func (Q) ForgetOrgSSOProofs added in v0.5.0

func (q Q) ForgetOrgSSOProofs(ctx context.Context, org uuid.UUID) error

ForgetOrgSSOProofs drops the sign-on marks of an organization's tokens, for example after its provider changed.

func (Q) GetBranch

func (q Q) GetBranch(ctx context.Context, repoID uuid.UUID, name string) (Branch, error)

GetBranch returns a tracked branch.

func (Q) GetChangeset

func (q Q) GetChangeset(ctx context.Context, repoID uuid.UUID, h hash.Hash) (ChangesetRow, error)

GetChangeset loads a changeset by hash.

func (Q) GetCheckResult added in v0.7.0

func (q Q) GetCheckResult(ctx context.Context, id uuid.UUID) (CheckResult, error)

GetCheckResult loads one check result with its artifacts.

func (Q) GetEffort

func (q Q) GetEffort(ctx context.Context, repoID uuid.UUID, slug string) (Effort, error)

GetEffort finds an effort by repo and slug.

func (Q) GetOrgQuota added in v0.5.0

func (q Q) GetOrgQuota(ctx context.Context, orgID uuid.UUID) (OrgQuota, error)

GetOrgQuota returns an organization's override; one without a row has every field nil.

func (Q) GetOverlap added in v0.3.0

func (q Q) GetOverlap(ctx context.Context, a, b uuid.UUID) (EffortOverlap, error)

GetOverlap loads the forecast of a pair, in either order.

func (Q) GetReview added in v0.4.0

func (q Q) GetReview(ctx context.Context, id uuid.UUID) (Review, error)

GetReview loads a review by id.

func (Q) GetReviewForUpdate added in v0.4.0

func (q Q) GetReviewForUpdate(ctx context.Context, id uuid.UUID) (Review, error)

GetReviewForUpdate loads and locks a review (in a transaction).

func (Q) GetServerNotice added in v0.5.0

func (q Q) GetServerNotice(ctx context.Context, key string) (ServerNotice, error)

GetServerNotice reads a notice (ErrNotFound when the server never had it).

func (Q) GetUpstreamSecrets added in v0.4.0

func (q Q) GetUpstreamSecrets(ctx context.Context, repoID uuid.UUID) (UpstreamSecrets, error)

GetUpstreamSecrets returns the sealed token and webhook secret of a repository.

func (Q) GetWorkspace

func (q Q) GetWorkspace(ctx context.Context, id uuid.UUID) (Workspace, error)

GetWorkspace loads a workspace.

func (Q) GetWorkspaceForUpdate

func (q Q) GetWorkspaceForUpdate(ctx context.Context, id uuid.UUID) (Workspace, error)

GetWorkspaceForUpdate loads a workspace and locks its row until the transaction ends, so two lands of the same workspace cannot race.

func (Q) GitHashesFor

func (q Q) GitHashesFor(ctx context.Context, repoID uuid.UUID, vxHashes []hash.Hash) (map[hash.Hash]string, error)

GitHashesFor returns git hashes for vx objects (the reverse mapping).

func (Q) GitHubAccessFacts added in v0.2.0

func (q Q) GitHubAccessFacts(ctx context.Context, repo uuid.UUID, since time.Time) ([]AccessFact, error)

GitHubAccessFacts is RepoAccessFacts for a GitHub-backed repository: the roles GitHub reported for people checked since since (via "GitHub"), and direct grants of service principals, by handle. Support grants are listed by ListSupportGrants.

func (Q) GitHubApp added in v0.2.0

func (q Q) GitHubApp(ctx context.Context) (GitHubApp, error)

GitHubApp returns the server's GitHub App, or ErrNotFound.

func (Q) GitHubAppGaps added in v0.4.0

func (q Q) GitHubAppGaps(ctx context.Context) ([]GitHubAppGap, error)

GitHubAppGaps lists the recorded gaps.

func (Q) GitHubBackedRepos added in v0.2.0

func (q Q) GitHubBackedRepos(ctx context.Context, installations []int64, org *uuid.UUID) ([]Repo, error)

GitHubBackedRepos returns the GitHub-backed repositories of the given installations, by name; org limits them to one organization.

func (Q) GitHubCheckRuns added in v0.7.0

func (q Q) GitHubCheckRuns(ctx context.Context, shipment uuid.UUID, headSHA string) ([]GitHubCheckRunRow, error)

GitHubCheckRuns lists the check runs of a shipment's head.

func (Q) GitHubInstallationByID added in v0.2.0

func (q Q) GitHubInstallationByID(ctx context.Context, id int64) (GitHubInstallationRow, error)

GitHubInstallationByID returns one installation.

func (Q) GitHubLinkOf added in v0.2.0

func (q Q) GitHubLinkOf(ctx context.Context, principalID uuid.UUID) (GitHubLink, bool, error)

GitHubLinkOf returns the GitHub account linked to a principal; ok is false when there is none.

func (Q) GitHubLinksOf added in v0.2.0

func (q Q) GitHubLinksOf(ctx context.Context, ids []uuid.UUID) (map[uuid.UUID]GitHubLink, error)

GitHubLinksOf returns the GitHub accounts linked to any of ids, by principal id; principals without one are left out.

func (Q) GitHubMembershipCache added in v0.2.0

func (q Q) GitHubMembershipCache(ctx context.Context, principal uuid.UUID) (map[int64]CachedRole, error)

GitHubMembershipCache returns principal's cached memberships in GitHub organizations, by GitHub organization id.

func (Q) GitHubRoleCache added in v0.2.0

func (q Q) GitHubRoleCache(ctx context.Context, principal uuid.UUID, repos []uuid.UUID) (map[uuid.UUID]CachedRole, error)

GitHubRoleCache returns principal's cached roles on repos, by repo id. Repositories without a cached role are missing from the map.

func (Q) HandleTaken added in v0.2.0

func (q Q) HandleTaken(ctx context.Context, handle string) (bool, error)

HandleTaken reports whether a handle is used by a principal or an organization (people's handles and organization handles share one space).

func (Q) IdentitiesOf added in v0.5.0

func (q Q) IdentitiesOf(ctx context.Context, person uuid.UUID) ([]Identity, error)

IdentitiesOf lists a person's identities, by issuer.

func (Q) InitPushKey added in v0.5.0

func (q Q) InitPushKey(ctx context.Context, k PushKey) (PushKey, error)

InitPushKey stores k unless a key exists, and returns the stored one: two servers making a key at once agree on the first.

func (Q) InsertCIToken added in v0.7.0

func (q Q) InsertCIToken(ctx context.Context, t CIToken) (CIToken, error)

InsertCIToken stores a CI token record.

func (Q) InsertChangeset

func (q Q) InsertChangeset(ctx context.Context, repoID uuid.UUID, effortID *uuid.UUID, cs *object.Changeset, files []FileChange) (hash.Hash, error)

InsertChangeset stores a changeset and its file list. Inserting the same changeset twice is a no-op, which makes imports safe to repeat.

func (Q) InsertCheckResult added in v0.7.0

func (q Q) InsertCheckResult(ctx context.Context, r CheckResult) (CheckResult, error)

InsertCheckResult stores r and its artifacts and returns it as stored (id and created_at set). Run it in a transaction so the artifacts are stored with it.

func (Q) InsertClaim added in v0.2.0

func (q Q) InsertClaim(ctx context.Context, c Claim) (Claim, error)

InsertClaim stores a claim. A zero ID gets a new one; a zero CreatedAt means now. The repo is taken from the effort.

func (Q) InsertNote added in v0.2.0

func (q Q) InsertNote(ctx context.Context, n Note) (Note, error)

InsertNote stores a note. A zero ID gets a new one; a zero ThreadID makes the note a thread root; a zero CreatedAt means now. The repo is taken from the effort. Supersedes, System and SimilarTo are stored as given; SupersededBy and Similar are ignored.

func (Q) InsertReservation added in v0.3.0

func (q Q) InsertReservation(ctx context.Context, repoID uuid.UUID, rule, value string, effortID, by *uuid.UUID) (bool, error)

InsertReservation records value for rule. It reports false, and no error, when that value is already reserved (another call won).

func (Q) InsertTask added in v0.2.0

func (q Q) InsertTask(ctx context.Context, t Task) (Task, error)

InsertTask stores a task. A zero ID gets a new one, an empty State is open and a zero CreatedAt means now. The repo is taken from the effort. Dependencies are added separately with AddTaskDeps.

func (Q) IssueToken added in v0.2.0

func (q Q) IssueToken(ctx context.Context, principalID uuid.UUID, name string) (Token, string, error)

IssueToken is CreateToken that also returns the new token's record.

func (Q) KeepMovingClaims added in v0.5.0

func (q Q) KeepMovingClaims(ctx context.Context, workspaceID uuid.UUID, until time.Time) error

KeepMovingClaims detaches the active moving claims of a workspace that lands from it, so they outlive the land, and keeps them until at least until.

func (Q) LapseIdleClaims added in v0.5.0

func (q Q) LapseIdleClaims(ctx context.Context, effortID uuid.UUID, now, idleSince time.Time) ([]Claim, error)

LapseIdleClaims releases, at now, the claims of an effort that are alive only because their workspace is open (past their own expiry) while that workspace has done nothing since idleSince, and returns them.

func (Q) LatestRebase added in v0.2.0

func (q Q) LatestRebase(ctx context.Context, effortID uuid.UUID) (Rebase, error)

LatestRebase returns the effort's newest rebase in any state.

func (Q) LearnShipmentPR added in v0.4.0

func (q Q) LearnShipmentPR(ctx context.Context, id uuid.UUID, number, url string) error

LearnShipmentPR records the pull request number (and its URL, when the shipment has none) of a shipment pushed without one: a person opened the pull request on the host from vx's branch.

func (Q) LeaseCheckJob added in v0.7.0

func (q Q) LeaseCheckJob(ctx context.Context, id, owner uuid.UUID, now, expires time.Time) (CheckJob, error)

LeaseCheckJob gives a queued job to owner until expires.

func (Q) LinkGitHub added in v0.2.0

func (q Q) LinkGitHub(ctx context.Context, principalID uuid.UUID, githubUserID int64, login string) error

LinkGitHub links a person to a GitHub account, or updates the login of the account they are already linked to. It returns ErrExists when that GitHub account is linked to someone else.

func (Q) LinkIdentity added in v0.5.0

func (q Q) LinkIdentity(ctx context.Context, person uuid.UUID, issuer, subject, email string) error

LinkIdentity links (issuer, subject) to a person. ErrExists: the identity belongs to someone, or the person has another identity at this issuer.

func (Q) ListActorOps added in v0.2.0

func (q Q) ListActorOps(ctx context.Context, actorID uuid.UUID, limit int) ([]Op, error)

ListActorOps returns the newest operations a principal performed, in any repo or none (agent creation, token revocation).

func (Q) ListAgents

func (q Q) ListAgents(ctx context.Context, owner uuid.UUID) ([]Principal, error)

ListAgents returns the agents acting for owner.

func (Q) ListAudit added in v0.5.0

func (q Q) ListAudit(ctx context.Context, f AuditFilter) ([]AuditEntry, error)

ListAudit returns entries matching f, oldest first (newest with Desc).

func (Q) ListBranches

func (q Q) ListBranches(ctx context.Context, repoID uuid.UUID) ([]Branch, error)

ListBranches returns the tracked branches of a repo.

func (Q) ListCITokens added in v0.7.0

func (q Q) ListCITokens(ctx context.Context, repoID uuid.UUID, withRevoked bool) ([]CIToken, error)

ListCITokens returns a repository's CI tokens, active ones first.

func (Q) ListChangesetTrees added in v0.2.0

func (q Q) ListChangesetTrees(ctx context.Context, repoID uuid.UUID) ([]ChangesetTrees, error)

ListChangesetTrees returns the trees of every changeset in the repo, in the order they were created.

func (Q) ListCheckJobs added in v0.7.0

func (q Q) ListCheckJobs(ctx context.Context, f CheckJobFilter) ([]CheckJob, error)

ListCheckJobs returns jobs, pending ones first, then newest first.

func (Q) ListCheckResults added in v0.7.0

func (q Q) ListCheckResults(ctx context.Context, f CheckResultFilter) ([]CheckResult, error)

ListCheckResults returns check results, newest first, with their artifacts.

func (Q) ListEffortOverlaps added in v0.3.0

func (q Q) ListEffortOverlaps(ctx context.Context, effortID uuid.UUID) ([]EffortOverlap, error)

ListEffortOverlaps returns the stored forecasts of an effort with every other effort that is still open, oldest pair first.

func (Q) ListEfforts

func (q Q) ListEfforts(ctx context.Context, repoID uuid.UUID, state EffortState) ([]Effort, error)

ListEfforts lists a repo's efforts, newest first. An empty state lists all.

func (Q) ListGitHubInstallations added in v0.2.0

func (q Q) ListGitHubInstallations(ctx context.Context) ([]GitHubInstallationRow, error)

ListGitHubInstallations returns every installation, by account login.

func (Q) ListInvites added in v0.2.0

func (q Q) ListInvites(ctx context.Context, all bool) ([]SignupInvite, error)

ListInvites returns invites newest first; open ones only unless all.

func (Q) ListNotes added in v0.2.0

func (q Q) ListNotes(ctx context.Context, f NoteFilter) ([]Note, error)

ListNotes lists an effort's notes, newest first.

func (Q) ListOps

func (q Q) ListOps(ctx context.Context, repoID uuid.UUID, limit int) ([]Op, error)

ListOps returns a repo's newest operations first.

func (Q) ListOrgMembers added in v0.2.0

func (q Q) ListOrgMembers(ctx context.Context, org uuid.UUID) ([]OrgMember, error)

ListOrgMembers returns org's members by handle.

func (Q) ListOrgs added in v0.2.0

func (q Q) ListOrgs(ctx context.Context, person uuid.UUID, all bool) ([]OrgWithRole, error)

ListOrgs returns every organization (all) or those person is a member of, with person's role, by handle. Deleted organizations are left out.

func (Q) ListPeople added in v0.2.0

func (q Q) ListPeople(ctx context.Context) ([]Principal, error)

ListPeople returns every person (KindHuman) by handle.

func (Q) ListRepoGrants added in v0.2.0

func (q Q) ListRepoGrants(ctx context.Context, repo uuid.UUID) ([]RepoGrant, error)

ListRepoGrants returns repo's direct grants: principals first by handle, then teams by name.

func (Q) ListRepoOverlaps added in v0.3.0

func (q Q) ListRepoOverlaps(ctx context.Context, repoID uuid.UUID) ([]EffortOverlap, error)

ListRepoOverlaps returns the stored forecasts of every pair of open efforts of a repository.

func (Q) ListRepoRoleFacts added in v0.2.0

func (q Q) ListRepoRoleFacts(ctx context.Context, principal uuid.UUID, directOnly bool, org *uuid.UUID, at time.Time) ([]Repo, []RoleFacts, error)

ListRepoRoleFacts returns every repository with what principal's role on it is computed from, by name. Callers filter out what it cannot read.

func (Q) ListRepos

func (q Q) ListRepos(ctx context.Context) ([]Repo, error)

ListRepos returns all repos by name.

func (Q) ListReservations added in v0.3.0

func (q Q) ListReservations(ctx context.Context, repoID uuid.UUID, rule string) ([]Reservation, error)

ListReservations lists a repository's reservations, newest first; an empty rule lists every rule's.

func (Q) ListReviews added in v0.4.0

func (q Q) ListReviews(ctx context.Context, f ReviewFilter) ([]Review, error)

ListReviews returns reviews, newest first.

func (Q) ListShipments

func (q Q) ListShipments(ctx context.Context, effortID uuid.UUID) ([]Shipment, error)

ListShipments returns an effort's shipments with their changes: oldest first, the parts of a split in part order.

func (Q) ListSupportGrants added in v0.5.0

func (q Q) ListSupportGrants(ctx context.Context, repo uuid.UUID, at time.Time) ([]SupportGrant, error)

ListSupportGrants returns repo's support grants unexpired at at, by handle. Grants to people who are no longer superadmins are left out: they give no role.

func (Q) ListTargetOps added in v0.5.0

func (q Q) ListTargetOps(ctx context.Context, target string, limit int) ([]Op, error)

ListTargetOps returns the newest operations on one target ("user:alice", "github:octocat"), whoever performed them; console operations have no actor.

func (Q) ListTasks added in v0.2.0

func (q Q) ListTasks(ctx context.Context, f TaskFilter) ([]Task, error)

ListTasks lists an effort's tasks: not done first, then by creation.

func (Q) ListTeams added in v0.2.0

func (q Q) ListTeams(ctx context.Context, org Org) ([]Team, error)

ListTeams returns org's teams with their members, by name.

func (Q) ListTokens added in v0.2.0

func (q Q) ListTokens(ctx context.Context, principalIDs ...uuid.UUID) ([]Token, error)

ListTokens returns the tokens of the given principals, active ones first, then newest first.

func (Q) ListWorkspaces

func (q Q) ListWorkspaces(ctx context.Context, effortID uuid.UUID, state WorkspaceState) ([]Workspace, error)

ListWorkspaces lists an effort's workspaces. An empty state lists all.

func (Q) LockOrg added in v0.2.0

func (q Q) LockOrg(ctx context.Context, handle string) (Org, error)

LockOrg looks an organization up and locks it until the transaction ends, so membership checks such as "the last owner stays" cannot race.

func (Q) LockOverlapPair added in v0.3.0

func (q Q) LockOverlapPair(ctx context.Context, a, b uuid.UUID) error

LockOverlapPair serializes writers of one pair's forecast and notes until the transaction ends, also across servers.

func (Q) LockPrincipal added in v0.4.0

func (q Q) LockPrincipal(ctx context.Context, id uuid.UUID) error

LockPrincipal locks a principal's row until the transaction ends, so checks of its budgets and the writes they guard happen one at a time.

func (Q) LockSystemNoteKey added in v0.4.0

func (q Q) LockSystemNoteKey(ctx context.Context, effortID uuid.UUID, key string) error

LockSystemNoteKey serializes writers of one key until the transaction ends (two deliveries of the same CI result at once post one note).

func (Q) LogOp

func (q Q) LogOp(ctx context.Context, repoID, actorID *uuid.UUID, op, target string, before, after any) error

LogOp appends to the operation log. before and after are marshaled to JSON.

func (Q) LoginCodeToken added in v0.5.0

func (q Q) LoginCodeToken(ctx context.Context, codeHash []byte) (uuid.UUID, error)

LoginCodeToken is the token that asked for a sign-in code (uuid.Nil when none is known or the code does not exist).

func (Q) LookupGitObjects

func (q Q) LookupGitObjects(ctx context.Context, repoID uuid.UUID, gitHashes []string) (map[string]hash.Hash, error)

LookupGitObjects returns the vx hashes known for the given git hashes.

func (Q) MarkNoteAnswered added in v0.2.0

func (q Q) MarkNoteAnswered(ctx context.Context, id uuid.UUID) error

MarkNoteAnswered marks a question answered.

func (Q) MarkNotesRead added in v0.3.0

func (q Q) MarkNotesRead(ctx context.Context, principal uuid.UUID, ids []uuid.UUID) error

MarkNotesRead records that principal was shown the notes. Ids of notes that do not exist are skipped; marking a note twice keeps the first time.

func (Q) MarkOrgDeleted added in v0.6.0

func (q Q) MarkOrgDeleted(ctx context.Context, org Org, by Principal, at, purgeAfter time.Time) (OrgDeletion, error)

MarkOrgDeleted hides an organization from now on and records its deletion. It fails with ErrNotFound when the organization is already deleted.

func (Q) MarkPushResult added in v0.5.0

func (q Q) MarkPushResult(ctx context.Context, id uuid.UUID, at time.Time, failure string) error

MarkPushResult records the outcome of a send: when it went out, or why it did not.

func (Q) MarkServerNoticeLogged added in v0.5.0

func (q Q) MarkServerNoticeLogged(ctx context.Context, key string) (bool, error)

MarkServerNoticeLogged records that the server logged a notice. It reports whether this call was the first to do so.

func (Q) MarkTokenSSO added in v0.5.0

func (q Q) MarkTokenSSO(ctx context.Context, token, org uuid.UUID) error

MarkTokenSSO records that token was issued through org's sign-on.

func (Q) MergePeople added in v0.5.0

func (q Q) MergePeople(ctx context.Context, keep, merged uuid.UUID) (MergeStats, error)

MergePeople moves everything that lets merged act to keep: tokens, agents (keeping their handles, so authorship stays readable), organization and team memberships (the higher role wins), repository grants (the higher role wins), identities and, when keep has none, the GitHub link. merged stays as a disabled principal so changes, notes and the op log still name them. Run it in a transaction.

func (Q) MergedPeople added in v0.5.0

func (q Q) MergedPeople(ctx context.Context) (map[uuid.UUID]uuid.UUID, error)

MergedPeople maps each merged person to the person they were merged into.

func (Q) NoteByID added in v0.2.0

func (q Q) NoteByID(ctx context.Context, id uuid.UUID) (Note, error)

NoteByID loads a note.

func (Q) NoteByPrefix added in v0.2.0

func (q Q) NoteByPrefix(ctx context.Context, prefix string) (Note, error)

NoteByPrefix finds the one note whose id starts with prefix (lowercase hex and dashes). It returns ErrNotFound or ErrAmbiguous otherwise.

func (Q) NoteForUpdate added in v0.2.0

func (q Q) NoteForUpdate(ctx context.Context, id uuid.UUID) (Note, error)

NoteForUpdate loads a note and locks its row until the transaction ends.

func (Q) NoteRepos added in v0.3.0

func (q Q) NoteRepos(ctx context.Context, ids []uuid.UUID) (map[uuid.UUID]uuid.UUID, error)

NoteRepos returns the repository of each of the notes that exist.

func (Q) NotesRead added in v0.3.0

func (q Q) NotesRead(ctx context.Context, principal uuid.UUID, ids []uuid.UUID) (map[uuid.UUID]bool, error)

NotesRead returns which of the notes principal has seen.

func (Q) ObjectBackfillPending added in v0.2.0

func (q Q) ObjectBackfillPending(ctx context.Context, repoID uuid.UUID) (bool, error)

ObjectBackfillPending reports whether the repo still waits for a backfill.

func (Q) ObjectBackfillQueue added in v0.2.0

func (q Q) ObjectBackfillQueue(ctx context.Context) ([]uuid.UUID, error)

ObjectBackfillQueue lists the repos waiting for a backfill, oldest first.

func (Q) ObjectSizesKnown added in v0.5.0

func (q Q) ObjectSizesKnown(ctx context.Context, hs []hash.Hash) (map[hash.Hash]bool, error)

ObjectSizesKnown tells which of hs have a recorded size.

func (Q) ObjectsWithoutSize added in v0.5.0

func (q Q) ObjectsWithoutSize(ctx context.Context, limit int) ([]hash.Hash, error)

ObjectsWithoutSize returns up to limit objects that are part of some repository but have no recorded size yet.

func (Q) OnChain

func (q Q) OnChain(ctx context.Context, repoID uuid.UUID, head, target hash.Hash, limit int) (bool, error)

OnChain reports whether target is head or one of its first-parent ancestors, looking back at most limit steps.

func (Q) OpenEffortsOwnedBy added in v0.5.0

func (q Q) OpenEffortsOwnedBy(ctx context.Context, owners []uuid.UUID, limit int) ([]Effort, error)

OpenEffortsOwnedBy lists the open and shipping efforts the principals own, most recently updated first, across repositories (the For you page; callers filter by what the viewer may read).

func (Q) OpenInvite added in v0.2.0

func (q Q) OpenInvite(ctx context.Context, login string) (SignupInvite, bool, error)

OpenInvite returns the open invite for login; ok is false when there is none.

func (Q) OpenQuestionsCopiedTo added in v0.5.0

func (q Q) OpenQuestionsCopiedTo(ctx context.Context, person uuid.UUID, limit int) ([]Note, error)

OpenQuestionsCopiedTo returns open questions copied to person (their agent was not working when they were asked), newest first.

func (Q) OpenQuestionsIn added in v0.7.0

func (q Q) OpenQuestionsIn(ctx context.Context, effortID uuid.UUID, limit int) ([]Note, error)

OpenQuestionsIn returns the effort's open questions (overdue ones included), newest first.

func (Q) OpenQuestionsTo added in v0.2.0

func (q Q) OpenQuestionsTo(ctx context.Context, to []uuid.UUID, limit int) ([]Note, error)

OpenQuestionsTo returns open questions (overdue ones included) addressed to any of the principals, newest first.

func (Q) OpenWorkspacesOf added in v0.4.0

func (q Q) OpenWorkspacesOf(ctx context.Context, owner uuid.UUID) ([]Workspace, error)

OpenWorkspacesOf lists the open workspaces a principal owns in open efforts, oldest first.

func (Q) OrgAgreementByID added in v0.6.0

func (q Q) OrgAgreementByID(ctx context.Context, org, id uuid.UUID) (OrgAgreement, error)

OrgAgreementByID returns one acceptance of an organization.

func (Q) OrgAgreements added in v0.6.0

func (q Q) OrgAgreements(ctx context.Context, org uuid.UUID) ([]OrgAgreement, error)

OrgAgreements lists an organization's acceptances, newest first.

func (Q) OrgAgreementsOf added in v0.6.0

func (q Q) OrgAgreementsOf(ctx context.Context, orgs []uuid.UUID) ([]OrgAgreement, error)

OrgAgreementsOf lists the acceptances of several organizations, newest first, for the banner and notifications.

func (Q) OrgByGitHubID added in v0.2.0

func (q Q) OrgByGitHubID(ctx context.Context, githubOrgID int64) (Org, error)

OrgByGitHubID looks up the organization linked to a GitHub organization.

func (Q) OrgByHandle added in v0.2.0

func (q Q) OrgByHandle(ctx context.Context, handle string) (Org, error)

OrgByHandle looks an organization up by handle. Deleted organizations are not found (DeletedOrgByHandle reads them).

func (Q) OrgByID added in v0.5.0

func (q Q) OrgByID(ctx context.Context, id uuid.UUID) (Org, error)

OrgByID looks an organization up by id; deleted ones are not found.

func (Q) OrgCheckHistory added in v0.7.0

func (q Q) OrgCheckHistory(ctx context.Context, org uuid.UUID, limit int) ([]OrgCheckVersion, error)

OrgCheckHistory lists an organization's versions, newest first, at most limit (0: all).

func (Q) OrgChecks added in v0.7.0

func (q Q) OrgChecks(ctx context.Context, org uuid.UUID) (OrgCheckVersion, bool, error)

OrgChecks returns the newest version of an organization's checks; ok is false when it never defined any.

func (Q) OrgDeletionByID added in v0.6.0

func (q Q) OrgDeletionByID(ctx context.Context, orgID uuid.UUID) (OrgDeletion, error)

OrgDeletionByID returns the deletion record of an organization.

func (Q) OrgDeletionsByHandle added in v0.6.0

func (q Q) OrgDeletionsByHandle(ctx context.Context, handle string) ([]OrgDeletion, error)

OrgDeletionsByHandle returns the deletion records of organizations that had handle, newest first (a handle is free again after a purge, so it may have been deleted more than once).

func (Q) OrgObjectHashes added in v0.6.0

func (q Q) OrgObjectHashes(ctx context.Context, orgID uuid.UUID) (own, shared []hash.Hash, err error)

OrgObjectHashes returns the hashes of the objects an organization's repositories record: those no other repository records (a purge deletes them) and those another repository records too (they stay).

func (Q) OrgRecordIDs added in v0.6.0

func (q Q) OrgRecordIDs(ctx context.Context, orgID uuid.UUID) ([]uuid.UUID, error)

OrgRecordIDs returns the ids of an organization and of every record in it: its repositories, teams, and the rows of every table with an id column that belong to one of its repositories (a repo_id column) or efforts (an effort_id column). It walks the schema, so tables added later are included; with PurgeLeftovers it checks a purge.

func (Q) OrgRole added in v0.2.0

func (q Q) OrgRole(ctx context.Context, org, person uuid.UUID) (string, error)

OrgRole returns person's role in org, or "" when they are not a member.

func (Q) OrgSSOOf added in v0.5.0

func (q Q) OrgSSOOf(ctx context.Context, org uuid.UUID) (OrgSSO, bool, error)

OrgSSOOf returns an organization's configuration; ok is false without one.

func (Q) OrgStoredBytes added in v0.5.0

func (q Q) OrgStoredBytes(ctx context.Context, orgID uuid.UUID) (int64, error)

OrgStoredBytes is the blob store bytes of the objects of the organization's repositories, each object counted once even when several of its repositories use it. Objects whose size is not recorded yet count 0.

func (Q) OrgUsage added in v0.5.0

func (q Q) OrgUsage(ctx context.Context, orgID uuid.UUID) (repos, openEfforts int64, err error)

OrgUsage counts what an organization uses: its repositories and its efforts that are open or shipping. Counts only, never names.

func (Q) OrgsBySSODomain added in v0.5.0

func (q Q) OrgsBySSODomain(ctx context.Context, domain string) ([]Org, error)

OrgsBySSODomain lists the organizations whose sign-on allows email domain, with their handles.

func (Q) OrgsDueForPurge added in v0.6.0

func (q Q) OrgsDueForPurge(ctx context.Context, at time.Time) ([]uuid.UUID, error)

OrgsDueForPurge returns the ids of deleted organizations whose grace period ended by at, and of purges that started and did not finish, oldest first.

func (Q) OrgsWithRepos added in v0.6.0

func (q Q) OrgsWithRepos(ctx context.Context, orgs []uuid.UUID) (map[uuid.UUID]bool, error)

OrgsWithRepos reports which of orgs have at least one repository.

func (Q) OverdueQuestions added in v0.2.0

func (q Q) OverdueQuestions(ctx context.Context, owner uuid.UUID, to []uuid.UUID, now time.Time, limit int) ([]Note, error)

OverdueQuestions returns open questions whose deadline is before now and that are either in an effort owned by owner or addressed to one of to, newest first.

func (Q) OverlapCounts added in v0.3.0

func (q Q) OverlapCounts(ctx context.Context, repoID uuid.UUID) (map[uuid.UUID][2]int, error)

OverlapCounts returns, for each open effort of a repository, how many other open efforts it overlaps or conflicts with (clean pairs are not counted), and how many of those conflict.

func (Q) PeekLoginCode added in v0.5.0

func (q Q) PeekLoginCode(ctx context.Context, codeHash []byte, now time.Time) (uuid.UUID, error)

PeekLoginCode returns who an unexpired code signs in, or ErrNotFound.

func (Q) PendingBackfillsOutside added in v0.6.0

func (q Q) PendingBackfillsOutside(ctx context.Context, repos []uuid.UUID) (int64, error)

PendingBackfillsOutside reports whether a repository other than the given ones waits for its object backfill: until it is indexed, the objects it uses are not in repo_objects, so no blob may be deleted.

func (Q) PendingReviewOf added in v0.4.0

func (q Q) PendingReviewOf(ctx context.Context, workspace uuid.UUID) (Review, error)

PendingReviewOf returns the workspace's pending review.

func (Q) PeopleByEmail added in v0.5.0

func (q Q) PeopleByEmail(ctx context.Context, email string) ([]Principal, error)

PeopleByEmail lists the people (enabled ones) whose email is email, ignoring case.

func (Q) PersonByIdentity added in v0.5.0

func (q Q) PersonByIdentity(ctx context.Context, issuer, subject string) (Principal, error)

PersonByIdentity finds the person linked to (issuer, subject).

func (Q) PrincipalByGitHubID added in v0.2.0

func (q Q) PrincipalByGitHubID(ctx context.Context, githubUserID int64) (Principal, error)

PrincipalByGitHubID looks a person up by their GitHub user id.

func (Q) PrincipalByGitHubLogin added in v0.2.0

func (q Q) PrincipalByGitHubLogin(ctx context.Context, login string) (Principal, error)

PrincipalByGitHubLogin looks a person up by the GitHub login last seen for them, ignoring case. Logins can be renamed: use it for display and invites, never to sign someone in.

func (Q) PrincipalByHandle

func (q Q) PrincipalByHandle(ctx context.Context, handle string) (Principal, error)

PrincipalByHandle looks a principal up by handle.

func (Q) PrincipalByID

func (q Q) PrincipalByID(ctx context.Context, id uuid.UUID) (Principal, error)

PrincipalByID looks a principal up by id.

func (Q) PrincipalDisabled added in v0.5.0

func (q Q) PrincipalDisabled(ctx context.Context, id uuid.UUID) (disabled bool, into *uuid.UUID, err error)

PrincipalDisabled reports whether a principal was disabled (merged into another) and into whom.

func (Q) PruneBlobDeletions added in v0.6.0

func (q Q) PruneBlobDeletions(ctx context.Context, keep time.Duration) error

PruneBlobDeletions forgets marks of blobs deleted more than keep ago.

func (Q) PrunePushSent added in v0.5.0

func (q Q) PrunePushSent(ctx context.Context, before time.Time) error

PrunePushSent forgets pushes older than before: the items they were about are long decided or answered.

func (Q) PurgeLeftovers added in v0.6.0

func (q Q) PurgeLeftovers(ctx context.Context, ids []uuid.UUID, hashes [][]byte) ([]string, error)

PurgeLeftovers walks every table and lists the columns that still hold any of ids (in uuid, uuid[], text and jsonb columns) or hashes (in bytea columns), as "table.column (N rows)". After a purge, with the ids of the organization and of everything that was in it, it must be empty; tests use it so that tables added later are checked too. Not walked: the deletion record (org_deletions), the lifecycle entries of the operation log (org.delete, org.restore, org.purge) and the marks of deleted blobs (blob_deletions, kept a day; hashes, not content).

func (Q) PushKey added in v0.5.0

func (q Q) PushKey(ctx context.Context) (PushKey, error)

PushKey returns the server's VAPID key, or ErrNotFound before the first one is made.

func (Q) PushRecipients added in v0.5.0

func (q Q) PushRecipients(ctx context.Context) ([]uuid.UUID, error)

PushRecipients lists the principals with at least one subscription.

func (Q) PushSubscriptions added in v0.5.0

func (q Q) PushSubscriptions(ctx context.Context, principalID uuid.UUID) ([]PushSubscription, error)

PushSubscriptions lists a principal's subscriptions, oldest first.

func (Q) PutGitHubApp added in v0.2.0

func (q Q) PutGitHubApp(ctx context.Context, a GitHubApp) error

PutGitHubApp stores the server's GitHub App, replacing an earlier one.

func (Q) PutGitHubMembership added in v0.2.0

func (q Q) PutGitHubMembership(ctx context.Context, githubOrgID int64, principal uuid.UUID, role string, checkedAt time.Time) error

PutGitHubMembership caches principal's membership in a GitHub organization ("" for none).

func (Q) PutGitHubRole added in v0.2.0

func (q Q) PutGitHubRole(ctx context.Context, repo, principal uuid.UUID, role string, checkedAt time.Time) error

PutGitHubRole caches principal's role on repo ("" for none).

func (Q) PutOrgSSO added in v0.5.0

func (q Q) PutOrgSSO(ctx context.Context, c OrgSSO) (OrgSSO, error)

PutOrgSSO creates or replaces an organization's configuration.

func (Q) PutShipmentCheck added in v0.4.0

func (q Q) PutShipmentCheck(ctx context.Context, c ShipmentCheck) error

PutShipmentCheck records the latest report of one check.

func (Q) PutSystemNoteKey added in v0.4.0

func (q Q) PutSystemNoteKey(ctx context.Context, k SystemNoteKey) error

PutSystemNoteKey records the latest note on key.

func (Q) QueueObjectBackfill added in v0.2.0

func (q Q) QueueObjectBackfill(ctx context.Context, repoID uuid.UUID) error

QueueObjectBackfill queues one repo for a backfill.

func (Q) QueueObjectBackfills added in v0.2.0

func (q Q) QueueObjectBackfills(ctx context.Context) (int, error)

QueueObjectBackfills queues every repo that has changesets but no recorded objects, such as repos created by a server older than repo_objects. It returns how many were newly queued.

func (Q) QueuedCheckJobs added in v0.7.0

func (q Q) QueuedCheckJobs(ctx context.Context, repoIDs []uuid.UUID, effortID *uuid.UUID, runners []string, limit int) ([]CheckJob, error)

QueuedCheckJobs locks up to limit of the oldest queued jobs of the given repositories and runners, skipping rows another transaction holds (FOR UPDATE SKIP LOCKED), so servers taking jobs at once get different ones. Use it in a transaction and lease one of the rows before committing.

func (Q) QuotaOrg added in v0.5.0

func (q Q) QuotaOrg(ctx context.Context, id uuid.UUID) (Org, error)

QuotaOrg looks an organization up by id, for quota checks on its repositories.

func (Q) ReadableRepoIDs added in v0.2.0

func (q Q) ReadableRepoIDs(ctx context.Context, principal uuid.UUID, directOnly bool, at time.Time) ([]uuid.UUID, error)

ReadableRepoIDs returns the ids of the repositories principal can read through grants, teams and organization membership (directOnly: through direct grants only), and through support grants unexpired at at. Superadmins are not special here. GitHub-backed repositories are left out, except for directOnly (service principals keep their direct grants there) and support grants: roles on them come from GitHub, and the service adds them.

func (Q) ReapCheckJobs added in v0.7.0

func (q Q) ReapCheckJobs(ctx context.Context, now time.Time) (requeued, failed int, err error)

ReapCheckJobs puts the jobs whose lease expired before now back in the queue with the attempt counted, and fails those that used up their attempts. It returns how many it requeued and failed. Several servers may run it at once: each row is updated by one of them.

func (Q) RebaseEffort

func (q Q) RebaseEffort(ctx context.Context, id uuid.UUID, seenVersion int64, baseBranch string, newBase, newHead hash.Hash) (bool, error)

RebaseEffort moves the effort onto a new base branch, base and head, with the same compare-and-swap as AdvanceEffort.

func (Q) RecordGitHubDelivery added in v0.2.0

func (q Q) RecordGitHubDelivery(ctx context.Context, id, event string, keep time.Duration) (fresh bool, err error)

RecordGitHubDelivery records a webhook delivery id. fresh is false when the delivery was recorded before (a replay or redelivery). Deliveries older than keep are pruned on the way.

func (Q) RecordObjectSizes added in v0.5.0

func (q Q) RecordObjectSizes(ctx context.Context, sizes []ObjectSize) error

RecordObjectSizes stores object sizes; a size recorded before is kept (objects are immutable, so it cannot differ).

func (Q) ReleaseCheckJob added in v0.7.0

func (q Q) ReleaseCheckJob(ctx context.Context, id, owner uuid.UUID, now time.Time, reason string) (CheckJob, error)

ReleaseCheckJob puts owner's leased job back in the queue without counting an attempt.

func (Q) ReleaseClaim added in v0.2.0

func (q Q) ReleaseClaim(ctx context.Context, id uuid.UUID, now time.Time) (Claim, bool, error)

ReleaseClaim releases one claim if it is still active at now and returns it; ok is false when it was already released or expired.

func (Q) ReleaseWorkspaceClaims added in v0.2.0

func (q Q) ReleaseWorkspaceClaims(ctx context.Context, workspaceID uuid.UUID, owner *uuid.UUID, now time.Time) ([]Claim, error)

ReleaseWorkspaceClaims releases the claims tied to a workspace that are not released yet (they lasted as long as the workspace) and returns them. A non-nil owner releases only that principal's claims.

func (Q) RemoveOrgMember added in v0.2.0

func (q Q) RemoveOrgMember(ctx context.Context, org, person uuid.UUID) (bool, error)

RemoveOrgMember removes person from org and its teams. It reports whether they were a member.

func (Q) RemoveTeamMember added in v0.2.0

func (q Q) RemoveTeamMember(ctx context.Context, team, person uuid.UUID) (bool, error)

RemoveTeamMember removes person from team and reports whether they were in it.

func (Q) RenewCheckJob added in v0.7.0

func (q Q) RenewCheckJob(ctx context.Context, id, owner uuid.UUID, now, expires time.Time) (CheckJob, error)

RenewCheckJob moves the end of owner's lease on a job to expires.

func (Q) RepoAccessFacts added in v0.2.0

func (q Q) RepoAccessFacts(ctx context.Context, repo uuid.UUID) ([]AccessFact, error)

RepoAccessFacts returns every source of access to repo: organization owners and admins, the default role for members, direct grants and team grants. Support grants are listed by ListSupportGrants.

func (Q) RepoByGitHubID added in v0.2.0

func (q Q) RepoByGitHubID(ctx context.Context, githubRepoID int64) (Repo, error)

RepoByGitHubID looks a repo up by its GitHub repository id.

func (Q) RepoByID

func (q Q) RepoByID(ctx context.Context, id uuid.UUID) (Repo, error)

RepoByID looks a repo up by id.

func (Q) RepoByName

func (q Q) RepoByName(ctx context.Context, name string) (Repo, error)

RepoByName looks a repo up by name.

func (Q) RepoObjectsMissing added in v0.2.0

func (q Q) RepoObjectsMissing(ctx context.Context, repoID uuid.UUID, hashes []hash.Hash) ([]hash.Hash, error)

RepoObjectsMissing returns the hashes that are not part of the repo, in the order given. Objects stored only for other repos count as missing.

func (Q) RepoRoleFacts added in v0.2.0

func (q Q) RepoRoleFacts(ctx context.Context, name string, principal uuid.UUID, directOnly bool, at time.Time) (Repo, RoleFacts, error)

RepoRoleFacts looks up the repository named name together with what principal's role on it is computed from, in one query.

func (Q) RepoRoleFactsByID added in v0.2.0

func (q Q) RepoRoleFactsByID(ctx context.Context, id, principal uuid.UUID, directOnly bool, at time.Time) (Repo, RoleFacts, error)

RepoRoleFactsByID is RepoRoleFacts for a repository id.

func (Q) RepoStoredBytes added in v0.5.0

func (q Q) RepoStoredBytes(ctx context.Context, repoID uuid.UUID) (int64, error)

RepoStoredBytes is the blob store bytes of the repository's objects. Objects whose size is not recorded yet count 0.

func (Q) ReposByRemote added in v0.4.0

func (q Q) ReposByRemote(ctx context.Context, remote string, providers ...Provider) ([]Repo, error)

ReposByRemote lists the repositories following remote (compared without case) on one of providers, by name. Several vx repositories may follow the same upstream.

func (Q) ReposOfGitHubInstallation added in v0.2.0

func (q Q) ReposOfGitHubInstallation(ctx context.Context, installationID int64) ([]Repo, error)

ReposOfGitHubInstallation lists the repos linked to an installation.

func (Q) ResetObjectIndex added in v0.2.0

func (q Q) ResetObjectIndex(ctx context.Context, repoID uuid.UUID) error

ResetObjectIndex forgets which objects are part of the repo and queues it for a backfill, which rebuilds the index from its changesets. It is for repairs and for tests that recreate data from before repo_objects.

func (Q) ResolveChangeset

func (q Q) ResolveChangeset(ctx context.Context, repoID uuid.UUID, ref string) (ChangesetRow, error)

ResolveChangeset finds a changeset by full hash, hex prefix (at least 6 characters) or change ID.

func (Q) ResolveServerNotice added in v0.5.0

func (q Q) ResolveServerNotice(ctx context.Context, key string, by uuid.UUID) (bool, error)

ResolveServerNotice records that by reviewed a notice. It reports whether the notice was still open.

func (Q) RestoreDeletedOrg added in v0.6.0

func (q Q) RestoreDeletedOrg(ctx context.Context, orgID uuid.UUID) error

RestoreDeletedOrg brings a deleted organization back as it was and drops its deletion record. It fails with ErrPurgeStarted once a purge began.

func (Q) ReviewByPrefix added in v0.4.0

func (q Q) ReviewByPrefix(ctx context.Context, prefix string, repos []uuid.UUID) (Review, error)

ReviewByPrefix resolves a review id or a prefix of at least 8 hex characters among reviews of the given repositories (nil: any).

func (Q) RevokeCIToken added in v0.7.0

func (q Q) RevokeCIToken(ctx context.Context, repoID uuid.UUID, name string, now time.Time) (CIToken, error)

RevokeCIToken revokes a repository's active CI token by name, and its token.

func (Q) RevokeToken added in v0.2.0

func (q Q) RevokeToken(ctx context.Context, id uuid.UUID) (t Token, revoked bool, err error)

RevokeToken marks a token revoked and returns it. Revoking a token twice keeps the first revocation time; revoked reports whether this call did it.

func (Q) SSOBlocked added in v0.5.0

func (q Q) SSOBlocked(ctx context.Context, org, token uuid.UUID) (bool, error)

SSOBlocked reports whether org requires single sign-on and token was not issued through it.

func (Q) SaveGitHubCheckRun added in v0.7.0

func (q Q) SaveGitHubCheckRun(ctx context.Context, r GitHubCheckRunRow) error

SaveGitHubCheckRun records a check run vx created or updated.

func (Q) SaveGitObjects

func (q Q) SaveGitObjects(ctx context.Context, repoID uuid.UUID, objs []GitObject) error

SaveGitObjects records mappings; existing ones are kept.

func (Q) SaveOverlap added in v0.3.0

func (q Q) SaveOverlap(ctx context.Context, o EffortOverlap) error

SaveOverlap inserts or replaces a pair's forecast. EffortA and EffortB must be ordered (OrderPair).

func (Q) SavePushSubscription added in v0.5.0

func (q Q) SavePushSubscription(ctx context.Context, s PushSubscription) (PushSubscription, error)

SavePushSubscription adds a subscription, or updates the one with the same endpoint: a browser subscribes once, so the endpoint moves to whoever signed in on it last.

func (Q) SaveShipment

func (q Q) SaveShipment(ctx context.Context, s Shipment) (Shipment, error)

SaveShipment inserts a shipment or updates the one for the same effort and branch, replacing its change list.

func (Q) SetAgentRunnerKinds added in v0.7.0

func (q Q) SetAgentRunnerKinds(ctx context.Context, agentID uuid.UUID, kinds []string, by uuid.UUID, now time.Time) error

SetAgentRunnerKinds replaces the runner kinds of an agent.

func (Q) SetAgentScope added in v0.4.0

func (q Q) SetAgentScope(ctx context.Context, s AgentScope) error

SetAgentScope stores an agent's scope; an unlimited one removes the row.

func (Q) SetBranchIfUnchanged added in v0.5.0

func (q Q) SetBranchIfUnchanged(ctx context.Context, b Branch, fromSHA string, tracked bool) (bool, error)

SetBranchIfUnchanged moves a tracked branch to b only while it is still at git commit fromSHA, or, when it was not tracked (tracked false), only while it still is not. It reports whether it moved; false means another server moved the branch first. Imports use it so two servers syncing one branch at once never move it back to an older commit.

func (Q) SetCLILoginApprover added in v0.5.0

func (q Q) SetCLILoginApprover(ctx context.Context, deviceHash []byte, token uuid.UUID) error

SetCLILoginApprover records which token approved a CLI login.

func (Q) SetCLILoginStatus added in v0.2.0

func (q Q) SetCLILoginStatus(ctx context.Context, deviceHash []byte, from, to string, principalID *uuid.UUID, at time.Time) (bool, error)

SetCLILoginStatus moves a login from one status to another and reports whether it was in the from status. principalID is recorded when set.

func (Q) SetChangesetWarnings added in v0.2.0

func (q Q) SetChangesetWarnings(ctx context.Context, repoID uuid.UUID, h hash.Hash, ws []Warning) error

SetChangesetWarnings records the warnings found when a changeset landed. No warnings clears the column.

func (Q) SetDisplayName added in v0.2.0

func (q Q) SetDisplayName(ctx context.Context, principalID uuid.UUID, name string) error

SetDisplayName changes a principal's display name.

func (Q) SetEffortState

func (q Q) SetEffortState(ctx context.Context, id uuid.UUID, state EffortState) error

SetEffortState changes the lifecycle state.

func (Q) SetLoginCodeToken added in v0.5.0

func (q Q) SetLoginCodeToken(ctx context.Context, codeHash []byte, token uuid.UUID) error

SetLoginCodeToken records which token asked for a vx ui sign-in code.

func (Q) SetOrgGitHub added in v0.2.0

func (q Q) SetOrgGitHub(ctx context.Context, org uuid.UUID, githubOrgID *int64, login string) error

SetOrgGitHub links an organization to a GitHub organization (nil: unlink). Its membership then follows GitHub.

func (Q) SetOrgMember added in v0.2.0

func (q Q) SetOrgMember(ctx context.Context, org, person uuid.UUID, role string) error

SetOrgMember adds person to org with role, or changes their role.

func (Q) SetOrgQuota added in v0.5.0

func (q Q) SetOrgQuota(ctx context.Context, o OrgQuota) error

SetOrgQuota stores an override; an empty one deletes the row.

func (Q) SetPurgeStep added in v0.6.0

func (q Q) SetPurgeStep(ctx context.Context, orgID uuid.UUID, step string) error

SetPurgeStep records where a purge is.

func (Q) SetRepoGitHub added in v0.2.0

func (q Q) SetRepoGitHub(ctx context.Context, repo uuid.UUID, githubRepoID, installationID *int64) error

SetRepoGitHub links a repository to a GitHub repository through an installation of the App (both nil: unlink). A linked repository is GitHub-backed. Cached roles on it are dropped.

func (Q) SetRepoGrant added in v0.2.0

func (q Q) SetRepoGrant(ctx context.Context, repo uuid.UUID, principal, team *uuid.UUID, role string) (string, error)

SetRepoGrant grants principal or team (exactly one non-nil) role on repo, replacing an earlier grant to the same subject. It returns the previous role, or "".

func (Q) SetRepoUpstream added in v0.2.0

func (q Q) SetRepoUpstream(ctx context.Context, repoID uuid.UUID, remote, defaultBranch string) error

SetRepoUpstream changes a repo's remote and default branch, for example after the repository was renamed or transferred on GitHub.

func (Q) SetReviewConflicts added in v0.4.0

func (q Q) SetReviewConflicts(ctx context.Context, id uuid.UUID, paths []string, by uuid.UUID, at time.Time) error

SetReviewConflicts records that approving the review conflicted; it stays pending.

func (Q) SetShipmentCI added in v0.4.0

func (q Q) SetShipmentCI(ctx context.Context, c ShipmentCI) error

SetShipmentCI stores a shipment's CI result.

func (Q) SetShipmentState added in v0.4.0

func (q Q) SetShipmentState(ctx context.Context, id uuid.UUID, state string) error

SetShipmentState sets one shipment's state (a part of a split merged on its own, or left out of a newer split).

func (Q) SetSiteAdmin added in v0.2.0

func (q Q) SetSiteAdmin(ctx context.Context, person uuid.UUID, admin bool) error

SetSiteAdmin makes a person a superadmin (the site_admin column) or not.

func (Q) SetSupportGrant added in v0.5.0

func (q Q) SetSupportGrant(ctx context.Context, repo, person uuid.UUID, role string, expires time.Time, reason string, by *uuid.UUID) (*SupportGrant, error)

SetSupportGrant gives person role on repo until expires, replacing an earlier support grant to them. It returns the previous grant, if any.

func (Q) SetTaskState added in v0.2.0

func (q Q) SetTaskState(ctx context.Context, id uuid.UUID, state string, owner *uuid.UUID, now time.Time) error

SetTaskState changes a task's state and owner.

func (Q) SetUpstreamToken added in v0.4.0

func (q Q) SetUpstreamToken(ctx context.Context, repoID uuid.UUID, sealed []byte) error

SetUpstreamToken stores a sealed token for a repository; nil clears it.

func (Q) SetUpstreamWebhookSecret added in v0.4.0

func (q Q) SetUpstreamWebhookSecret(ctx context.Context, repoID uuid.UUID, sealed []byte) error

SetUpstreamWebhookSecret stores a sealed webhook secret; nil clears it.

func (Q) SetWelcomeDismissed added in v0.2.0

func (q Q) SetWelcomeDismissed(ctx context.Context, principalID uuid.UUID, dismissed bool) error

SetWelcomeDismissed dismisses the welcome page, or brings it back.

func (Q) SetWorkspaceBase

func (q Q) SetWorkspaceBase(ctx context.Context, id uuid.UUID, base hash.Hash) error

SetWorkspaceBase records the snapshot the workspace's files are based on.

func (Q) SetWorkspaceChangedPaths added in v0.3.0

func (q Q) SetWorkspaceChangedPaths(ctx context.Context, id uuid.UUID, paths []string, at time.Time) error

SetWorkspaceChangedPaths records the files an open workspace's working copy has changed.

func (Q) ShipmentByBranch added in v0.4.0

func (q Q) ShipmentByBranch(ctx context.Context, repoID uuid.UUID, branch string) (Shipment, error)

ShipmentByBranch returns the shipment of an effort in repoID pushed to branch, with its changes.

func (Q) ShipmentByPR added in v0.4.0

func (q Q) ShipmentByPR(ctx context.Context, repoID uuid.UUID, number, branch string) (ShipmentRef, error)

ShipmentByPR returns the newest shipment of the repository for a pull request: by its number on the host (provider_ref) when number is set, else, or when no shipment has that number, by its head branch.

func (Q) ShipmentCIs added in v0.4.0

func (q Q) ShipmentCIs(ctx context.Context, ids []uuid.UUID) (map[uuid.UUID]ShipmentCI, error)

ShipmentCIs returns the CI results of shipments, by shipment id; a shipment without one is missing.

func (Q) ShipmentChecks added in v0.4.0

func (q Q) ShipmentChecks(ctx context.Context, shipmentID uuid.UUID, sha string) ([]ShipmentCheck, error)

ShipmentChecks returns the checks reported for a shipment's commit, by name.

func (Q) ShipmentsByHeadSHA added in v0.4.0

func (q Q) ShipmentsByHeadSHA(ctx context.Context, repoID uuid.UUID, sha string) ([]ShipmentRef, error)

ShipmentsByHeadSHA returns the repository's shipments whose pushed head commit is sha, newest first.

func (Q) StartRebase added in v0.2.0

func (q Q) StartRebase(ctx context.Context, r Rebase) (Rebase, error)

StartRebase inserts a running rebase. It returns ErrExists when the effort already has a rebase running or stopped.

func (Q) SubmitReview added in v0.4.0

func (q Q) SubmitReview(ctx context.Context, r Review) (Review, error)

SubmitReview stores r as the workspace's pending review: a new one, or in place of the workspace's pending review (a later land from the same workspace replaces the snapshot and clears the conflicts). It returns the stored review.

func (Q) SystemNoteKey added in v0.4.0

func (q Q) SystemNoteKey(ctx context.Context, effortID uuid.UUID, key string) (SystemNoteKey, error)

SystemNoteKey returns the latest note on key in an effort.

func (Q) SystemNotesTo added in v0.4.0

func (q Q) SystemNotesTo(ctx context.Context, to []uuid.UUID, since time.Time, limit int) ([]Note, error)

SystemNotesTo returns system notes addressed to one of to (review and CI notes for a change's author), created at or after since, that no newer note replaced, newest first.

func (Q) TaskByID added in v0.2.0

func (q Q) TaskByID(ctx context.Context, id uuid.UUID) (Task, error)

TaskByID loads a task.

func (Q) TaskByPrefix added in v0.2.0

func (q Q) TaskByPrefix(ctx context.Context, effort uuid.UUID, prefix string) (Task, error)

TaskByPrefix finds the one task whose id starts with prefix, within one effort unless effort is uuid.Nil. It returns ErrNotFound or ErrAmbiguous otherwise.

func (Q) TaskDependents added in v0.2.0

func (q Q) TaskDependents(ctx context.Context, task uuid.UUID) ([]Task, error)

TaskDependents lists the tasks that wait for task, by creation.

func (Q) TaskForUpdate added in v0.2.0

func (q Q) TaskForUpdate(ctx context.Context, id uuid.UUID) (Task, error)

TaskForUpdate loads a task and locks its row until the transaction ends.

func (Q) TeamByName added in v0.2.0

func (q Q) TeamByName(ctx context.Context, org Org, name string) (Team, error)

TeamByName looks up a team of org, with its members.

func (Q) TokenByID added in v0.2.0

func (q Q) TokenByID(ctx context.Context, id uuid.UUID) (Token, error)

TokenByID looks a token up by id.

func (Q) TokenOwner added in v0.5.0

func (q Q) TokenOwner(ctx context.Context, token uuid.UUID) (uuid.UUID, bool, error)

TokenOwner is the principal a token belongs to and whether it is still active.

func (Q) TokenSSOOrgs added in v0.5.0

func (q Q) TokenSSOOrgs(ctx context.Context, token uuid.UUID) ([]uuid.UUID, error)

TokenSSOOrgs lists the organizations a token was issued through.

func (Q) TouchCLILoginPoll added in v0.2.0

func (q Q) TouchCLILoginPoll(ctx context.Context, deviceHash []byte, at time.Time) error

TouchCLILoginPoll records a poll.

func (Q) TouchIdentity added in v0.5.0

func (q Q) TouchIdentity(ctx context.Context, issuer, subject, email string) error

TouchIdentity records a sign-in with an identity and its current email.

func (Q) TouchWorkspace added in v0.5.0

func (q Q) TouchWorkspace(ctx context.Context, id uuid.UUID, at time.Time) error

TouchWorkspace records that an open workspace did something at at.

func (Q) UpdateOrg added in v0.2.0

func (q Q) UpdateOrg(ctx context.Context, id uuid.UUID, displayName, defaultRole *string) (Org, error)

UpdateOrg changes the display name and default repository role; nil values stay.

func (Q) UpdateRebase added in v0.2.0

func (q Q) UpdateRebase(ctx context.Context, r Rebase, seenVersion int64) (bool, error)

UpdateRebase saves a rebase's progress with a compare-and-swap on its version, and reports false when someone else changed it first (another continue, or an abort).

func (Q) UpsertBranch

func (q Q) UpsertBranch(ctx context.Context, b Branch) error

UpsertBranch records the current head of an upstream branch.

func (Q) UpsertGitHubInstallation added in v0.2.0

func (q Q) UpsertGitHubInstallation(ctx context.Context, in GitHubInstallationRow) error

UpsertGitHubInstallation records an installation of the App or updates it (account, linked organization, selection, suspension).

func (Q) UseInvite added in v0.2.0

func (q Q) UseInvite(ctx context.Context, login string) (ok bool, err error)

UseInvite marks an open invite for login used; ok is false when there is no open invite.

func (Q) UseLoginCode added in v0.5.0

func (q Q) UseLoginCode(ctx context.Context, codeHash []byte, now time.Time) (uuid.UUID, error)

UseLoginCode deletes a code and returns who it signs in. Of two servers redeeming one code at once, only one gets it; an expired or unknown code is ErrNotFound.

func (Q) UseNonce added in v0.5.0

func (q Q) UseNonce(ctx context.Context, key string, expires time.Time) (bool, error)

UseNonce records an ID token's nonce; false when it was used before. Expired nonces are dropped as it goes.

func (Q) WelcomeDismissed added in v0.2.0

func (q Q) WelcomeDismissed(ctx context.Context, principalID uuid.UUID) (bool, error)

WelcomeDismissed reports whether a person has dismissed the welcome page.

func (Q) WithdrawReviews added in v0.4.0

func (q Q) WithdrawReviews(ctx context.Context, workspace uuid.UUID) error

WithdrawReviews withdraws the workspace's pending review, if any.

type Rebase added in v0.2.0

type Rebase struct {
	ID         uuid.UUID
	RepoID     uuid.UUID
	EffortID   uuid.UUID
	State      RebaseState
	OntoBranch string
	Onto       hash.Hash
	OntoGitSHA string
	OldBase    hash.Hash
	OldHead    hash.Hash
	SeenHead   hash.Hash
	NewHead    hash.Hash
	Replayed   []Replayed
	Pending    []hash.Hash
	Conflicts  []RebaseConflict
	StartedBy  uuid.UUID
	UpdatedBy  uuid.UUID
	Version    int64
	CreatedAt  time.Time
	UpdatedAt  time.Time
}

Rebase is one rebase of an effort onto a newer head of a branch.

type RebaseConflict added in v0.2.0

type RebaseConflict struct {
	Path      string `json:"path"`
	Kind      string `json:"kind"`
	Detail    string `json:"detail,omitempty"`
	Generated bool   `json:"generated,omitempty"` // the file says "Code generated ... DO NOT EDIT."
}

RebaseConflict is one path that stopped a rebase.

type RebaseState added in v0.2.0

type RebaseState string

RebaseState is the lifecycle state of an effort rebase.

const (
	RebaseRunning RebaseState = "running" // the server is replaying changes
	RebaseStopped RebaseState = "stopped" // a change conflicts and waits for a resolution
	RebaseDone    RebaseState = "done"    // the effort head moved to the rebased chain
	RebaseAborted RebaseState = "aborted" // dropped; the effort is unchanged
)

func (RebaseState) Active added in v0.2.0

func (s RebaseState) Active() bool

Active reports whether the rebase is still in progress.

type Replayed added in v0.2.0

type Replayed struct {
	From hash.Hash `json:"from"`
	To   hash.Hash `json:"to"`
}

Replayed pairs an old-chain changeset with its rebased version.

type Repo

type Repo struct {
	ID            uuid.UUID
	Name          string
	Provider      Provider
	Remote        string
	DefaultBranch string
	// BaseURL is the web address of a GitLab, Gitea, Forgejo or Bitbucket
	// host, e.g. https://gitlab.example.com; empty for other providers.
	BaseURL   string
	OrgID     uuid.UUID // the owning organization
	Org       string    // its handle
	CreatedAt time.Time
	// GitHubRepoID is set for a repository linked to GitHub, and
	// GitHubInstallationID while an installation of the App reaches it.
	// Such a repository is GitHub-backed: roles on it come from GitHub,
	// never from vx grants. Without an installation nobody but service
	// principals and support grants has a role on it (it stays GitHub-backed, so access fails closed).
	GitHubRepoID         *int64
	GitHubInstallationID *int64
}

Repo is a repository known to vx and its upstream.

func (Repo) GitHubBacked added in v0.2.0

func (r Repo) GitHubBacked() bool

GitHubBacked reports whether roles on r come from GitHub: it is linked to a GitHub repository (with or without an installation reaching it now).

func (Repo) HostName added in v0.4.0

func (r Repo) HostName() string

HostName is the repository's git host as people call it.

func (Repo) PRName added in v0.4.0

func (r Repo) PRName() string

PRName is what the repository's host calls a pull request.

func (Repo) WebURL added in v0.4.0

func (r Repo) WebURL() string

WebURL is the page of a GitLab, Gitea, Forgejo or Bitbucket repository on its host, or "" for other providers (a GitHub repository may be on GitHub Enterprise, which only the service knows).

type RepoGrant added in v0.2.0

type RepoGrant struct {
	RepoID    uuid.UUID
	Principal *Principal // set for grants to a person or service
	Team      *Team      // set for grants to a team (without members)
	Role      string
}

RepoGrant is a direct grant on a repository, to a principal or a team.

type Reservation added in v0.3.0

type Reservation struct {
	RepoID     uuid.UUID
	Rule       string
	Value      string
	EffortID   *uuid.UUID
	EffortSlug string
	EffortOpen bool // the effort exists and is open
	ReservedBy string
	CreatedAt  time.Time
}

Reservation is a value of a vx.toml [unique] rule handed out by vx reserve (rule_reservations). EffortSlug and ReservedBy are read from the effort and principal; empty when those were deleted.

type Review added in v0.4.0

type Review struct {
	ID          uuid.UUID
	RepoID      uuid.UUID
	EffortID    uuid.UUID
	WorkspaceID uuid.UUID
	AuthorID    uuid.UUID
	ChangeID    string
	Intent      string
	Base        hash.Hash // changeset the snapshot was made on
	Tree        hash.Hash // the snapshot
	Evidence    *object.Evidence
	DependsOn   []string
	Model       string
	Session     string
	Paths       []string   // changed files under the human policy
	Policies    []string   // the matching [[policy]] tables, for people
	Approvers   [][]string // a person must be in every list; empty: anyone with write
	State       ReviewState
	Conflicts   []string // paths that conflicted when it was last approved
	DecidedBy   *uuid.UUID
	DecidedAt   *time.Time
	Reason      string
	Landed      hash.Hash
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

Review is a land under a "human" landing policy that waits for a person: the author's snapshot, kept until someone approves or rejects it.

type ReviewFilter added in v0.4.0

type ReviewFilter struct {
	Repos    []uuid.UUID // nil: every repository
	EffortID uuid.UUID
	States   []ReviewState
	Limit    int
}

ReviewFilter selects reviews. Zero fields do not filter.

type ReviewState added in v0.4.0

type ReviewState string

ReviewState is the lifecycle state of a review.

const (
	ReviewPending   ReviewState = "pending"   // waits for a person
	ReviewApproved  ReviewState = "approved"  // a person approved it and it landed
	ReviewRejected  ReviewState = "rejected"  // a person rejected it; the workspace stays open
	ReviewWithdrawn ReviewState = "withdrawn" // the workspace was abandoned
)

type RoleFacts added in v0.2.0

type RoleFacts struct {
	Grant       string // highest direct or team grant, or ""
	OrgRole     string // role in the repo's organization, or ""
	DefaultRole string // the organization's default role for members
	// Support is the role of an unexpired support grant to the principal,
	// a superadmin, or "". It counts on every repository, GitHub-backed
	// ones too. Superadmins have no other role on a repository than what
	// grants, teams, organizations and support grants give them.
	Support string
}

RoleFacts are what a principal's role on one repository is computed from, read in one query.

type ServerNotice added in v0.5.0

type ServerNotice struct {
	Key        string
	CreatedAt  time.Time
	LoggedAt   *time.Time
	ResolvedAt *time.Time
	ResolvedBy *uuid.UUID
}

ServerNotice is a one-time notice about an upgrade.

type Shipment

type Shipment struct {
	ID          uuid.UUID
	EffortID    uuid.UUID
	Title       string
	Branch      string
	Target      string
	BaseGitSHA  string
	HeadGitSHA  string
	ProviderRef string
	URL         string
	State       string
	// Split is how the parts of an effort shipped as several pull
	// requests relate: "independent" or "stacked"; empty for one PR.
	Split string
	// Part is the 1-based position among the effort's parts; 0 for one PR.
	Part      int
	CreatedBy uuid.UUID
	CreatedAt time.Time
	UpdatedAt time.Time
	Changes   []ShipmentChange
	// BaseTree is the target's tree the commits were made on; zero for
	// shipments made before v0.4.
	BaseTree hash.Hash
}

Shipment is an effort's changes pushed as a branch, usually with a PR.

type ShipmentCI added in v0.4.0

type ShipmentCI struct {
	ShipmentID uuid.UUID
	HeadSHA    string
	State      string // pending, passed, failed
	UpdatedAt  time.Time
}

ShipmentCI is the CI result of a shipment's head commit.

type ShipmentChange

type ShipmentChange struct {
	Position  int
	Changeset hash.Hash
	ChangeID  string
	GitSHA    string
	// Tree is the tree of the pushed commit; zero for shipments made
	// before v0.4. Review comments on lines map to changes through it.
	Tree hash.Hash
}

ShipmentChange is one changeset in a shipment and the commit made for it.

type ShipmentCheck added in v0.4.0

type ShipmentCheck struct {
	ShipmentID uuid.UUID
	HeadSHA    string
	Source     string // check_run, status, pipeline
	Name       string
	Status     string // queued, in_progress, completed
	Conclusion string // success, failure, ... once completed
	URL        string
	UpdatedAt  time.Time
}

ShipmentCheck is one CI check reported for a shipment's commit.

type ShipmentRef added in v0.4.0

type ShipmentRef struct {
	Shipment
	RepoID uuid.UUID
}

ShipmentRef is a shipment with the effort and repository it belongs to.

type SignupInvite added in v0.2.0

type SignupInvite struct {
	GitHubLogin string // lowercased
	InvitedBy   *uuid.UUID
	Note        string
	SiteAdmin   bool // the person becomes a superadmin (invites from the server console only)
	CreatedAt   time.Time
	UsedAt      *time.Time
}

SignupInvite allows a GitHub login to sign up while sign-up is invite-only.

type Store

type Store struct {
	Q
	// contains filtered or unexported fields
}

Store is the connection pool plus queries.

func Open

func Open(ctx context.Context, url string) (*Store, error)

Open connects to Postgres.

func (*Store) Close

func (s *Store) Close()

Close closes the pool.

func (*Store) InTx

func (s *Store) InTx(ctx context.Context, fn func(tx *Tx) error) error

InTx runs fn in a transaction. The transaction commits if fn returns nil.

func (*Store) Migrate

func (s *Store) Migrate(ctx context.Context) error

Migrate applies pending migrations in order, each in its own transaction. Numbers may have gaps (efforts built in parallel reserve numbers), and a migration is applied when its version has not been applied yet, even if a later one has: a lower number landing after a higher one still runs.

func (*Store) MigrateTo added in v0.2.0

func (s *Store) MigrateTo(ctx context.Context, upTo int) error

MigrateTo is Migrate that stops after version upTo (0: all), for tests of data migrations.

func (*Store) Ping

func (s *Store) Ping(ctx context.Context) error

Ping checks the database connection.

func (*Store) PoolStat added in v0.5.0

func (s *Store) PoolStat() *pgxpool.Stat

PoolStat returns the database pool's statistics, for /metrics.

func (*Store) PurgeOrgRows added in v0.6.0

func (s *Store) PurgeOrgRows(ctx context.Context, orgID uuid.UUID, handle string, at time.Time) (OrgDeletion, error)

PurgeOrgRows deletes the organization itself, after its repositories, and marks the purge done. It logs org.purge with the counts.

func (*Store) PurgeRepoObjects added in v0.6.0

func (s *Store) PurgeRepoObjects(ctx context.Context, orgID, repoID uuid.UUID, purged []uuid.UUID) (int, error)

PurgeRepoObjects deletes up to PurgeBatch of a repository's object records, and marks for deletion the blobs among them that no repository outside purged (the organization's repositories) records. It returns how many records it deleted; 0 means none are left.

func (*Store) PurgeRepoRow added in v0.6.0

func (s *Store) PurgeRepoRow(ctx context.Context, orgID, repoID uuid.UUID) error

PurgeRepoRow deletes what is left of a repository: its row and every small table that cascades from it, counted first.

func (*Store) PurgeRepoStep added in v0.6.0

func (s *Store) PurgeRepoStep(ctx context.Context, orgID, repoID uuid.UUID, i int) (n int64, ok bool, err error)

PurgeRepoStep runs step i of repoPurgeSteps once for a repository and returns how many rows it deleted; ok is false past the last step.

func (*Store) PurgeTarget added in v0.6.0

func (s *Store) PurgeTarget(ctx context.Context, orgID uuid.UUID, by string, at time.Time) (PurgeOrgRow, error)

PurgeTarget reads a deleted organization for its purge and marks the purge started (a restore is refused from then on).

func (*Store) RecordRepoObjects added in v0.6.0

func (s *Store) RecordRepoObjects(ctx context.Context, repoID uuid.UUID, hashes []hash.Hash, present func(context.Context, hash.Hash) (bool, error)) ([]hash.Hash, error)

RecordRepoObjects records objects as part of a repository, like AddRepoObjects, and makes sure none of them was deleted by an organization purge meanwhile: a blob can be deleted after the caller put it (the put found it there and skipped writing) and before it was recorded. Recording happens first; then, for the objects a purge marked, present checks under a shared lock on each hash that the blob is still in the store (the purge holds the lock exclusively while it checks and deletes, and sees the recording if it comes later). Objects that are gone are unrecorded again and returned: the caller puts them again and records them once more, or fails and is retried.

func (*Store) SweepBlobs added in v0.6.0

func (s *Store) SweepBlobs(ctx context.Context, orgID *uuid.UUID, limit int, del func(context.Context, hash.Hash) error) (deleted, handled int, err error)

SweepBlobs deletes up to limit blobs marked for deletion that no repository records, with del (the blob store's delete), and forgets their sizes. Marked blobs a repository records again are unmarked. It returns how many it deleted and how many marks it handled (0: none left).

func (*Store) TryPurgeLock added in v0.6.0

func (s *Store) TryPurgeLock(ctx context.Context) (alive func(context.Context) bool, unlock func(), ok bool, err error)

TryPurgeLock takes the purge lock if no other server holds it. It is a session lock on a connection of its own: if the server dies, the connection closes and the lock is free again. alive reports whether the lock is still held (the connection works); unlock releases it.

type SupportGrant added in v0.5.0

type SupportGrant struct {
	RepoID    uuid.UUID
	Person    Principal
	Role      string
	ExpiresAt time.Time
	Reason    string
	GrantedBy *Principal // nil when that person is gone
	CreatedAt time.Time
}

SupportGrant is a time-limited role a repository's admins gave a superadmin on that repository.

type SystemNoteKey added in v0.4.0

type SystemNoteKey struct {
	EffortID uuid.UUID
	Key      string
	NoteID   uuid.UUID
	Digest   string // what the note said, in short: an unchanged digest posts nothing
}

SystemNoteKey is the latest system note vx posted on one subject.

type Task added in v0.2.0

type Task struct {
	ID         uuid.UUID
	Seq        int64
	RepoID     uuid.UUID
	EffortID   uuid.UUID
	Title      string
	Body       string
	State      string // open, taken, done
	OwnerID    *uuid.UUID
	CreatedBy  uuid.UUID
	CreatedAt  time.Time
	UpdatedAt  time.Time
	DependsOn  []uuid.UUID // in the order the tasks were created
	Blocked    bool
	RepoName   string
	EffortSlug string
}

Task is a stored task of an effort's plan. DependsOn and Blocked are read from task_deps: Blocked is set while some task it depends on is not done.

type TaskFilter added in v0.2.0

type TaskFilter struct {
	EffortID uuid.UUID
	States   []string
	Owners   []uuid.UUID
}

TaskFilter selects an effort's tasks. Zero fields do not filter.

type Team added in v0.2.0

type Team struct {
	ID      uuid.UUID
	OrgID   uuid.UUID
	Org     string
	Name    string
	Members []Principal
}

Team is a named group of an organization's members.

type Token added in v0.2.0

type Token struct {
	ID          uuid.UUID
	PrincipalID uuid.UUID
	Name        string
	CreatedAt   time.Time
	LastUsedAt  *time.Time
	RevokedAt   *time.Time
}

Token describes a token without its secret, which is never stored.

func (Token) Active added in v0.2.0

func (t Token) Active() bool

Active reports whether the token can still be used.

type Tx

type Tx struct {
	Q
	// contains filtered or unexported fields
}

Tx is a transaction plus queries.

type UpstreamSecrets added in v0.4.0

type UpstreamSecrets struct {
	TokenEnc         []byte
	WebhookSecretEnc []byte
}

UpstreamSecrets are a repository's sealed host secrets (internal/secret): nil fields mean "use the server's".

type Warning added in v0.2.0

type Warning struct {
	Path   string   `json:"path"`
	Kind   string   `json:"kind"`
	Name   string   `json:"name,omitempty"`
	Decl   string   `json:"decl,omitempty"`
	Files  []string `json:"files,omitempty"`
	Detail string   `json:"detail"`
}

Warning is a problem found in a landed tree that did not stop the land, such as a Go function declared twice in one package.

type Workspace

type Workspace struct {
	ID        uuid.UUID
	EffortID  uuid.UUID
	OwnerID   uuid.UUID
	Intent    string
	ChangeID  string
	Base      hash.Hash
	State     WorkspaceState
	LandedAs  hash.Hash
	CreatedAt time.Time
	UpdatedAt time.Time
	// ChangedPaths are the files the working copy last reported as
	// changed, at ChangedPathsAt; nil ChangedPathsAt: never reported.
	ChangedPaths   []string
	ChangedPathsAt *time.Time
	// ActiveAt is when the workspace last synced, landed or reported its
	// files; nil: not since it was created.
	ActiveAt *time.Time
}

Workspace is one task's draft inside an effort.

func (Workspace) LastActive added in v0.5.0

func (w Workspace) LastActive() time.Time

LastActive is when the workspace last did something: ActiveAt, ChangedPathsAt or, failing both, when it was created.

type WorkspaceState

type WorkspaceState string

WorkspaceState is the lifecycle state of a workspace.

const (
	WorkspaceOpen      WorkspaceState = "open"
	WorkspaceLanded    WorkspaceState = "landed"
	WorkspaceAbandoned WorkspaceState = "abandoned"
)

Directories

Path Synopsis
Package storetest gives tests an isolated, migrated Postgres database.
Package storetest gives tests an isolated, migrated Postgres database.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL