pfsdb

package
v2.8.0-nightly.20230907 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package pfsdb contains the database schema that PFS uses.

Index

Constants

View Source
const (
	// ReposChannelName is used to watch events for the repos table.
	ReposChannelName = "pfs_repos"
)

Variables

View Source
var (
	RepoTypes    = RepoFields("type")
	RepoProjects = RepoFields("project_id")
	RepoNames    = RepoFields("name")
)
View Source
var BranchesRepoIndex = &col.Index{
	Name: "repo",
	Extract: func(val proto.Message) string {
		return RepoKey(val.(*pfs.BranchInfo).Branch.Repo)
	},
}
View Source
var CommitsBranchlessIndex = &col.Index{
	Name: "branchless",
	Extract: func(val proto.Message) string {
		return CommitKey(val.(*pfs.CommitInfo).Commit)
	},
}
View Source
var CommitsCommitSetIndex = &col.Index{
	Name: "commitset",
	Extract: func(val proto.Message) string {
		return val.(*pfs.CommitInfo).Commit.Id
	},
}
View Source
var CommitsRepoIndex = &col.Index{
	Name: "repo",
	Extract: func(val proto.Message) string {
		return RepoKey(val.(*pfs.CommitInfo).Commit.Repo)
	},
}

Functions

func AddCommit

func AddCommit(tx *pachsql.Tx, commit *pfs.Commit) error

func AddCommitProvenance

func AddCommitProvenance(tx *pachsql.Tx, from, to *pfs.Commit) error

func BranchKey

func BranchKey(branch *pfs.Branch) string

func Branches

func Branches(db *pachsql.DB, listener col.PostgresListener) col.PostgresCollection

Branches returns a collection of branches

func CommitKey

func CommitKey(commit *pfs.Commit) string

func CommitSetProvenance

func CommitSetProvenance(tx *pachsql.Tx, id string) (_ []*pfs.Commit, retErr error)

CommitSetProvenance returns all the commit IDs that are in the provenance of all the commits in this commit set.

TODO(provenance): is 'SELECT DISTINCT commit_id' a performance concern?

func CommitSetSubvenance

func CommitSetSubvenance(tx *pachsql.Tx, id string) (_ []*pfs.Commit, retErr error)

CommitSetSubvenance returns all the commit IDs that contain commits in this commit set in their full (transitive) provenance

func Commits

func Commits(db *pachsql.DB, listener col.PostgresListener) col.PostgresCollection

Commits returns a collection of commits

func CreateRepo

func CreateRepo(ctx context.Context, tx *pachsql.Tx, repo *pfs.RepoInfo) error

CreateRepo creates an entry in the pfs.repos table.

func DeleteRepo added in v2.8.0

func DeleteRepo(ctx context.Context, tx *pachsql.Tx, repoProject, repoName, repoType string) error

DeleteRepo deletes an entry in the pfs.repos table.

func GetBranch

func GetBranch(ctx context.Context, tx *pachsql.Tx, id BranchID) (*pfs.BranchInfo, error)

GetBranch returns a branch by id.

func GetRepo added in v2.8.0

func GetRepo(ctx context.Context, tx *pachsql.Tx, id RepoID) (*pfs.RepoInfo, error)

todo(fahad): rewrite branch related code during the branches migration. GetRepo retrieves an entry from the pfs.repos table by using the row id.

func GetRepoByName added in v2.8.0

func GetRepoByName(ctx context.Context, tx *pachsql.Tx, repoProject, repoName, repoType string) (*pfs.RepoInfo, error)

GetRepoByName retrieves an entry from the pfs.repos table by project, repo name, and type.

func IsDuplicateKeyErr added in v2.8.0

func IsDuplicateKeyErr(err error) bool

func IsErrRepoNotFound added in v2.8.0

func IsErrRepoNotFound(err error) bool

func ParseBranch added in v2.6.6

func ParseBranch(key string) *pfs.Branch

func ParseCommit

func ParseCommit(key string) *pfs.Commit

func ParseRepo

func ParseRepo(key string) *pfs.Repo

func ProjectKey

func ProjectKey(project *pfs.Project) string

func RepoKey

func RepoKey(repo *pfs.Repo) string

func ResolveCommitProvenance

func ResolveCommitProvenance(tx *pachsql.Tx, repo *pfs.Repo, commitSet string) (*pfs.Commit, error)

returns the commit of a certain repo in a commit set.

func UpdateRepo

func UpdateRepo(ctx context.Context, tx *pachsql.Tx, id RepoID, repo *pfs.RepoInfo) error

UpdateRepo overwrites an existing repo entry by RepoID.

func UpsertRepo added in v2.8.0

func UpsertRepo(ctx context.Context, tx *pachsql.Tx, repo *pfs.RepoInfo) error

UpsertRepo will attempt to insert a repo. If the repo already exists, it will update its description.

Types

type Branch added in v2.8.0

type Branch struct {
	ID   BranchID `db:"id"`
	Head Commit   `db:"head"`
	Repo Repo     `db:"repo"`
	Name string   `db:"name"`
	CreatedAtUpdatedAt
}

Branch is a row in the pfs.branches table.

func (*Branch) Pb added in v2.8.0

func (branch *Branch) Pb() *pfs.Branch

type BranchID added in v2.8.0

type BranchID uint64

BranchID is the row id for a branch entry in postgres.

func UpsertBranch added in v2.8.0

func UpsertBranch(ctx context.Context, tx *pachsql.Tx, branchInfo *pfs.BranchInfo) (BranchID, error)

UpsertBranch creates a branch if it does not exist, or updates the head commit if it does.

type Commit added in v2.8.0

type Commit struct {
	ID          CommitID `db:"id"`
	Repo        Repo     `db:"repo"`
	CommitSetID string   `db:"commit_set_id"`
	CreatedAtUpdatedAt
}

Commit is a row in the pfs.commits table.

func (*Commit) Pb added in v2.8.0

func (commit *Commit) Pb() *pfs.Commit

type CommitID added in v2.8.0

type CommitID uint64

CommitID is the row id for a commit entry in postgres.

type CreatedAtUpdatedAt added in v2.8.0

type CreatedAtUpdatedAt struct {
	CreatedAt time.Time `db:"created_at"`
	UpdatedAt time.Time `db:"updated_at"`
}

type ErrRepoAlreadyExists

type ErrRepoAlreadyExists struct {
	Project string
	Name    string
	Type    string
}

ErrRepoAlreadyExists is returned by CreateRepo() when a repo with the same name already exists in postgres.

func (ErrRepoAlreadyExists) Error

func (err ErrRepoAlreadyExists) Error() string

Error satisfies the error interface.

func (ErrRepoAlreadyExists) GRPCStatus

func (err ErrRepoAlreadyExists) GRPCStatus() *status.Status

type ErrRepoNotFound

type ErrRepoNotFound struct {
	Project string
	Name    string
	Type    string
	ID      RepoID
}

ErrRepoNotFound is returned by GetRepo() when a repo is not found in postgres.

func (ErrRepoNotFound) Error

func (err ErrRepoNotFound) Error() string

Error satisfies the error interface.

func (ErrRepoNotFound) GRPCStatus

func (err ErrRepoNotFound) GRPCStatus() *status.Status

type Repo added in v2.8.0

type Repo struct {
	ID          RepoID         `db:"id"`
	Project     coredb.Project `db:"project"`
	Name        string         `db:"name"`
	Description string         `db:"description"`
	Type        string         `db:"type"`
	CreatedAtUpdatedAt
}

Repo is a row in the pfs.repos table.

func (*Repo) Pb added in v2.8.0

func (repo *Repo) Pb() *pfs.Repo

type RepoFields

type RepoFields string

RepoFields is used in the ListRepoFilter and defines specific field names for type safety. This should hopefully prevent a library user from misconfiguring the filter.

type RepoID added in v2.8.0

type RepoID uint64

RepoID is the row id for a repo entry in postgres. A separate type is defined for safety so row ids must be explicitly cast for use in another table.

func GetRepoID added in v2.8.0

func GetRepoID(ctx context.Context, tx *pachsql.Tx, repoProject, repoName, repoType string) (RepoID, error)

type RepoIterator added in v2.8.0

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

RepoIterator batches a page of repoRow entries. Entries can be retrieved using iter.Next().

func ListRepo added in v2.8.0

func ListRepo(ctx context.Context, tx *pachsql.Tx, filter RepoListFilter) (*RepoIterator, error)

ListRepo returns a RepoIterator that exposes a Next() function for retrieving *pfs.RepoInfo references.

func (*RepoIterator) Next added in v2.8.0

func (iter *RepoIterator) Next(ctx context.Context, dst *RepoPair) error

Next advances the iterator by one row. It returns a stream.EOS when there are no more entries.

type RepoListFilter

type RepoListFilter map[RepoFields][]string

RepoListFilter is a filter for listing repos. It ANDs together separate keys, but ORs together the key values: where repo.<key_1> IN (<key_1:value_1>, <key_2:value_2>, ...) AND repo.<key_2> IN (<key_2:value_1>,<key_2:value_2>,...)

type RepoPair

type RepoPair struct {
	ID       RepoID
	RepoInfo *pfs.RepoInfo
}

RepoPair is an (id, repoInfo) tuple returned by the repo iterator.

Jump to

Keyboard shortcuts

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