database

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package database provides the ability for Vela to integrate with different supported SQL backends.

Usage:

import "github.com/go-vela/server/database"

Index

Constants

This section is empty.

Variables

View Source
var Flags = []cli.Flag{

	&cli.StringFlag{
		EnvVars:  []string{"VELA_DATABASE_DRIVER", "DATABASE_DRIVER"},
		FilePath: "/vela/database/driver",
		Name:     "database.driver",
		Usage:    "driver to be used for the database system",
		Value:    "sqlite3",
	},
	&cli.StringFlag{
		EnvVars:  []string{"VELA_DATABASE_ADDR", "DATABASE_ADDR"},
		FilePath: "/vela/database/addr",
		Name:     "database.addr",
		Usage:    "fully qualified url (<scheme>://<host>) for the database",
		Value:    "vela.sqlite",
	},
	&cli.IntFlag{
		EnvVars:  []string{"VELA_DATABASE_CONNECTION_OPEN", "DATABASE_CONNECTION_OPEN"},
		FilePath: "/vela/database/connection_open",
		Name:     "database.connection.open",
		Usage:    "maximum number of open connections to the database",
		Value:    0,
	},
	&cli.IntFlag{
		EnvVars:  []string{"VELA_DATABASE_CONNECTION_IDLE", "DATABASE_CONNECTION_IDLE"},
		FilePath: "/vela/database/connection_idle",
		Name:     "database.connection.idle",
		Usage:    "maximum number of idle connections to the database",
		Value:    2,
	},
	&cli.DurationFlag{
		EnvVars:  []string{"VELA_DATABASE_CONNECTION_LIFE", "DATABASE_CONNECTION_LIFE"},
		FilePath: "/vela/database/connection_life",
		Name:     "database.connection.life",
		Usage:    "duration of time a connection may be reused for the database",
		Value:    30 * time.Minute,
	},
	&cli.IntFlag{
		EnvVars:  []string{"VELA_DATABASE_COMPRESSION_LEVEL", "DATABASE_COMPRESSION_LEVEL"},
		FilePath: "/vela/database/compression_level",
		Name:     "database.compression.level",
		Usage:    "level of compression for logs stored in the database",
		Value:    constants.CompressionThree,
	},
	&cli.StringFlag{
		EnvVars:  []string{"VELA_DATABASE_ENCRYPTION_KEY", "DATABASE_ENCRYPTION_KEY"},
		FilePath: "/vela/database/encryption_key",
		Name:     "database.encryption.key",
		Usage:    "AES-256 key for encrypting and decrypting values in the database",
	},
	&cli.BoolFlag{
		EnvVars:  []string{"VELA_DATABASE_SKIP_CREATION", "DATABASE_SKIP_CREATION"},
		FilePath: "/vela/database/skip_creation",
		Name:     "database.skip_creation",
		Usage:    "enables skipping the creation of tables and indexes in the database",
	},
}

Flags represents all supported command line interface (CLI) flags for the database.

https://pkg.go.dev/github.com/urfave/cli?tab=doc#Flag

Functions

func ToContext

func ToContext(c Setter, d Service)

ToContext adds the database Service to this context if it supports the Setter interface.

Types

type Service

type Service interface {

	// Driver defines a function that outputs
	// the configured database driver.
	Driver() string

	// GetBuild defines a function that
	// gets a build by number and repo ID.
	GetBuild(int, *library.Repo) (*library.Build, error)
	// GetBuildByID defines a function that
	// gets a build by its id.
	GetBuildByID(int64) (*library.Build, error)
	// GetLastBuild defines a function that
	// gets the last build ran by repo ID.
	GetLastBuild(*library.Repo) (*library.Build, error)
	// GetLastBuildByBranch defines a function that
	// gets the last build ran by repo ID and branch.
	GetLastBuildByBranch(*library.Repo, string) (*library.Build, error)
	// GetBuildCount defines a function that
	// gets the count of builds.
	GetBuildCount() (int64, error)
	// GetBuildCountByStatus defines a function that
	// gets a the count of builds by status.
	GetBuildCountByStatus(string) (int64, error)
	// GetBuildList defines a function that gets
	// a list of all builds.
	GetBuildList() ([]*library.Build, error)
	// GetDeploymentBuildList defines a function that gets
	// a list of builds related to a deployment.
	GetDeploymentBuildList(string) ([]*library.Build, error)
	// GetRepoBuildList defines a function that
	// gets a list of builds by repo ID.
	GetRepoBuildList(*library.Repo, map[string]interface{}, int64, int64, int, int) ([]*library.Build, int64, error)
	// GetOrgBuildList defines a function that
	// gets a list of builds by org.
	GetOrgBuildList(string, map[string]interface{}, int, int) ([]*library.Build, int64, error)
	// GetRepoBuildCount defines a function that
	// gets the count of builds by repo ID.
	GetRepoBuildCount(*library.Repo, map[string]interface{}) (int64, error)
	// GetOrgBuildCount defines a function that
	// gets the count of builds by org.
	GetOrgBuildCount(string, map[string]interface{}) (int64, error)
	// GetPendingAndRunningBuilds defines a function that
	// gets the list of pending and running builds.
	GetPendingAndRunningBuilds(string) ([]*library.BuildQueue, error)
	// CreateBuild defines a function that
	// creates a new build.
	CreateBuild(*library.Build) error
	// UpdateBuild defines a function that
	// updates a build.
	UpdateBuild(*library.Build) error
	// DeleteBuild defines a function that
	// deletes a build by unique ID.
	DeleteBuild(int64) error

	// HookService provides the interface for functionality
	// related to hooks stored in the database.
	hook.HookService

	// LogService provides the interface for functionality
	// related to logs stored in the database.
	log.LogService

	// PipelineService provides the interface for functionality
	// related to pipelines stored in the database.
	pipeline.PipelineService

	// RepoService provides the interface for functionality
	// related to repos stored in the database.
	repo.RepoService

	// SecretService provides the interface for functionality
	// related to secrets stored in the database.
	secret.SecretService

	// StepService provides the interface for functionality
	// related to steps stored in the database.
	step.StepService

	// GetService defines a function that
	// gets a step by number and build ID.
	GetService(int, *library.Build) (*library.Service, error)
	// GetServiceList defines a function that
	// gets a list of all steps.
	GetServiceList() ([]*library.Service, error)
	// GetBuildServiceList defines a function
	// that gets a list of steps by build ID.
	GetBuildServiceList(*library.Build, int, int) ([]*library.Service, error)
	// GetBuildServiceCount defines a function
	// that gets the count of steps by build ID.
	GetBuildServiceCount(*library.Build) (int64, error)
	// GetServiceImageCount defines a function that
	// gets a list of all service images and the
	// count of their occurrence.
	GetServiceImageCount() (map[string]float64, error)
	// GetServiceStatusCount defines a function that
	// gets a list of all service statuses and the
	// count of their occurrence.
	GetServiceStatusCount() (map[string]float64, error)
	// CreateService defines a function that
	// creates a new step.
	CreateService(*library.Service) error
	// UpdateService defines a function that
	// updates a step.
	UpdateService(*library.Service) error
	// DeleteService defines a function that
	// deletes a step by unique ID.
	DeleteService(int64) error

	// UserService provides the interface for functionality
	// related to users stored in the database.
	user.UserService

	// WorkerService provides the interface for functionality
	// related to workers stored in the database.
	worker.WorkerService
}

Service represents the interface for Vela integrating with the different supported Database backends.

func FromContext

func FromContext(c context.Context) Service

FromContext returns the database Service associated with this context.

func New

func New(s *Setup) (Service, error)

New creates and returns a Vela service capable of integrating with the configured database provider.

Currently the following database providers are supported:

* Postgres * Sqlite .

type Setter

type Setter interface {
	Set(string, interface{})
}

Setter defines a context that enables setting values.

type Setup added in v0.8.0

type Setup struct {

	// specifies the driver to use for the database client
	Driver string
	// specifies the address to use for the database client
	Address string
	// specifies the level of compression to use for the database client
	CompressionLevel int
	// specifies the connection duration to use for the database client
	ConnectionLife time.Duration
	// specifies the maximum idle connections for the database client
	ConnectionIdle int
	// specifies the maximum open connections for the database client
	ConnectionOpen int
	// specifies the encryption key to use for the database client
	EncryptionKey string
	// specifies to skip creating tables and indexes for the database client
	SkipCreation bool
}

Setup represents the configuration necessary for creating a Vela service capable of integrating with a configured database system.

func (*Setup) Postgres added in v0.8.0

func (s *Setup) Postgres() (Service, error)

Postgres creates and returns a Vela service capable of integrating with a Postgres database system.

func (*Setup) Sqlite added in v0.8.0

func (s *Setup) Sqlite() (Service, error)

Sqlite creates and returns a Vela service capable of integrating with a Sqlite database system.

func (*Setup) Validate added in v0.8.0

func (s *Setup) Validate() error

Validate verifies the necessary fields for the provided configuration are populated correctly.

Directories

Path Synopsis
Package postgres provides the ability for Vela to integrate with Postgres as a SQL backend.
Package postgres provides the ability for Vela to integrate with Postgres as a SQL backend.
ddl
Package ddl provides the Postgres data definition language (DDL) for Vela.
Package ddl provides the Postgres data definition language (DDL) for Vela.
dml
Package dml provides the Postgres data manipulation language (DML) for Vela.
Package dml provides the Postgres data manipulation language (DML) for Vela.
Package sqlite provides the ability for Vela to integrate with Sqlite as a SQL backend.
Package sqlite provides the ability for Vela to integrate with Sqlite as a SQL backend.
ddl
Package ddl provides the Sqlite data definition language (DDL) for Vela.
Package ddl provides the Sqlite data definition language (DDL) for Vela.
dml
Package dml provides the Sqlite data manipulation language (DML) for Vela.
Package dml provides the Sqlite data manipulation language (DML) for Vela.

Jump to

Keyboard shortcuts

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