store

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 21 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 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 ErrNotFound = errors.New("not found")

ErrNotFound is returned when a row does not exist.

Functions

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 // "site admin", "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 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 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 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
}

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 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 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 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
}

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 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 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 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
)

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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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 site admins 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) 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) 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) 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) 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) 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) 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) 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) 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) 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: site admins, the roles GitHub reported for people checked since since (via "GitHub"), and direct grants of service principals, by handle.

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) 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) 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) 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) 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 and System are stored as given; SupersededBy is 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) 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) 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) 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) ListBranches

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

ListBranches returns the tracked branches of a repo.

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) 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.

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) ([]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) ListShipments

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

ListShipments returns an effort's shipments with their changes.

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) 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) 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) 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) 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) 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) 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) 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.

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) 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) 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) 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) 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) ReadableRepoIDs added in v0.2.0

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

ReadableRepoIDs returns the ids of the repositories principal can read through grants, teams and organization membership (directOnly: through direct grants only). Site admins are not special here; callers check. GitHub-backed repositories are left out, except for directOnly (service principals keep their direct grants there): roles on them come from GitHub, and the service adds 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) 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) 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: site admins, organization owners and admins, the default role for members, direct grants and team grants.

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) (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) (Repo, RoleFacts, error)

RepoRoleFactsByID is RepoRoleFacts for a repository id.

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) 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) 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) 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) 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) 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) 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) SetSiteAdmin added in v0.2.0

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

SetSiteAdmin makes a person a site admin or not.

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) 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) 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) 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) 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) 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) 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.

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
	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 site admins
	// 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).

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 RoleFacts added in v0.2.0

type RoleFacts struct {
	SiteAdmin   bool   // the principal is a site admin
	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
}

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

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
	CreatedBy   uuid.UUID
	CreatedAt   time.Time
	UpdatedAt   time.Time
	Changes     []ShipmentChange
}

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

type ShipmentChange

type ShipmentChange struct {
	Position  int
	Changeset hash.Hash
	ChangeID  string
	GitSHA    string
}

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

type SignupInvite added in v0.2.0

type SignupInvite struct {
	GitHubLogin string // lowercased
	InvitedBy   *uuid.UUID
	Note        string
	SiteAdmin   bool // the person becomes a site admin (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.

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 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
}

Workspace is one task's draft inside an effort.

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