database

package
v0.11.0-rc3 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2021 License: Apache-2.0 Imports: 10 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_LOG_FORMAT", "DATABASE_LOG_FORMAT", "VELA_LOG_FORMAT"},
		FilePath: "/vela/database/log_format",
		Name:     "database.log.format",
		Usage:    "format of logs to output",
		Value:    "json",
	},
	&cli.StringFlag{
		EnvVars:  []string{"VELA_DATABASE_LOG_LEVEL", "DATABASE_LOG_LEVEL", "VELA_LOG_LEVEL"},
		FilePath: "/vela/database/log_level",
		Name:     "database.log.level",
		Usage:    "level of logs to output",
		Value:    "info",
	},

	&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)
	// 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]string, int, int) ([]*library.Build, int64, error)
	// GetOrgBuildList defines a function that
	// gets a list of builds by org.
	GetOrgBuildList(string, map[string]string, int, int) ([]*library.Build, int64, error)
	// GetRepoBuildCount defines a function that
	// gets the count of builds by repo ID.
	GetRepoBuildCount(*library.Repo, map[string]string) (int64, error)
	// GetOrgBuildCount defines a function that
	// gets the count of builds by org.
	GetOrgBuildCount(string, map[string]string) (int64, error)
	// GetRepoBuildCountByEvent defines a function that
	// gets the count of builds by repo ID and event type.
	GetRepoBuildCountByEvent(*library.Repo, string) (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

	// GetHook defines a function that
	// gets a webhook by number and repo ID.
	GetHook(int, *library.Repo) (*library.Hook, error)
	// GetLastHook defines a function that
	// gets the last hook by repo ID.
	GetLastHook(*library.Repo) (*library.Hook, error)
	// GetHookList defines a function that gets
	// a list of all webhooks.
	GetHookList() ([]*library.Hook, error)
	// GetRepoHookList defines a function that
	// gets a list of webhooks by repo ID.
	GetRepoHookList(*library.Repo, int, int) ([]*library.Hook, error)
	// GetRepoHookCount defines a function that
	// gets the count of webhooks by repo ID.
	GetRepoHookCount(*library.Repo) (int64, error)
	// CreateHook defines a function that
	// creates a new webhook.
	CreateHook(*library.Hook) error
	// UpdateHook defines a function that
	// updates a webhook.
	UpdateHook(*library.Hook) error
	// DeleteHook defines a function that
	// deletes a webhook by unique ID.
	DeleteHook(int64) error

	// GetStepLog defines a function that
	// gets a step log by unique ID.
	GetStepLog(int64) (*library.Log, error)
	// GetServiceLog defines a function that
	// gets a service log by unique ID.
	GetServiceLog(int64) (*library.Log, error)
	// GetBuildLogs defines a function that
	// gets a list of logs by build ID.
	GetBuildLogs(int64) ([]*library.Log, error)
	// CreateLog defines a function that
	// creates a new log.
	CreateLog(*library.Log) error
	// UpdateLog defines a function that
	// updates a log.
	UpdateLog(*library.Log) error
	// DeleteLog defines a function that
	// deletes a log by unique ID.
	DeleteLog(int64) error

	// GetRepo defines a function that
	// gets a repo by org and name.
	GetRepo(string, string) (*library.Repo, error)
	// GetRepoList defines a function that
	// gets a list of all repos.
	GetRepoList() ([]*library.Repo, error)
	// GetOrgRepoList defines a function that
	// gets a list of all repos by org excluding repos specified.
	GetOrgRepoList(string, map[string]string, int, int) ([]*library.Repo, error)
	// GetOrgRepoCount defines a function that
	// gets the count of repos for an org.
	GetOrgRepoCount(string, map[string]string) (int64, error)
	// GetRepoCount defines a function that
	// gets the count of repos.
	GetRepoCount() (int64, error)
	// GetUserRepoList defines a function
	// that gets a list of repos by user ID.
	GetUserRepoList(*library.User, int, int) ([]*library.Repo, error)
	// GetUserRepoCount defines a function that
	// gets the count of repos for a user.
	GetUserRepoCount(*library.User) (int64, error)
	// CreateRepo defines a function that
	// creates a new repo.
	CreateRepo(*library.Repo) error
	// UpdateRepo defines a function that
	// updates a repo.
	UpdateRepo(*library.Repo) error
	// DeleteRepo defines a function that
	// deletes a repo by unique ID.
	DeleteRepo(int64) error

	// GetSecret defines a function that gets a secret
	// by type, org, name (repo or team) and secret name.
	GetSecret(string, string, string, string) (*library.Secret, error)
	// GetSecretList defines a function that
	// gets a list of all secrets.
	GetSecretList() ([]*library.Secret, error)
	// GetTypeSecretList defines a function that gets a list
	// of secrets by type, owner, and name (repo or team).
	GetTypeSecretList(string, string, string, int, int, []string) ([]*library.Secret, error)
	// GetTypeSecretCount defines a function that gets a count
	// of secrets by type, owner, and name (repo or team).
	GetTypeSecretCount(string, string, string, []string) (int64, error)
	// CreateSecret defines a function that
	// creates a new secret.
	CreateSecret(*library.Secret) error
	// UpdateSecret defines a function that
	// updates a secret.
	UpdateSecret(*library.Secret) error
	// DeleteSecret defines a function that
	// deletes a secret by unique ID.
	DeleteSecret(int64) error

	// GetStep defines a function that
	// gets a step by number and build ID.
	GetStep(int, *library.Build) (*library.Step, error)
	// GetStepList defines a function that
	// gets a list of all steps.
	GetStepList() ([]*library.Step, error)
	// GetBuildStepList defines a function that
	// gets a list of steps by build ID.
	GetBuildStepList(*library.Build, int, int) ([]*library.Step, error)
	// GetBuildStepCount defines a function that
	// gets the count of steps by build ID.
	GetBuildStepCount(*library.Build) (int64, error)
	// GetStepImageCount defines a function that
	// gets a list of all step images and the
	// count of their occurrence.
	GetStepImageCount() (map[string]float64, error)
	// GetStepStatusCount defines a function that
	// gets a list of all step statuses and the
	// count of their occurrence.
	GetStepStatusCount() (map[string]float64, error)
	// CreateStep defines a function that
	// creates a new step.
	CreateStep(*library.Step) error
	// UpdateStep defines a function that
	// updates a step.
	UpdateStep(*library.Step) error
	// DeleteStep defines a function that
	// deletes a step by unique ID.
	DeleteStep(int64) error

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

	// GetUser defines a function that
	// gets a user by unique ID.
	GetUser(int64) (*library.User, error)
	// GetUserName defines a function that
	// gets a user by name.
	GetUserName(string) (*library.User, error)
	// GetUserList defines a function that
	// gets a list of all users.
	GetUserList() ([]*library.User, error)
	// GetUserCount defines a function that
	// gets the count of users.
	GetUserCount() (int64, error)
	// GetUserLiteList defines a function
	// that gets a lite list of users.
	GetUserLiteList(int, int) ([]*library.User, error)
	// CreateUser defines a function that
	// creates a new user.
	CreateUser(*library.User) error
	// UpdateUser defines a function that
	// updates a user.
	UpdateUser(*library.User) error
	// DeleteUser defines a function that
	// deletes a user by unique ID.
	DeleteUser(int64) error

	// GetWorker defines a function that
	// gets a worker by hostname.
	GetWorker(string) (*library.Worker, error)
	// GetWorkerAddress defines a function that
	// gets a worker by address.
	GetWorkerByAddress(string) (*library.Worker, error)
	// GetWorkerList defines a function that
	// gets a list of all workers.
	GetWorkerList() ([]*library.Worker, error)
	// GetWorkerCount defines a function that
	// gets the count of workers.
	GetWorkerCount() (int64, error)
	// CreateWorker defines a function that
	// creates a new worker.
	CreateWorker(*library.Worker) error
	// UpdateWorker defines a function that
	// updates a worker by unique ID.
	UpdateWorker(*library.Worker) error
	// DeleteWorker defines a function that
	// deletes a worker by hostname.
	DeleteWorker(int64) error
}

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)

nolint: godot // top level comment ends in a list

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