db

package
v0.0.0-...-d34966d Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BuildFailed string = "build_failed"
	//	BuiltNotTested  string = "built"
	//	BuildTestFailed string = "tests_failed"
	BuildSuccess string = "success"
)

Variables

View Source
var ErrEntityNotFound = errors.New("entity not found")
View Source
var ErrFindingExists = errors.New("the finding already exists")
View Source
var ErrSeriesExists = errors.New("the series already exists")
View Source
var ErrSessionAlreadyStarted = errors.New("the session already started")

Functions

func CreateSpannerDB

func CreateSpannerDB(ctx context.Context, uri ParsedURI) error

func CreateSpannerInstance

func CreateSpannerInstance(ctx context.Context, uri ParsedURI) error

func NewTransientDB

func NewTransientDB(t *testing.T) (*spanner.Client, context.Context)

func RunMigrations

func RunMigrations(ctx context.Context, uri string) error

Types

type Build

type Build struct {
	ID         string             `spanner:"ID"`
	TreeName   string             `spanner:"TreeName"`
	CommitHash string             `spanner:"CommitHash"`
	CommitDate time.Time          `spanner:"CommitDate"`
	SeriesID   spanner.NullString `spanner:"SeriesID"`
	Arch       string             `spanner:"Arch"`
	ConfigName string             `spanner:"ConfigName"`
	ConfigURI  string             `spanner:"ConfigURI"`
	Status     string             `spanner:"Status"`
}

func (*Build) SetSeriesID

func (b *Build) SetSeriesID(val string)

type BuildRepository

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

func NewBuildRepository

func NewBuildRepository(client *spanner.Client) *BuildRepository

func (BuildRepository) GetByID

func (g BuildRepository) GetByID(ctx context.Context, key KeyType) (*EntityType, error)

func (*BuildRepository) Insert

func (repo *BuildRepository) Insert(ctx context.Context, build *Build) error

func (*BuildRepository) LastBuiltTree

func (repo *BuildRepository) LastBuiltTree(ctx context.Context, params *LastBuildParams) (*Build, error)

func (BuildRepository) Update

func (g BuildRepository) Update(ctx context.Context, key KeyType,
	cb func(*EntityType) error) error

type Finding

type Finding struct {
	ID        string `spanner:"ID"`
	SessionID string `spanner:"SessionID"`
	TestName  string `spanner:"TestName"`
	Title     string `spanner:"Title"`
	ReportURI string `spanner:"ReportURI"`
	LogURI    string `spanner:"LogURI"`
}

type FindingRepository

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

func NewFindingRepository

func NewFindingRepository(client *spanner.Client) *FindingRepository

func (FindingRepository) GetByID

func (g FindingRepository) GetByID(ctx context.Context, key KeyType) (*EntityType, error)

func (FindingRepository) Insert

func (g FindingRepository) Insert(ctx context.Context, obj *EntityType) error

func (*FindingRepository) ListForSession

func (repo *FindingRepository) ListForSession(ctx context.Context, sessionID string) ([]*Finding, error)

nolint: dupl

func (*FindingRepository) Save

func (repo *FindingRepository) Save(ctx context.Context, finding *Finding) error

Save either adds the finding to the database or returns ErrFindingExists.

func (FindingRepository) Update

func (g FindingRepository) Update(ctx context.Context, key KeyType,
	cb func(*EntityType) error) error

type FullSessionTest

type FullSessionTest struct {
	*SessionTest
	BaseBuild    *Build
	PatchedBuild *Build
}

type LastBuildParams

type LastBuildParams struct {
	Arch       string
	TreeName   string
	ConfigName string
	Status     string
	Commit     string
}

type NextSession

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

type ParsedURI

type ParsedURI struct {
	ProjectPrefix  string // projects/<project>
	InstancePrefix string // projects/<project>/instances/<instance>
	Instance       string
	Database       string
	Full           string
}

func ParseURI

func ParseURI(uri string) (ParsedURI, error)

type Patch

type Patch struct {
	ID       string `spanner:"ID"`
	Seq      int64  `spanner:"Seq"`
	SeriesID string `spanner:"SeriesID"`
	Title    string `spanner:"Title"`
	Link     string `spanner:"Link"`
	BodyURI  string `spanner:"BodyURI"`
}

type ReportRepository

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

func NewReportRepository

func NewReportRepository(client *spanner.Client) *ReportRepository

func (ReportRepository) GetByID

func (g ReportRepository) GetByID(ctx context.Context, key KeyType) (*EntityType, error)

func (*ReportRepository) Insert

func (repo *ReportRepository) Insert(ctx context.Context, rep *SessionReport) error

func (*ReportRepository) ListNotReported

func (repo *ReportRepository) ListNotReported(ctx context.Context, limit int) ([]*SessionReport, error)

func (ReportRepository) Update

func (g ReportRepository) Update(ctx context.Context, key KeyType,
	cb func(*EntityType) error) error

type Series

type Series struct {
	ID          string    `spanner:"ID"`
	ExtID       string    `spanner:"ExtID"`
	AuthorName  string    `spanner:"AuthorName"`
	AuthorEmail string    `spanner:"AuthorEmail"`
	Title       string    `spanner:"Title"`
	Link        string    `spanner:"Link"`
	Version     int64     `spanner:"Version"`
	PublishedAt time.Time `spanner:"PublishedAt"`
	// TODO: we could ger rid of the field by using slightly more complicated SQL queries.
	LatestSessionID spanner.NullString `spanner:"LatestSessionID"`
	Cc              []string           `spanner:"Cc"`
}

func (*Series) SetLatestSession

func (s *Series) SetLatestSession(session *Session)

type SeriesRepository

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

func NewSeriesRepository

func NewSeriesRepository(client *spanner.Client) *SeriesRepository

func (*SeriesRepository) Count

func (repo *SeriesRepository) Count(ctx context.Context) (int, error)

func (*SeriesRepository) GetByExtID

func (repo *SeriesRepository) GetByExtID(ctx context.Context, extID string) (*Series, error)

nolint:dupl

func (SeriesRepository) GetByID

func (g SeriesRepository) GetByID(ctx context.Context, key KeyType) (*EntityType, error)

func (*SeriesRepository) Insert

func (repo *SeriesRepository) Insert(ctx context.Context, series *Series,
	queryPatches func() ([]*Patch, error)) error

Insert() checks whether there already exists a series with the same ExtID. Since Patch content is stored elsewhere, we do not demand it be filled out before calling Insert(). Instead, Insert() obtains this data via a callback.

func (*SeriesRepository) ListLatest

func (repo *SeriesRepository) ListLatest(ctx context.Context,
	maxPublishedAt time.Time, limit int) ([]*SeriesWithSession, error)

ListLatest() returns the list of series ordered by the decreasing PublishedAt value.

func (*SeriesRepository) ListPatches

func (repo *SeriesRepository) ListPatches(ctx context.Context, series *Series) ([]*Patch, error)

golint sees too much similarity with SessionRepository's ListForSeries, but in reality there's not. nolint:dupl

func (*SeriesRepository) PatchByID

func (repo *SeriesRepository) PatchByID(ctx context.Context, id string) (*Patch, error)

TODO: move to SeriesPatchesRepository? nolint:dupl

func (SeriesRepository) Update

func (g SeriesRepository) Update(ctx context.Context, key KeyType,
	cb func(*EntityType) error) error

type SeriesWithSession

type SeriesWithSession struct {
	Series  *Series
	Session *Session
}

type Session

type Session struct {
	ID         string             `spanner:"ID"`
	SeriesID   string             `spanner:"SeriesID"`
	CreatedAt  time.Time          `spanner:"CreatedAt"`
	StartedAt  spanner.NullTime   `spanner:"StartedAt"`
	FinishedAt spanner.NullTime   `spanner:"FinishedAt"`
	SkipReason spanner.NullString `spanner:"SkipReason"`
	LogURI     string             `spanner:"LogURI"`
	Tags       []string           `spanner:"Tags"`
}

func (*Session) SetFinishedAt

func (s *Session) SetFinishedAt(t time.Time)

func (*Session) SetSkipReason

func (s *Session) SetSkipReason(reason string)

func (*Session) SetStartedAt

func (s *Session) SetStartedAt(t time.Time)

type SessionReport

type SessionReport struct {
	ID         string           `spanner:"ID"`
	SessionID  string           `spanner:"SessionID"`
	ReportedAt spanner.NullTime `spanner:"ReportedAt"`
	Moderation bool             `spanner:"Moderation"`
	Link       string           `spanner:"Link"`
}

func (*SessionReport) SetReportedAt

func (s *SessionReport) SetReportedAt(t time.Time)

type SessionRepository

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

func NewSessionRepository

func NewSessionRepository(client *spanner.Client) *SessionRepository

func (SessionRepository) GetByID

func (g SessionRepository) GetByID(ctx context.Context, key KeyType) (*EntityType, error)

func (*SessionRepository) Insert

func (repo *SessionRepository) Insert(ctx context.Context, session *Session) error

func (*SessionRepository) ListForSeries

func (repo *SessionRepository) ListForSeries(ctx context.Context, series *Series) ([]*Session, error)

golint sees too much similarity with SeriesRepository's ListPatches, but in reality there's not. nolint:dupl

func (*SessionRepository) ListRunning

func (repo *SessionRepository) ListRunning(ctx context.Context) ([]*Session, error)

func (*SessionRepository) ListWaiting

func (repo *SessionRepository) ListWaiting(ctx context.Context, from *NextSession,
	limit int) ([]*Session, *NextSession, error)

func (*SessionRepository) MissingReportList

func (repo *SessionRepository) MissingReportList(ctx context.Context, from time.Time, limit int) ([]*Session, error)

MissingReportList lists the session objects that are missing any SessionReport objects, but do have Findings. Once the conditions for creating a SessionRepor object become more complex, it will likely be not enough to have this simple method, but for now it should be fine.

func (*SessionRepository) Start

func (repo *SessionRepository) Start(ctx context.Context, sessionID string) error

func (SessionRepository) Update

func (g SessionRepository) Update(ctx context.Context, key KeyType,
	cb func(*EntityType) error) error

type SessionTest

type SessionTest struct {
	SessionID      string             `spanner:"SessionID"`
	BaseBuildID    spanner.NullString `spanner:"BaseBuildID"`
	PatchedBuildID spanner.NullString `spanner:"PatchedBuildID"`
	UpdatedAt      time.Time          `spanner:"UpdatedAt"`
	TestName       string             `spanner:"TestName"`
	Result         string             `spanner:"Result"`
	LogURI         string             `spanner:"LogURI"`
}

type SessionTestRepository

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

func NewSessionTestRepository

func NewSessionTestRepository(client *spanner.Client) *SessionTestRepository

func (*SessionTestRepository) BySession

func (repo *SessionTestRepository) BySession(ctx context.Context, sessionID string) ([]*FullSessionTest, error)

func (*SessionTestRepository) Get

func (repo *SessionTestRepository) Get(ctx context.Context, sessionID, testName string) (*SessionTest, error)

func (*SessionTestRepository) InsertOrUpdate

func (repo *SessionTestRepository) InsertOrUpdate(ctx context.Context, test *SessionTest) error

Jump to

Keyboard shortcuts

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