Skip to content

Conversation

@jbrockopp
Copy link
Contributor

@jbrockopp jbrockopp commented Jun 1, 2023

Based off of #574, #663, #687, #692, #721, #722, #782, #810, #816 and #858

This change continues the refactor efforts initially introduced in the above PRs.

Those PRs ensured we leverage our DB library's (GORM) agnostic abstraction for integrating with a database.

Now, we can begin the efforts to create an agnostic engine that will be shared across all drivers:

// engine represents the functionality that implements the Interface.
engine struct {
Config *Config
Database *gorm.DB
Logger *logrus.Entry
build.BuildInterface
hook.HookInterface
log.LogInterface
pipeline.PipelineInterface
repo.RepoInterface
schedule.ScheduleInterface
secret.SecretInterface
service.ServiceInterface
step.StepInterface
user.UserInterface
worker.WorkerInterface
}

We also add a Config{} that currently mirrors the Setup{} (I think "config" is a better name compared to "setup"):

// Config represents the settings required to create the engine that implements the Interface.
Config struct {
// specifies the address to use for the database engine
Address string
// specifies the level of compression to use for the database engine
CompressionLevel int
// specifies the maximum idle connections for the database engine
ConnectionIdle int
// specifies the connection duration to use for the database engine
ConnectionLife time.Duration
// specifies the maximum open connections for the database engine
ConnectionOpen int
// specifies the driver to use for the database engine
Driver string
// specifies the encryption key to use for the database engine
EncryptionKey string
// specifies to skip creating tables and indexes for the database engine
SkipCreation bool
}

This will help ensure we reduce the amount of duplicate code across the currently supported drivers:

Also, this will lower the barrier to entry for adding support for future drivers assuming they are supported by GORM.

Basically, we're ensuring we leverage the full functionality our DB library (GORM) has to offer.

@jbrockopp jbrockopp added the feature Indicates a new feature label Jun 1, 2023
@jbrockopp jbrockopp self-assigned this Jun 1, 2023
@codecov
Copy link

codecov bot commented Jun 1, 2023

Codecov Report

Merging #868 (ab04f2f) into main (a5fc7c6) will increase coverage by 0.12%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #868      +/-   ##
==========================================
+ Coverage   71.92%   72.04%   +0.12%     
==========================================
  Files         307      310       +3     
  Lines       12872    12930      +58     
==========================================
+ Hits         9258     9316      +58     
  Misses       3168     3168              
  Partials      446      446              
Impacted Files Coverage Δ
database/database.go 100.00% <ø> (ø)
database/close.go 100.00% <100.00%> (ø)
database/driver.go 100.00% <100.00%> (ø)
database/validate.go 100.00% <100.00%> (ø)

@jbrockopp jbrockopp marked this pull request as ready for review June 1, 2023 02:52
@jbrockopp jbrockopp requested a review from a team as a code owner June 1, 2023 02:52
@plyr4 plyr4 merged commit a600274 into main Jun 2, 2023
@plyr4 plyr4 deleted the feature/database/engine branch June 2, 2023 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Indicates a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants