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 ¶
- Variables
- func ToContext(c Setter, d Interface)
- type EngineOpt
- func WithAddress(address string) EngineOpt
- func WithCompressionLevel(level int) EngineOpt
- func WithConnectionIdle(connectionIdle int) EngineOpt
- func WithConnectionLife(connectionLife time.Duration) EngineOpt
- func WithConnectionOpen(connectionOpen int) EngineOpt
- func WithContext(ctx context.Context) EngineOpt
- func WithDriver(driver string) EngineOpt
- func WithEncryptionKey(encryptionKey string) EngineOpt
- func WithLogLevel(logLevel string) EngineOpt
- func WithLogPartitionPattern(pattern string) EngineOpt
- func WithLogPartitionSchema(schema string) EngineOpt
- func WithLogPartitioned(partitioned bool) EngineOpt
- func WithLogShowSQL(logShowSQL bool) EngineOpt
- func WithLogSkipNotFound(logSkipNotFound bool) EngineOpt
- func WithLogSlowThreshold(logSlowThreshold time.Duration) EngineOpt
- func WithSkipCreation(skipCreation bool) EngineOpt
- func WithTracing(tracing *tracing.Client) EngineOpt
- type GormLogger
- func (l *GormLogger) Error(ctx context.Context, msg string, args ...interface{})
- func (l *GormLogger) Info(ctx context.Context, msg string, args ...interface{})
- func (l *GormLogger) LogMode(logger.LogLevel) logger.Interface
- func (l *GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)
- func (l *GormLogger) Warn(ctx context.Context, msg string, args ...interface{})
- type Interface
- type Setter
Constants ¶
This section is empty.
Variables ¶
var Flags = []cli.Flag{ &cli.StringFlag{ Name: "database.driver", Usage: "driver to be used for the database system", Sources: cli.NewValueSourceChain( cli.EnvVar("VELA_DATABASE_DRIVER"), cli.EnvVar("DATABASE_DRIVER"), cli.File("/vela/database/driver"), ), Value: "sqlite3", Action: func(_ context.Context, _ *cli.Command, v string) error { if len(v) == 0 { return fmt.Errorf("no database driver provided") } return nil }, }, &cli.StringFlag{ Name: "database.addr", Usage: "fully qualified url (<scheme>://<host>) for the database", Sources: cli.NewValueSourceChain( cli.EnvVar("VELA_DATABASE_ADDR"), cli.EnvVar("DATABASE_ADDR"), cli.File("/vela/database/addr"), ), Required: true, Action: func(_ context.Context, _ *cli.Command, v string) error { if strings.HasSuffix(v, "/") { return fmt.Errorf("invalid database address provided: address must not have trailing slash") } return nil }, }, &cli.IntFlag{ Name: "database.connection.open", Usage: "maximum number of open connections to the database", Sources: cli.NewValueSourceChain( cli.EnvVar("VELA_DATABASE_CONNECTION_OPEN"), cli.EnvVar("DATABASE_CONNECTION_OPEN"), cli.File("/vela/database/connection_open"), ), Value: 0, }, &cli.IntFlag{ Name: "database.connection.idle", Usage: "maximum number of idle connections to the database", Sources: cli.NewValueSourceChain( cli.EnvVar("VELA_DATABASE_CONNECTION_IDLE"), cli.EnvVar("DATABASE_CONNECTION_IDLE"), cli.File("/vela/database/connection_idle"), ), Value: 2, }, &cli.DurationFlag{ Name: "database.connection.life", Usage: "duration of time a connection may be reused for the database", Sources: cli.NewValueSourceChain( cli.EnvVar("VELA_DATABASE_CONNECTION_LIFE"), cli.EnvVar("DATABASE_CONNECTION_LIFE"), cli.File("/vela/database/connection_life"), ), Value: 30 * time.Minute, }, &cli.Int64Flag{ Name: "database.compression.level", Usage: "level of compression for logs stored in the database", Sources: cli.NewValueSourceChain( cli.EnvVar("VELA_DATABASE_COMPRESSION_LEVEL"), cli.EnvVar("DATABASE_COMPRESSION_LEVEL"), cli.File("/vela/database/compression_level"), ), Value: constants.CompressionThree, Action: func(_ context.Context, _ *cli.Command, v int64) error { switch v { case constants.CompressionNegOne: fallthrough case constants.CompressionZero: fallthrough case constants.CompressionOne: fallthrough case constants.CompressionTwo: fallthrough case constants.CompressionThree: fallthrough case constants.CompressionFour: fallthrough case constants.CompressionFive: fallthrough case constants.CompressionSix: fallthrough case constants.CompressionSeven: fallthrough case constants.CompressionEight: fallthrough case constants.CompressionNine: break default: return fmt.Errorf("invalid database compression level provided: level (%d) must be between %d and %d", v, constants.CompressionNegOne, constants.CompressionNine, ) } return nil }, }, &cli.StringFlag{ Name: "database.encryption.key", Usage: "AES-256 key for encrypting and decrypting values in the database", Sources: cli.NewValueSourceChain( cli.EnvVar("VELA_DATABASE_ENCRYPTION_KEY"), cli.EnvVar("DATABASE_ENCRYPTION_KEY"), cli.File("/vela/database/encryption_key"), ), Required: true, Action: func(_ context.Context, _ *cli.Command, v string) error { if len(v) != 32 { return fmt.Errorf("invalid database encryption key provided: key length (%d) must be 32 characters", len(v)) } return nil }, }, &cli.StringFlag{ Name: "database.log.level", Usage: "set log level - options: (trace|debug|info|warn|error|fatal|panic)", Sources: cli.NewValueSourceChain( cli.EnvVar("VELA_DATABASE_LOG_LEVEL"), cli.EnvVar("DATABASE_LOG_LEVEL"), cli.File("/vela/database/log_level"), ), Value: "warn", }, &cli.BoolFlag{ Name: "database.log.show_sql", Usage: "show the SQL query in the logs", Sources: cli.NewValueSourceChain( cli.EnvVar("VELA_DATABASE_LOG_SHOW_SQL"), cli.EnvVar("DATABASE_LOG_SHOW_SQL"), cli.File("/vela/database/log_show_sql"), ), }, &cli.BoolFlag{ Name: "database.log.skip_notfound", Usage: "skip logging when a resource is not found in the database", Sources: cli.NewValueSourceChain( cli.EnvVar("VELA_DATABASE_LOG_SKIP_NOTFOUND"), cli.EnvVar("DATABASE_LOG_SKIP_NOTFOUND"), cli.File("/vela/database/log_skip_notfound"), ), Value: true, }, &cli.DurationFlag{ Name: "database.log.slow_threshold", Usage: "queries that take longer than this threshold are considered slow and will be logged", Sources: cli.NewValueSourceChain( cli.EnvVar("VELA_DATABASE_LOG_SLOW_THRESHOLD"), cli.EnvVar("DATABASE_LOG_SLOW_THRESHOLD"), cli.File("/vela/database/log_slow_threshold"), ), Value: 200 * time.Millisecond, }, &cli.BoolFlag{ Name: "database.skip_creation", Usage: "enables skipping the creation of tables and indexes in the database", Sources: cli.NewValueSourceChain( cli.EnvVar("VELA_DATABASE_SKIP_CREATION"), cli.EnvVar("DATABASE_SKIP_CREATION"), cli.File("/vela/database/skip_creation"), ), }, &cli.BoolFlag{ Name: "database.log.partitioned", Usage: "enables partition-aware log cleanup for partitioned log tables", Sources: cli.NewValueSourceChain( cli.EnvVar("VELA_DATABASE_LOG_PARTITIONED"), cli.EnvVar("DATABASE_LOG_PARTITIONED"), cli.File("/vela/database/log_partitioned"), ), Value: false, }, &cli.StringFlag{ Name: "database.log.partition_pattern", Usage: "naming pattern for log table partitions (e.g., logs_%, logs_y%, logs_monthly_)", Sources: cli.NewValueSourceChain( cli.EnvVar("VELA_DATABASE_LOG_PARTITION_PATTERN"), cli.EnvVar("DATABASE_LOG_PARTITION_PATTERN"), cli.File("/vela/database/log_partition_pattern"), ), Value: "logs_%", }, &cli.StringFlag{ Name: "database.log.partition_schema", Usage: "database schema containing log table partitions", Sources: cli.NewValueSourceChain( cli.EnvVar("VELA_DATABASE_LOG_PARTITION_SCHEMA"), cli.EnvVar("DATABASE_LOG_PARTITION_SCHEMA"), cli.File("/vela/database/log_partition_schema"), ), Value: "public", }, }
Flags represents all supported command line interface (CLI) flags for the database.
Functions ¶
Types ¶
type EngineOpt ¶ added in v0.20.0
type EngineOpt func(*engine) error
EngineOpt represents a configuration option to initialize the database engine.
func WithAddress ¶ added in v0.20.0
WithAddress sets the address in the database engine.
func WithCompressionLevel ¶ added in v0.20.0
WithCompressionLevel sets the compression level in the database engine.
func WithConnectionIdle ¶ added in v0.20.0
WithConnectionIdle sets the idle connections in the database engine.
func WithConnectionLife ¶ added in v0.20.0
WithConnectionLife sets the life of connections in the database engine.
func WithConnectionOpen ¶ added in v0.20.0
WithConnectionOpen sets the open connections in the database engine.
func WithContext ¶ added in v0.21.0
WithContext sets the context in the database engine.
func WithDriver ¶ added in v0.20.0
WithDriver sets the driver in the database engine.
func WithEncryptionKey ¶ added in v0.20.0
WithEncryptionKey sets the encryption key in the database engine.
func WithLogLevel ¶ added in v0.24.0
WithLogLevel sets the log level in the database engine.
func WithLogPartitionPattern ¶ added in v0.27.0
WithLogPartitionPattern sets the log partition pattern in the database engine.
func WithLogPartitionSchema ¶ added in v0.27.0
WithLogPartitionSchema sets the log partition schema in the database engine.
func WithLogPartitioned ¶ added in v0.27.0
WithLogPartitioned sets the log partitioned flag in the database engine.
func WithLogShowSQL ¶ added in v0.24.0
WithLogShowSQL sets the log show SQL option in the database engine.
func WithLogSkipNotFound ¶ added in v0.24.0
WithLogSkipNotFound sets the log skip not found option in the database engine.
func WithLogSlowThreshold ¶ added in v0.24.0
WithLogSlowThreshold sets the log slow query threshold in the database engine.
func WithSkipCreation ¶ added in v0.20.0
WithSkipCreation sets the skip creation logic in the database engine.
func WithTracing ¶ added in v0.25.0
WithTracing sets the shared tracing config in the database engine.
type GormLogger ¶ added in v0.24.0
type GormLogger struct {
// contains filtered or unexported fields
}
GormLogger is a custom logger for Gorm.
func NewGormLogger ¶ added in v0.24.0
func NewGormLogger(logger *logrus.Entry, slowThreshold time.Duration, skipNotFound, showSQL bool) *GormLogger
NewGormLogger creates a new Gorm logger.
func (*GormLogger) Error ¶ added in v0.24.0
func (l *GormLogger) Error(ctx context.Context, msg string, args ...interface{})
Error implements the logger.Interface.
func (*GormLogger) Info ¶ added in v0.24.0
func (l *GormLogger) Info(ctx context.Context, msg string, args ...interface{})
Info implements the logger.Interface.
func (*GormLogger) LogMode ¶ added in v0.24.0
func (l *GormLogger) LogMode(logger.LogLevel) logger.Interface
LogMode sets the log mode for the logger.
type Interface ¶ added in v0.20.0
type Interface interface { // Close defines a function that stops and terminates the connection to the database. Close() error // Driver defines a function that outputs the configured database driver. Driver() string // Ping defines a function that sends a "ping" request to the configured database. Ping() error // IsLogPartitioned defines a function that returns whether log partitioning is enabled. IsLogPartitioned() bool // SettingsInterface defines the interface for platform settings stored in the database. settings.SettingsInterface // BuildInterface defines the interface for builds stored in the database. build.BuildInterface // BuildExecutableInterface defines the interface for build executables stored in the database. executable.BuildExecutableInterface // DashboardInterface defines the interface for builds store in the database. dashboard.DashboardInterface // DeploymentInterface defines the interface for deployments stored in the database. deployment.DeploymentInterface // HookInterface defines the interface for hooks stored in the database. hook.HookInterface // JWKInterface defines the interface for JWKs stored in the database. jwk.JWKInterface // LogInterface defines the interface for logs stored in the database. log.LogInterface // PipelineInterface defines the interface for pipelines stored in the database. pipeline.PipelineInterface // RepoInterface defines the interface for repos stored in the database. repo.RepoInterface // ScheduleInterface defines the interface for schedules stored in the database. schedule.ScheduleInterface // SecretInterface defines the interface for secrets stored in the database. secret.SecretInterface // ServiceInterface defines the interface for services stored in the database. service.ServiceInterface // StepInterface defines the interface for steps stored in the database. step.StepInterface // UserInterface defines the interface for users stored in the database. user.UserInterface // WorkerInterface defines the interface for workers stored in the database. worker.WorkerInterface }
Interface represents the interface for integrating with the supported database providers.
func FromCLICommand ¶ added in v0.27.0
FromCLICommand creates and returns a database engine from the urfave/cli context.
func FromContext ¶
FromContext returns the database Interface associated with this context.