diff --git a/database/build/clean.go b/database/build/clean.go index b7d876d16..81a461469 100644 --- a/database/build/clean.go +++ b/database/build/clean.go @@ -26,6 +26,7 @@ func (e *engine) CleanBuilds(ctx context.Context, msg string, before int64) (int // send query to the database result := e.client. + WithContext(ctx). Table(constants.TableBuild). Where("created < ?", before). Where("status = 'running' OR status = 'pending'"). diff --git a/database/build/count.go b/database/build/count.go index 3e86611d9..6b26c3f28 100644 --- a/database/build/count.go +++ b/database/build/count.go @@ -17,6 +17,7 @@ func (e *engine) CountBuilds(ctx context.Context) (int64, error) { // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableBuild). Count(&b). Error diff --git a/database/build/count_deployment.go b/database/build/count_deployment.go index 46c8170fc..e00151cac 100644 --- a/database/build/count_deployment.go +++ b/database/build/count_deployment.go @@ -22,6 +22,7 @@ func (e *engine) CountBuildsForDeployment(ctx context.Context, d *library.Deploy // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableBuild). Where("source = ?", d.GetURL()). Where(filters). diff --git a/database/build/count_org.go b/database/build/count_org.go index d9f4105ed..5a349c730 100644 --- a/database/build/count_org.go +++ b/database/build/count_org.go @@ -21,6 +21,7 @@ func (e *engine) CountBuildsForOrg(ctx context.Context, org string, filters map[ // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableBuild). Joins("JOIN repos ON builds.repo_id = repos.id"). Where("repos.org = ?", org). diff --git a/database/build/count_repo.go b/database/build/count_repo.go index 298420caa..138b4d6d4 100644 --- a/database/build/count_repo.go +++ b/database/build/count_repo.go @@ -23,6 +23,7 @@ func (e *engine) CountBuildsForRepo(ctx context.Context, r *api.Repo, filters ma // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableBuild). Where("repo_id = ?", r.GetID()). Where(filters). diff --git a/database/build/count_status.go b/database/build/count_status.go index 524d27d76..8fb401ffb 100644 --- a/database/build/count_status.go +++ b/database/build/count_status.go @@ -17,6 +17,7 @@ func (e *engine) CountBuildsForStatus(ctx context.Context, status string, filter // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableBuild). Where("status = ?", status). Where(filters). diff --git a/database/build/create.go b/database/build/create.go index 3a3684102..7789434cb 100644 --- a/database/build/create.go +++ b/database/build/create.go @@ -30,7 +30,10 @@ func (e *engine) CreateBuild(ctx context.Context, b *api.Build) (*api.Build, err build = build.Crop() // send query to the database - err = e.client.Table(constants.TableBuild).Create(build).Error + err = e.client. + WithContext(ctx). + Table(constants.TableBuild). + Create(build).Error if err != nil { return nil, err } diff --git a/database/build/delete.go b/database/build/delete.go index 2bcb282e4..f03387a5f 100644 --- a/database/build/delete.go +++ b/database/build/delete.go @@ -22,6 +22,7 @@ func (e *engine) DeleteBuild(ctx context.Context, b *api.Build) error { // send query to the database return e.client. + WithContext(ctx). Table(constants.TableBuild). Delete(build). Error diff --git a/database/build/get.go b/database/build/get.go index caaf1fe0c..dc7f0e2de 100644 --- a/database/build/get.go +++ b/database/build/get.go @@ -19,6 +19,7 @@ func (e *engine) GetBuild(ctx context.Context, id int64) (*api.Build, error) { // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableBuild). Preload("Repo"). Preload("Repo.Owner"). diff --git a/database/build/get_repo.go b/database/build/get_repo.go index b144cf432..8ac935881 100644 --- a/database/build/get_repo.go +++ b/database/build/get_repo.go @@ -25,6 +25,7 @@ func (e *engine) GetBuildForRepo(ctx context.Context, r *api.Repo, number int) ( // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableBuild). Preload("Repo"). Preload("Repo.Owner"). diff --git a/database/build/index.go b/database/build/index.go index 446395cc9..f224ccacc 100644 --- a/database/build/index.go +++ b/database/build/index.go @@ -47,23 +47,31 @@ func (e *engine) CreateBuildIndexes(ctx context.Context) error { e.logger.Tracef("creating indexes for builds table") // create the created column index for the builds table - err := e.client.Exec(CreateCreatedIndex).Error + err := e.client. + WithContext(ctx). + Exec(CreateCreatedIndex).Error if err != nil { return err } // create the repo_id column index for the builds table - err = e.client.Exec(CreateRepoIDIndex).Error + err = e.client. + WithContext(ctx). + Exec(CreateRepoIDIndex).Error if err != nil { return err } // create the source column index for the builds table - err = e.client.Exec(CreateSourceIndex).Error + err = e.client. + WithContext(ctx). + Exec(CreateSourceIndex).Error if err != nil { return err } // create the status column index for the builds table - return e.client.Exec(CreateStatusIndex).Error + return e.client. + WithContext(ctx). + Exec(CreateStatusIndex).Error } diff --git a/database/build/last_repo.go b/database/build/last_repo.go index fe04af158..ccade3cc8 100644 --- a/database/build/last_repo.go +++ b/database/build/last_repo.go @@ -26,6 +26,7 @@ func (e *engine) LastBuildForRepo(ctx context.Context, r *api.Repo, branch strin // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableBuild). Preload("Repo"). Preload("Repo.Owner"). diff --git a/database/build/list.go b/database/build/list.go index 9e3e45c8c..4074618c7 100644 --- a/database/build/list.go +++ b/database/build/list.go @@ -32,6 +32,7 @@ func (e *engine) ListBuilds(ctx context.Context) ([]*api.Build, error) { // send query to the database and store result in variable err = e.client. + WithContext(ctx). Preload("Repo"). Preload("Repo.Owner"). Table(constants.TableBuild). diff --git a/database/build/list_dashboard.go b/database/build/list_dashboard.go index 8ddc6fa57..7ba0c379a 100644 --- a/database/build/list_dashboard.go +++ b/database/build/list_dashboard.go @@ -23,7 +23,10 @@ func (e *engine) ListBuildsForDashboardRepo(ctx context.Context, r *api.Repo, br b := new([]types.Build) builds := []*api.Build{} - query := e.client.Table(constants.TableBuild).Where("repo_id = ?", r.GetID()) + query := e.client. + WithContext(ctx). + Table(constants.TableBuild). + Where("repo_id = ?", r.GetID()) if len(branches) > 0 { query = query.Where("branch IN (?)", branches) diff --git a/database/build/list_org.go b/database/build/list_org.go index cfaa1992d..d1c33a7a7 100644 --- a/database/build/list_org.go +++ b/database/build/list_org.go @@ -40,6 +40,7 @@ func (e *engine) ListBuildsForOrg(ctx context.Context, org string, filters map[s offset := perPage * (page - 1) err = e.client. + WithContext(ctx). Table(constants.TableBuild). Preload("Repo"). Preload("Repo.Owner"). diff --git a/database/build/list_pending_running.go b/database/build/list_pending_running.go index 858b9c08e..6a08dcbac 100644 --- a/database/build/list_pending_running.go +++ b/database/build/list_pending_running.go @@ -20,6 +20,7 @@ func (e *engine) ListPendingAndRunningBuilds(ctx context.Context, after string) // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableBuild). Select("builds.created, builds.number, builds.status, repos.full_name"). InnerJoins("INNER JOIN repos ON builds.repo_id = repos.id"). diff --git a/database/build/list_pending_running_repo.go b/database/build/list_pending_running_repo.go index cc8984265..f4028a57a 100644 --- a/database/build/list_pending_running_repo.go +++ b/database/build/list_pending_running_repo.go @@ -20,6 +20,7 @@ func (e *engine) ListPendingAndRunningBuildsForRepo(ctx context.Context, repo *a // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableBuild). Preload("Repo"). Preload("Repo.Owner"). diff --git a/database/build/list_repo.go b/database/build/list_repo.go index 2552c2ea3..880ea8e8c 100644 --- a/database/build/list_repo.go +++ b/database/build/list_repo.go @@ -41,6 +41,7 @@ func (e *engine) ListBuildsForRepo(ctx context.Context, r *api.Repo, filters map offset := perPage * (page - 1) err = e.client. + WithContext(ctx). Table(constants.TableBuild). Preload("Repo"). Preload("Repo.Owner"). diff --git a/database/build/table.go b/database/build/table.go index 8a7ae172c..2a7af528c 100644 --- a/database/build/table.go +++ b/database/build/table.go @@ -108,11 +108,15 @@ func (e *engine) CreateBuildTable(ctx context.Context, driver string) error { switch driver { case constants.DriverPostgres: // create the builds table for Postgres - return e.client.Exec(CreatePostgresTable).Error + return e.client. + WithContext(ctx). + Exec(CreatePostgresTable).Error case constants.DriverSqlite: fallthrough default: // create the builds table for Sqlite - return e.client.Exec(CreateSqliteTable).Error + return e.client. + WithContext(ctx). + Exec(CreateSqliteTable).Error } } diff --git a/database/build/update.go b/database/build/update.go index e8ff1f274..07b029093 100644 --- a/database/build/update.go +++ b/database/build/update.go @@ -30,7 +30,10 @@ func (e *engine) UpdateBuild(ctx context.Context, b *api.Build) (*api.Build, err build = build.Crop() // send query to the database - err = e.client.Table(constants.TableBuild).Save(build).Error + err = e.client. + WithContext(ctx). + Table(constants.TableBuild). + Save(build).Error if err != nil { return nil, err } diff --git a/database/dashboard/create.go b/database/dashboard/create.go index 1af56728a..5d49d574f 100644 --- a/database/dashboard/create.go +++ b/database/dashboard/create.go @@ -26,7 +26,10 @@ func (e *engine) CreateDashboard(ctx context.Context, d *api.Dashboard) (*api.Da } // send query to the database - result := e.client.Table(constants.TableDashboard).Create(dashboard) + result := e.client. + WithContext(ctx). + Table(constants.TableDashboard). + Create(dashboard) return dashboard.ToAPI(), result.Error } diff --git a/database/dashboard/delete.go b/database/dashboard/delete.go index 2f49cca9f..1e8c40434 100644 --- a/database/dashboard/delete.go +++ b/database/dashboard/delete.go @@ -22,6 +22,7 @@ func (e *engine) DeleteDashboard(ctx context.Context, d *api.Dashboard) error { // send query to the database return e.client. + WithContext(ctx). Table(constants.TableDashboard). Delete(dashboard). Error diff --git a/database/dashboard/get.go b/database/dashboard/get.go index 7c29c987f..d6d8f1f21 100644 --- a/database/dashboard/get.go +++ b/database/dashboard/get.go @@ -19,6 +19,7 @@ func (e *engine) GetDashboard(ctx context.Context, id string) (*api.Dashboard, e // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableDashboard). Where("id = ?", id). Take(d). diff --git a/database/dashboard/table.go b/database/dashboard/table.go index 1cedb30c3..cef302382 100644 --- a/database/dashboard/table.go +++ b/database/dashboard/table.go @@ -50,11 +50,15 @@ func (e *engine) CreateDashboardTable(ctx context.Context, driver string) error switch driver { case constants.DriverPostgres: // create the dashboards table for Postgres - return e.client.Exec(CreatePostgresTable).Error + return e.client. + WithContext(ctx). + Exec(CreatePostgresTable).Error case constants.DriverSqlite: fallthrough default: // create the dashboards table for Sqlite - return e.client.Exec(CreateSqliteTable).Error + return e.client. + WithContext(ctx). + Exec(CreateSqliteTable).Error } } diff --git a/database/dashboard/update.go b/database/dashboard/update.go index e13387cb3..18089ff86 100644 --- a/database/dashboard/update.go +++ b/database/dashboard/update.go @@ -26,7 +26,10 @@ func (e *engine) UpdateDashboard(ctx context.Context, d *api.Dashboard) (*api.Da } // send query to the database - err = e.client.Table(constants.TableDashboard).Save(dashboard).Error + err = e.client. + WithContext(ctx). + Table(constants.TableDashboard). + Save(dashboard).Error if err != nil { return nil, err } diff --git a/database/deployment/count.go b/database/deployment/count.go index 26189cf10..f1c9e5b14 100644 --- a/database/deployment/count.go +++ b/database/deployment/count.go @@ -17,6 +17,7 @@ func (e *engine) CountDeployments(ctx context.Context) (int64, error) { // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableDeployment). Count(&d). Error diff --git a/database/deployment/count_repo.go b/database/deployment/count_repo.go index 94ed86558..8a2afd6fc 100644 --- a/database/deployment/count_repo.go +++ b/database/deployment/count_repo.go @@ -23,6 +23,7 @@ func (e *engine) CountDeploymentsForRepo(ctx context.Context, r *api.Repo) (int6 // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableDeployment). Where("repo_id = ?", r.GetID()). Count(&d). diff --git a/database/deployment/create.go b/database/deployment/create.go index c766596e8..923625bb6 100644 --- a/database/deployment/create.go +++ b/database/deployment/create.go @@ -27,7 +27,10 @@ func (e *engine) CreateDeployment(ctx context.Context, d *library.Deployment) (* return nil, err } - result := e.client.Table(constants.TableDeployment).Create(deployment) + result := e.client. + WithContext(ctx). + Table(constants.TableDeployment). + Create(deployment) // send query to the database return deployment.ToLibrary(d.Builds), result.Error diff --git a/database/deployment/delete.go b/database/deployment/delete.go index 606ef8262..cdb98fe31 100644 --- a/database/deployment/delete.go +++ b/database/deployment/delete.go @@ -23,6 +23,7 @@ func (e *engine) DeleteDeployment(ctx context.Context, d *library.Deployment) er // send query to the database return e.client. + WithContext(ctx). Table(constants.TableDeployment). Delete(deployment). Error diff --git a/database/deployment/get.go b/database/deployment/get.go index 214dcf57f..0086a03a2 100644 --- a/database/deployment/get.go +++ b/database/deployment/get.go @@ -20,6 +20,7 @@ func (e *engine) GetDeployment(ctx context.Context, id int64) (*library.Deployme // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableDeployment). Where("id = ?", id). Take(d). @@ -40,6 +41,7 @@ func (e *engine) GetDeployment(ctx context.Context, id int64) (*library.Deployme // send query to the database and store result in variable err = e.client. + WithContext(ctx). Table(constants.TableBuild). Where("id = ?", bID). Take(b). diff --git a/database/deployment/get_repo.go b/database/deployment/get_repo.go index 1558b0428..f50ef3aba 100644 --- a/database/deployment/get_repo.go +++ b/database/deployment/get_repo.go @@ -27,6 +27,7 @@ func (e *engine) GetDeploymentForRepo(ctx context.Context, r *api.Repo, number i // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableDeployment). Where("repo_id = ?", r.GetID()). Where("number = ?", number). @@ -48,6 +49,7 @@ func (e *engine) GetDeploymentForRepo(ctx context.Context, r *api.Repo, number i // send query to the database and store result in variable err = e.client. + WithContext(ctx). Table(constants.TableBuild). Where("id = ?", bID). Take(b). diff --git a/database/deployment/index.go b/database/deployment/index.go index f9b6a3419..c695313d0 100644 --- a/database/deployment/index.go +++ b/database/deployment/index.go @@ -20,5 +20,7 @@ func (e *engine) CreateDeploymentIndexes(ctx context.Context) error { e.logger.Tracef("creating indexes for deployments table") // create the repo_id column index for the deployments table - return e.client.Exec(CreateRepoIDIndex).Error + return e.client. + WithContext(ctx). + Exec(CreateRepoIDIndex).Error } diff --git a/database/deployment/list.go b/database/deployment/list.go index f395f668b..7f942f859 100644 --- a/database/deployment/list.go +++ b/database/deployment/list.go @@ -21,6 +21,7 @@ func (e *engine) ListDeployments(ctx context.Context) ([]*library.Deployment, er // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableDeployment). Find(&d). Error @@ -45,6 +46,7 @@ func (e *engine) ListDeployments(ctx context.Context) ([]*library.Deployment, er // send query to the database and store result in variable err = e.client. + WithContext(ctx). Table(constants.TableBuild). Where("id = ?", bID). Take(b). diff --git a/database/deployment/list_repo.go b/database/deployment/list_repo.go index 8f9b40eb4..4be4e071b 100644 --- a/database/deployment/list_repo.go +++ b/database/deployment/list_repo.go @@ -30,6 +30,7 @@ func (e *engine) ListDeploymentsForRepo(ctx context.Context, r *api.Repo, page, // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableDeployment). Where("repo_id = ?", r.GetID()). Order("number DESC"). @@ -58,6 +59,7 @@ func (e *engine) ListDeploymentsForRepo(ctx context.Context, r *api.Repo, page, // send query to the database and store result in variable err = e.client. + WithContext(ctx). Table(constants.TableBuild). Where("id = ?", bID). Take(b). diff --git a/database/deployment/table.go b/database/deployment/table.go index b519c8abf..9baef0284 100644 --- a/database/deployment/table.go +++ b/database/deployment/table.go @@ -62,11 +62,15 @@ func (e *engine) CreateDeploymentTable(ctx context.Context, driver string) error switch driver { case constants.DriverPostgres: // create the deployments table for Postgres - return e.client.Exec(CreatePostgresTable).Error + return e.client. + WithContext(ctx). + Exec(CreatePostgresTable).Error case constants.DriverSqlite: fallthrough default: // create the deployments table for Sqlite - return e.client.Exec(CreateSqliteTable).Error + return e.client. + WithContext(ctx). + Exec(CreateSqliteTable).Error } } diff --git a/database/deployment/update.go b/database/deployment/update.go index c2bbecff0..810450d79 100644 --- a/database/deployment/update.go +++ b/database/deployment/update.go @@ -27,7 +27,10 @@ func (e *engine) UpdateDeployment(ctx context.Context, d *library.Deployment) (* return nil, err } - result := e.client.Table(constants.TableDeployment).Save(deployment) + result := e.client. + WithContext(ctx). + Table(constants.TableDeployment). + Save(deployment) // send query to the database return deployment.ToLibrary(d.Builds), result.Error diff --git a/database/executable/clean.go b/database/executable/clean.go index b6bd2580a..ba4c06172 100644 --- a/database/executable/clean.go +++ b/database/executable/clean.go @@ -33,10 +33,16 @@ func (e *engine) CleanBuildExecutables(ctx context.Context) (int64, error) { switch e.config.Driver { case constants.DriverPostgres: - res := e.client.Exec(CleanExecutablesPostgres) + res := e.client. + WithContext(ctx). + Exec(CleanExecutablesPostgres) + return res.RowsAffected, res.Error default: - res := e.client.Exec(CleanExecutablesSqlite) + res := e.client. + WithContext(ctx). + Exec(CleanExecutablesSqlite) + return res.RowsAffected, res.Error } } diff --git a/database/executable/create.go b/database/executable/create.go index b619da068..e231f01fb 100644 --- a/database/executable/create.go +++ b/database/executable/create.go @@ -50,6 +50,7 @@ func (e *engine) CreateBuildExecutable(ctx context.Context, b *library.BuildExec // send query to the database return e.client. + WithContext(ctx). Table(constants.TableBuildExecutable). Create(executable). Error diff --git a/database/executable/pop.go b/database/executable/pop.go index 62dfde193..9625ad984 100644 --- a/database/executable/pop.go +++ b/database/executable/pop.go @@ -25,6 +25,7 @@ func (e *engine) PopBuildExecutable(ctx context.Context, id int64) (*library.Bui case constants.DriverPostgres: // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableBuildExecutable). Clauses(clause.Returning{}). Where("build_id = ?", id). @@ -37,6 +38,7 @@ func (e *engine) PopBuildExecutable(ctx context.Context, id int64) (*library.Bui case constants.DriverSqlite: // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableBuildExecutable). Where("id = ?", id). Take(b). @@ -47,6 +49,7 @@ func (e *engine) PopBuildExecutable(ctx context.Context, id int64) (*library.Bui // send query to the database to delete result just got err = e.client. + WithContext(ctx). Table(constants.TableBuildExecutable). Delete(b). Error diff --git a/database/executable/table.go b/database/executable/table.go index 9a683f245..0a7a3c147 100644 --- a/database/executable/table.go +++ b/database/executable/table.go @@ -42,11 +42,15 @@ func (e *engine) CreateBuildExecutableTable(ctx context.Context, driver string) switch driver { case constants.DriverPostgres: // create the build_executables table for Postgres - return e.client.Exec(CreatePostgresTable).Error + return e.client. + WithContext(ctx). + Exec(CreatePostgresTable).Error case constants.DriverSqlite: fallthrough default: // create the build_executables table for Sqlite - return e.client.Exec(CreateSqliteTable).Error + return e.client. + WithContext(ctx). + Exec(CreateSqliteTable).Error } } diff --git a/database/hook/count.go b/database/hook/count.go index ce02e6fa0..9f3e3c264 100644 --- a/database/hook/count.go +++ b/database/hook/count.go @@ -17,6 +17,7 @@ func (e *engine) CountHooks(ctx context.Context) (int64, error) { // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableHook). Count(&h). Error diff --git a/database/hook/count_repo.go b/database/hook/count_repo.go index aa794b5f1..456019fc1 100644 --- a/database/hook/count_repo.go +++ b/database/hook/count_repo.go @@ -23,6 +23,7 @@ func (e *engine) CountHooksForRepo(ctx context.Context, r *api.Repo) (int64, err // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableHook). Where("repo_id = ?", r.GetID()). Count(&h). diff --git a/database/hook/create.go b/database/hook/create.go index c260eb2b5..badb47e82 100644 --- a/database/hook/create.go +++ b/database/hook/create.go @@ -31,7 +31,10 @@ func (e *engine) CreateHook(ctx context.Context, h *library.Hook) (*library.Hook return nil, err } - result := e.client.Table(constants.TableHook).Create(hook) + result := e.client. + WithContext(ctx). + Table(constants.TableHook). + Create(hook) // send query to the database return hook.ToLibrary(), result.Error diff --git a/database/hook/delete.go b/database/hook/delete.go index 0245477af..6eab73780 100644 --- a/database/hook/delete.go +++ b/database/hook/delete.go @@ -25,6 +25,7 @@ func (e *engine) DeleteHook(ctx context.Context, h *library.Hook) error { // send query to the database return e.client. + WithContext(ctx). Table(constants.TableHook). Delete(hook). Error diff --git a/database/hook/get.go b/database/hook/get.go index 82e421dda..afe9b920d 100644 --- a/database/hook/get.go +++ b/database/hook/get.go @@ -19,6 +19,7 @@ func (e *engine) GetHook(ctx context.Context, id int64) (*library.Hook, error) { // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableHook). Where("id = ?", id). Take(h). diff --git a/database/hook/get_repo.go b/database/hook/get_repo.go index a88d593df..61afe28b2 100644 --- a/database/hook/get_repo.go +++ b/database/hook/get_repo.go @@ -26,6 +26,7 @@ func (e *engine) GetHookForRepo(ctx context.Context, r *api.Repo, number int) (* // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableHook). Where("repo_id = ?", r.GetID()). Where("number = ?", number). diff --git a/database/hook/get_webhook.go b/database/hook/get_webhook.go index 919092fd7..47ea57f6c 100644 --- a/database/hook/get_webhook.go +++ b/database/hook/get_webhook.go @@ -19,6 +19,7 @@ func (e *engine) GetHookByWebhookID(ctx context.Context, webhookID int64) (*libr // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableHook). Where("webhook_id = ?", webhookID). Take(h). diff --git a/database/hook/index.go b/database/hook/index.go index b86c9ac39..7f813ca8c 100644 --- a/database/hook/index.go +++ b/database/hook/index.go @@ -20,5 +20,7 @@ func (e *engine) CreateHookIndexes(ctx context.Context) error { e.logger.Tracef("creating indexes for hooks table") // create the repo_id column index for the hooks table - return e.client.Exec(CreateRepoIDIndex).Error + return e.client. + WithContext(ctx). + Exec(CreateRepoIDIndex).Error } diff --git a/database/hook/last_repo.go b/database/hook/last_repo.go index 710053ad8..776f9b6c0 100644 --- a/database/hook/last_repo.go +++ b/database/hook/last_repo.go @@ -27,6 +27,7 @@ func (e *engine) LastHookForRepo(ctx context.Context, r *api.Repo) (*library.Hoo // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableHook). Where("repo_id = ?", r.GetID()). Order("number DESC"). diff --git a/database/hook/list.go b/database/hook/list.go index fcfba1e28..3957f57f2 100644 --- a/database/hook/list.go +++ b/database/hook/list.go @@ -32,6 +32,7 @@ func (e *engine) ListHooks(ctx context.Context) ([]*library.Hook, error) { // send query to the database and store result in variable err = e.client. + WithContext(ctx). Table(constants.TableHook). Find(&h). Error diff --git a/database/hook/list_repo.go b/database/hook/list_repo.go index 28e80c03e..7d4487f63 100644 --- a/database/hook/list_repo.go +++ b/database/hook/list_repo.go @@ -41,6 +41,7 @@ func (e *engine) ListHooksForRepo(ctx context.Context, r *api.Repo, page, perPag // send query to the database and store result in variable err = e.client. + WithContext(ctx). Table(constants.TableHook). Where("repo_id = ?", r.GetID()). Order("id DESC"). diff --git a/database/hook/table.go b/database/hook/table.go index 81ef7157f..a5d8d46ea 100644 --- a/database/hook/table.go +++ b/database/hook/table.go @@ -64,11 +64,15 @@ func (e *engine) CreateHookTable(ctx context.Context, driver string) error { switch driver { case constants.DriverPostgres: // create the hooks table for Postgres - return e.client.Exec(CreatePostgresTable).Error + return e.client. + WithContext(ctx). + Exec(CreatePostgresTable).Error case constants.DriverSqlite: fallthrough default: // create the hooks table for Sqlite - return e.client.Exec(CreateSqliteTable).Error + return e.client. + WithContext(ctx). + Exec(CreateSqliteTable).Error } } diff --git a/database/hook/update.go b/database/hook/update.go index 16222a6d1..bd6fe93ef 100644 --- a/database/hook/update.go +++ b/database/hook/update.go @@ -31,7 +31,10 @@ func (e *engine) UpdateHook(ctx context.Context, h *library.Hook) (*library.Hook return nil, err } - result := e.client.Table(constants.TableHook).Save(hook) + result := e.client. + WithContext(ctx). + Table(constants.TableHook). + Save(hook) // send query to the database return hook.ToLibrary(), result.Error diff --git a/database/jwk/create.go b/database/jwk/create.go index 0ef8330b9..684f49b97 100644 --- a/database/jwk/create.go +++ b/database/jwk/create.go @@ -14,7 +14,7 @@ import ( ) // CreateJWK creates a new JWK in the database. -func (e *engine) CreateJWK(_ context.Context, j jwk.RSAPublicKey) error { +func (e *engine) CreateJWK(ctx context.Context, j jwk.RSAPublicKey) error { e.logger.WithFields(logrus.Fields{ "jwk": j.KeyID(), }).Tracef("creating key %s", j.KeyID()) @@ -23,5 +23,8 @@ func (e *engine) CreateJWK(_ context.Context, j jwk.RSAPublicKey) error { key.Active = sql.NullBool{Bool: true, Valid: true} // send query to the database - return e.client.Table(constants.TableJWK).Create(key).Error + return e.client. + WithContext(ctx). + Table(constants.TableJWK). + Create(key).Error } diff --git a/database/jwk/get.go b/database/jwk/get.go index b324ae3cc..a99dbbb63 100644 --- a/database/jwk/get.go +++ b/database/jwk/get.go @@ -12,7 +12,7 @@ import ( ) // GetActiveJWK gets a JWK by UUID (kid) from the database if active. -func (e *engine) GetActiveJWK(_ context.Context, id string) (jwk.RSAPublicKey, error) { +func (e *engine) GetActiveJWK(ctx context.Context, id string) (jwk.RSAPublicKey, error) { e.logger.Tracef("getting JWK key %s", id) // variable to store query results @@ -20,6 +20,7 @@ func (e *engine) GetActiveJWK(_ context.Context, id string) (jwk.RSAPublicKey, e // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableJWK). Where("id = ?", id). Where("active = ?", true). diff --git a/database/jwk/list.go b/database/jwk/list.go index 4c29a4c5c..8de0fcf63 100644 --- a/database/jwk/list.go +++ b/database/jwk/list.go @@ -12,7 +12,7 @@ import ( ) // ListJWKs gets a list of all configured JWKs from the database. -func (e *engine) ListJWKs(_ context.Context) (jwk.Set, error) { +func (e *engine) ListJWKs(ctx context.Context) (jwk.Set, error) { e.logger.Trace("listing all JWKs") k := new([]types.JWK) @@ -20,6 +20,7 @@ func (e *engine) ListJWKs(_ context.Context) (jwk.Set, error) { // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableJWK). Find(&k). Error diff --git a/database/jwk/rotate.go b/database/jwk/rotate.go index 793584037..bcd4462ce 100644 --- a/database/jwk/rotate.go +++ b/database/jwk/rotate.go @@ -11,13 +11,14 @@ import ( ) // RotateKeys removes all inactive keys and sets active keys to inactive. -func (e *engine) RotateKeys(_ context.Context) error { +func (e *engine) RotateKeys(ctx context.Context) error { e.logger.Trace("rotating jwks") k := types.JWK{} // remove inactive keys err := e.client. + WithContext(ctx). Table(constants.TableJWK). Where("active = ?", false). Delete(&k). @@ -28,6 +29,7 @@ func (e *engine) RotateKeys(_ context.Context) error { // set active keys to inactive err = e.client. + WithContext(ctx). Table(constants.TableJWK). Where("active = ?", true). Update("active", sql.NullBool{Bool: false, Valid: true}). diff --git a/database/jwk/table.go b/database/jwk/table.go index b2a40c844..ee5895fcb 100644 --- a/database/jwk/table.go +++ b/database/jwk/table.go @@ -40,11 +40,15 @@ func (e *engine) CreateJWKTable(ctx context.Context, driver string) error { switch driver { case constants.DriverPostgres: // create the jwks table for Postgres - return e.client.Exec(CreatePostgresTable).Error + return e.client. + WithContext(ctx). + Exec(CreatePostgresTable).Error case constants.DriverSqlite: fallthrough default: // create the jwks table for Sqlite - return e.client.Exec(CreateSqliteTable).Error + return e.client. + WithContext(ctx). + Exec(CreateSqliteTable).Error } } diff --git a/database/log/count.go b/database/log/count.go index e3b38b316..d31c37f62 100644 --- a/database/log/count.go +++ b/database/log/count.go @@ -17,6 +17,7 @@ func (e *engine) CountLogs(ctx context.Context) (int64, error) { // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableLog). Count(&l). Error diff --git a/database/log/count_build.go b/database/log/count_build.go index 524ff2960..36cd2984f 100644 --- a/database/log/count_build.go +++ b/database/log/count_build.go @@ -18,6 +18,7 @@ func (e *engine) CountLogsForBuild(ctx context.Context, b *api.Build) (int64, er // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableLog). Where("build_id = ?", b.GetID()). Count(&l). diff --git a/database/log/create.go b/database/log/create.go index fdabab63c..4d0ee3428 100644 --- a/database/log/create.go +++ b/database/log/create.go @@ -50,6 +50,7 @@ func (e *engine) CreateLog(ctx context.Context, l *library.Log) error { // send query to the database return e.client. + WithContext(ctx). Table(constants.TableLog). Create(log). Error diff --git a/database/log/delete.go b/database/log/delete.go index 31f4ea31e..394321159 100644 --- a/database/log/delete.go +++ b/database/log/delete.go @@ -27,6 +27,7 @@ func (e *engine) DeleteLog(ctx context.Context, l *library.Log) error { // send query to the database return e.client. + WithContext(ctx). Table(constants.TableLog). Delete(log). Error diff --git a/database/log/get.go b/database/log/get.go index 2a825a6da..cf66dbfd7 100644 --- a/database/log/get.go +++ b/database/log/get.go @@ -19,6 +19,7 @@ func (e *engine) GetLog(ctx context.Context, id int64) (*library.Log, error) { // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableLog). Where("id = ?", id). Take(l). diff --git a/database/log/get_service.go b/database/log/get_service.go index aac501801..ad4156a8d 100644 --- a/database/log/get_service.go +++ b/database/log/get_service.go @@ -20,6 +20,7 @@ func (e *engine) GetLogForService(ctx context.Context, s *library.Service) (*lib // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableLog). Where("service_id = ?", s.GetID()). Take(l). diff --git a/database/log/get_step.go b/database/log/get_step.go index f2ca4a3a1..6d0084712 100644 --- a/database/log/get_step.go +++ b/database/log/get_step.go @@ -20,6 +20,7 @@ func (e *engine) GetLogForStep(ctx context.Context, s *library.Step) (*library.L // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableLog). Where("step_id = ?", s.GetID()). Take(l). diff --git a/database/log/index.go b/database/log/index.go index 230a10d8b..1c9ff5736 100644 --- a/database/log/index.go +++ b/database/log/index.go @@ -20,5 +20,7 @@ func (e *engine) CreateLogIndexes(ctx context.Context) error { e.logger.Tracef("creating indexes for logs table") // create the build_id column index for the logs table - return e.client.Exec(CreateBuildIDIndex).Error + return e.client. + WithContext(ctx). + Exec(CreateBuildIDIndex).Error } diff --git a/database/log/list.go b/database/log/list.go index 367d8c15e..ed6ecdcb7 100644 --- a/database/log/list.go +++ b/database/log/list.go @@ -32,6 +32,7 @@ func (e *engine) ListLogs(ctx context.Context) ([]*library.Log, error) { // send query to the database and store result in variable err = e.client. + WithContext(ctx). Table(constants.TableLog). Find(&l). Error diff --git a/database/log/list_build.go b/database/log/list_build.go index 43c117916..f27798b78 100644 --- a/database/log/list_build.go +++ b/database/log/list_build.go @@ -36,6 +36,7 @@ func (e *engine) ListLogsForBuild(ctx context.Context, b *api.Build, page, perPa // send query to the database and store result in variable err = e.client. + WithContext(ctx). Table(constants.TableLog). Where("build_id = ?", b.GetID()). Order("service_id ASC NULLS LAST"). diff --git a/database/log/table.go b/database/log/table.go index 94ec398ff..fbf74cd28 100644 --- a/database/log/table.go +++ b/database/log/table.go @@ -50,11 +50,15 @@ func (e *engine) CreateLogTable(ctx context.Context, driver string) error { switch driver { case constants.DriverPostgres: // create the logs table for Postgres - return e.client.Exec(CreatePostgresTable).Error + return e.client. + WithContext(ctx). + Exec(CreatePostgresTable).Error case constants.DriverSqlite: fallthrough default: // create the logs table for Sqlite - return e.client.Exec(CreateSqliteTable).Error + return e.client. + WithContext(ctx). + Exec(CreateSqliteTable).Error } } diff --git a/database/log/update.go b/database/log/update.go index f7a148aae..ae9819e4a 100644 --- a/database/log/update.go +++ b/database/log/update.go @@ -50,6 +50,7 @@ func (e *engine) UpdateLog(ctx context.Context, l *library.Log) error { // send query to the database return e.client. + WithContext(ctx). Table(constants.TableLog). Save(log). Error diff --git a/database/pipeline/count.go b/database/pipeline/count.go index 3252f5edd..818982b52 100644 --- a/database/pipeline/count.go +++ b/database/pipeline/count.go @@ -17,6 +17,7 @@ func (e *engine) CountPipelines(ctx context.Context) (int64, error) { // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TablePipeline). Count(&p). Error diff --git a/database/pipeline/count_repo.go b/database/pipeline/count_repo.go index 6adf46984..147ae552b 100644 --- a/database/pipeline/count_repo.go +++ b/database/pipeline/count_repo.go @@ -23,6 +23,7 @@ func (e *engine) CountPipelinesForRepo(ctx context.Context, r *api.Repo) (int64, // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TablePipeline). Where("repo_id = ?", r.GetID()). Count(&p). diff --git a/database/pipeline/create.go b/database/pipeline/create.go index 4ee770b52..e2910e6a1 100644 --- a/database/pipeline/create.go +++ b/database/pipeline/create.go @@ -40,7 +40,10 @@ func (e *engine) CreatePipeline(ctx context.Context, p *library.Pipeline) (*libr } // send query to the database - err = e.client.Table(constants.TablePipeline).Create(pipeline).Error + err = e.client. + WithContext(ctx). + Table(constants.TablePipeline). + Create(pipeline).Error if err != nil { return nil, err } diff --git a/database/pipeline/delete.go b/database/pipeline/delete.go index b35cdd7d3..ff49a8406 100644 --- a/database/pipeline/delete.go +++ b/database/pipeline/delete.go @@ -25,6 +25,7 @@ func (e *engine) DeletePipeline(ctx context.Context, p *library.Pipeline) error // send query to the database return e.client. + WithContext(ctx). Table(constants.TablePipeline). Delete(pipeline). Error diff --git a/database/pipeline/get.go b/database/pipeline/get.go index 8e1c54b13..e685a9178 100644 --- a/database/pipeline/get.go +++ b/database/pipeline/get.go @@ -19,6 +19,7 @@ func (e *engine) GetPipeline(ctx context.Context, id int64) (*library.Pipeline, // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TablePipeline). Where("id = ?", id). Take(p). diff --git a/database/pipeline/get_repo.go b/database/pipeline/get_repo.go index 0fc493003..5724dd0a7 100644 --- a/database/pipeline/get_repo.go +++ b/database/pipeline/get_repo.go @@ -26,6 +26,7 @@ func (e *engine) GetPipelineForRepo(ctx context.Context, commit string, r *api.R // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TablePipeline). Where("repo_id = ?", r.GetID()). Where("\"commit\" = ?", commit). diff --git a/database/pipeline/index.go b/database/pipeline/index.go index f49ecb58a..4f0095f70 100644 --- a/database/pipeline/index.go +++ b/database/pipeline/index.go @@ -20,5 +20,7 @@ func (e *engine) CreatePipelineIndexes(ctx context.Context) error { e.logger.Tracef("creating indexes for pipelines table in the database") // create the repo_id column index for the pipelines table - return e.client.Exec(CreateRepoIDIndex).Error + return e.client. + WithContext(ctx). + Exec(CreateRepoIDIndex).Error } diff --git a/database/pipeline/list.go b/database/pipeline/list.go index fd9e077e0..12fac0bf1 100644 --- a/database/pipeline/list.go +++ b/database/pipeline/list.go @@ -32,6 +32,7 @@ func (e *engine) ListPipelines(ctx context.Context) ([]*library.Pipeline, error) // send query to the database and store result in variable err = e.client. + WithContext(ctx). Table(constants.TablePipeline). Find(&p). Error diff --git a/database/pipeline/list_repo.go b/database/pipeline/list_repo.go index 4f855c746..22e9032cb 100644 --- a/database/pipeline/list_repo.go +++ b/database/pipeline/list_repo.go @@ -42,6 +42,7 @@ func (e *engine) ListPipelinesForRepo(ctx context.Context, r *api.Repo, page, pe offset := perPage * (page - 1) err = e.client. + WithContext(ctx). Table(constants.TablePipeline). Where("repo_id = ?", r.GetID()). Limit(perPage). diff --git a/database/pipeline/table.go b/database/pipeline/table.go index eb399772c..919b1b652 100644 --- a/database/pipeline/table.go +++ b/database/pipeline/table.go @@ -66,11 +66,15 @@ func (e *engine) CreatePipelineTable(ctx context.Context, driver string) error { switch driver { case constants.DriverPostgres: // create the pipelines table for Postgres - return e.client.Exec(CreatePostgresTable).Error + return e.client. + WithContext(ctx). + Exec(CreatePostgresTable).Error case constants.DriverSqlite: fallthrough default: // create the pipelines table for Sqlite - return e.client.Exec(CreateSqliteTable).Error + return e.client. + WithContext(ctx). + Exec(CreateSqliteTable).Error } } diff --git a/database/pipeline/update.go b/database/pipeline/update.go index 37353d853..93cff9351 100644 --- a/database/pipeline/update.go +++ b/database/pipeline/update.go @@ -40,7 +40,10 @@ func (e *engine) UpdatePipeline(ctx context.Context, p *library.Pipeline) (*libr } // send query to the database - err = e.client.Table(constants.TablePipeline).Save(pipeline).Error + err = e.client. + WithContext(ctx). + Table(constants.TablePipeline). + Save(pipeline).Error if err != nil { return nil, err } diff --git a/database/repo/count.go b/database/repo/count.go index 165bf0f0b..6db509b06 100644 --- a/database/repo/count.go +++ b/database/repo/count.go @@ -17,6 +17,7 @@ func (e *engine) CountRepos(ctx context.Context) (int64, error) { // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableRepo). Count(&r). Error diff --git a/database/repo/count_org.go b/database/repo/count_org.go index 6e0ce6cb4..915a0d9a7 100644 --- a/database/repo/count_org.go +++ b/database/repo/count_org.go @@ -21,6 +21,7 @@ func (e *engine) CountReposForOrg(ctx context.Context, org string, filters map[s // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableRepo). Where("org = ?", org). Where(filters). diff --git a/database/repo/count_user.go b/database/repo/count_user.go index dfc002d9b..57f3ecb3c 100644 --- a/database/repo/count_user.go +++ b/database/repo/count_user.go @@ -22,6 +22,7 @@ func (e *engine) CountReposForUser(ctx context.Context, u *api.User, filters map // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableRepo). Where("user_id = ?", u.GetID()). Where(filters). diff --git a/database/repo/create.go b/database/repo/create.go index 166362de9..7500b4101 100644 --- a/database/repo/create.go +++ b/database/repo/create.go @@ -37,7 +37,10 @@ func (e *engine) CreateRepo(ctx context.Context, r *api.Repo) (*api.Repo, error) } // send query to the database - err = e.client.Table(constants.TableRepo).Create(repo).Error + err = e.client. + WithContext(ctx). + Table(constants.TableRepo). + Create(repo).Error if err != nil { return nil, err } diff --git a/database/repo/delete.go b/database/repo/delete.go index a12e2ec91..cfd6dffa3 100644 --- a/database/repo/delete.go +++ b/database/repo/delete.go @@ -24,6 +24,7 @@ func (e *engine) DeleteRepo(ctx context.Context, r *api.Repo) error { // send query to the database return e.client. + WithContext(ctx). Table(constants.TableRepo). Delete(repo). Error diff --git a/database/repo/get.go b/database/repo/get.go index d29ba16c8..15a301290 100644 --- a/database/repo/get.go +++ b/database/repo/get.go @@ -19,6 +19,7 @@ func (e *engine) GetRepo(ctx context.Context, id int64) (*api.Repo, error) { // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableRepo). Preload("Owner"). Where("id = ?", id). diff --git a/database/repo/get_org.go b/database/repo/get_org.go index e66b97b37..38b32d4ca 100644 --- a/database/repo/get_org.go +++ b/database/repo/get_org.go @@ -24,6 +24,7 @@ func (e *engine) GetRepoForOrg(ctx context.Context, org, name string) (*api.Repo // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableRepo). Preload("Owner"). Where("org = ?", org). diff --git a/database/repo/index.go b/database/repo/index.go index 9c97ad962..e4b236064 100644 --- a/database/repo/index.go +++ b/database/repo/index.go @@ -20,5 +20,7 @@ func (e *engine) CreateRepoIndexes(ctx context.Context) error { e.logger.Tracef("creating indexes for repos table") // create the org and name columns index for the repos table - return e.client.Exec(CreateOrgNameIndex).Error + return e.client. + WithContext(ctx). + Exec(CreateOrgNameIndex).Error } diff --git a/database/repo/list.go b/database/repo/list.go index abe27a434..980044d97 100644 --- a/database/repo/list.go +++ b/database/repo/list.go @@ -32,6 +32,7 @@ func (e *engine) ListRepos(ctx context.Context) ([]*api.Repo, error) { // send query to the database and store result in variable err = e.client. + WithContext(ctx). Table(constants.TableRepo). Preload("Owner"). Find(&r). diff --git a/database/repo/list_org.go b/database/repo/list_org.go index 016044744..1b39feea8 100644 --- a/database/repo/list_org.go +++ b/database/repo/list_org.go @@ -42,6 +42,7 @@ func (e *engine) ListReposForOrg(ctx context.Context, org, sortBy string, filter switch sortBy { case "latest": query := e.client. + WithContext(ctx). Table(constants.TableBuild). Select("repos.id, MAX(builds.created) AS latest_build"). Joins("INNER JOIN repos repos ON builds.repo_id = repos.id"). @@ -49,6 +50,7 @@ func (e *engine) ListReposForOrg(ctx context.Context, org, sortBy string, filter Group("repos.id") err = e.client. + WithContext(ctx). Table(constants.TableRepo). Preload("Owner"). Select("repos.*"). @@ -65,6 +67,7 @@ func (e *engine) ListReposForOrg(ctx context.Context, org, sortBy string, filter fallthrough default: err = e.client. + WithContext(ctx). Table(constants.TableRepo). Preload("Owner"). Where("org = ?", org). diff --git a/database/repo/list_user.go b/database/repo/list_user.go index f50374de1..997fe15f4 100644 --- a/database/repo/list_user.go +++ b/database/repo/list_user.go @@ -42,6 +42,7 @@ func (e *engine) ListReposForUser(ctx context.Context, u *api.User, sortBy strin switch sortBy { case "latest": query := e.client. + WithContext(ctx). Table(constants.TableBuild). Select("repos.id, MAX(builds.created) AS latest_build"). Joins("INNER JOIN repos repos ON builds.repo_id = repos.id"). @@ -49,6 +50,7 @@ func (e *engine) ListReposForUser(ctx context.Context, u *api.User, sortBy strin Group("repos.id") err = e.client. + WithContext(ctx). Table(constants.TableRepo). Preload("Owner"). Select("repos.*"). @@ -65,6 +67,7 @@ func (e *engine) ListReposForUser(ctx context.Context, u *api.User, sortBy strin fallthrough default: err = e.client. + WithContext(ctx). Table(constants.TableRepo). Preload("Owner"). Where("user_id = ?", u.GetID()). diff --git a/database/repo/table.go b/database/repo/table.go index 65bd21fb2..0b16bae94 100644 --- a/database/repo/table.go +++ b/database/repo/table.go @@ -78,11 +78,15 @@ func (e *engine) CreateRepoTable(ctx context.Context, driver string) error { switch driver { case constants.DriverPostgres: // create the repos table for Postgres - return e.client.Exec(CreatePostgresTable).Error + return e.client. + WithContext(ctx). + Exec(CreatePostgresTable).Error case constants.DriverSqlite: fallthrough default: // create the repos table for Sqlite - return e.client.Exec(CreateSqliteTable).Error + return e.client. + WithContext(ctx). + Exec(CreateSqliteTable).Error } } diff --git a/database/repo/update.go b/database/repo/update.go index 9a11b8010..05af67470 100644 --- a/database/repo/update.go +++ b/database/repo/update.go @@ -37,7 +37,10 @@ func (e *engine) UpdateRepo(ctx context.Context, r *api.Repo) (*api.Repo, error) } // send query to the database - err = e.client.Table(constants.TableRepo).Save(repo).Error + err = e.client. + WithContext(ctx). + Table(constants.TableRepo). + Save(repo).Error if err != nil { return nil, err } diff --git a/database/schedule/count.go b/database/schedule/count.go index 8da93e69f..e199e8ed0 100644 --- a/database/schedule/count.go +++ b/database/schedule/count.go @@ -17,6 +17,7 @@ func (e *engine) CountSchedules(ctx context.Context) (int64, error) { // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableSchedule). Count(&s). Error diff --git a/database/schedule/count_active.go b/database/schedule/count_active.go index be2dd9b5e..5aa6e7209 100644 --- a/database/schedule/count_active.go +++ b/database/schedule/count_active.go @@ -17,6 +17,7 @@ func (e *engine) CountActiveSchedules(ctx context.Context) (int64, error) { // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableSchedule). Where("active = ?", true). Count(&s). diff --git a/database/schedule/count_repo.go b/database/schedule/count_repo.go index 724ce19b3..41246b800 100644 --- a/database/schedule/count_repo.go +++ b/database/schedule/count_repo.go @@ -23,6 +23,7 @@ func (e *engine) CountSchedulesForRepo(ctx context.Context, r *api.Repo) (int64, // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableSchedule). Where("repo_id = ?", r.GetID()). Count(&s). diff --git a/database/schedule/create.go b/database/schedule/create.go index 9b349a7d1..891237c26 100644 --- a/database/schedule/create.go +++ b/database/schedule/create.go @@ -28,7 +28,10 @@ func (e *engine) CreateSchedule(ctx context.Context, s *api.Schedule) (*api.Sche } // send query to the database - err = e.client.Table(constants.TableSchedule).Create(schedule).Error + err = e.client. + WithContext(ctx). + Table(constants.TableSchedule). + Create(schedule).Error if err != nil { return nil, err } diff --git a/database/schedule/delete.go b/database/schedule/delete.go index bc63c2f10..8f28c1173 100644 --- a/database/schedule/delete.go +++ b/database/schedule/delete.go @@ -23,6 +23,7 @@ func (e *engine) DeleteSchedule(ctx context.Context, s *api.Schedule) error { // send query to the database return e.client. + WithContext(ctx). Table(constants.TableSchedule). Delete(schedule). Error diff --git a/database/schedule/get.go b/database/schedule/get.go index 1bcdc37cb..887d4e002 100644 --- a/database/schedule/get.go +++ b/database/schedule/get.go @@ -19,6 +19,7 @@ func (e *engine) GetSchedule(ctx context.Context, id int64) (*api.Schedule, erro // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableSchedule). Preload("Repo"). Preload("Repo.Owner"). diff --git a/database/schedule/get_repo.go b/database/schedule/get_repo.go index e940694a4..57c9f485a 100644 --- a/database/schedule/get_repo.go +++ b/database/schedule/get_repo.go @@ -25,6 +25,7 @@ func (e *engine) GetScheduleForRepo(ctx context.Context, r *api.Repo, name strin // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableSchedule). Preload("Repo"). Preload("Repo.Owner"). diff --git a/database/schedule/index.go b/database/schedule/index.go index 11834bf4f..b02543b93 100644 --- a/database/schedule/index.go +++ b/database/schedule/index.go @@ -20,5 +20,7 @@ func (e *engine) CreateScheduleIndexes(ctx context.Context) error { e.logger.Tracef("creating indexes for schedules table in the database") // create the repo_id column index for the schedules table - return e.client.Exec(CreateRepoIDIndex).Error + return e.client. + WithContext(ctx). + Exec(CreateRepoIDIndex).Error } diff --git a/database/schedule/list.go b/database/schedule/list.go index 4282f554a..44f548352 100644 --- a/database/schedule/list.go +++ b/database/schedule/list.go @@ -32,6 +32,7 @@ func (e *engine) ListSchedules(ctx context.Context) ([]*api.Schedule, error) { // send query to the database and store result in variable err = e.client. + WithContext(ctx). Table(constants.TableSchedule). Preload("Repo"). Preload("Repo.Owner"). diff --git a/database/schedule/list_active.go b/database/schedule/list_active.go index 84e575b1a..8952de929 100644 --- a/database/schedule/list_active.go +++ b/database/schedule/list_active.go @@ -32,6 +32,7 @@ func (e *engine) ListActiveSchedules(ctx context.Context) ([]*api.Schedule, erro // send query to the database and store result in variable err = e.client. + WithContext(ctx). Table(constants.TableSchedule). Preload("Repo"). Preload("Repo.Owner"). diff --git a/database/schedule/list_repo.go b/database/schedule/list_repo.go index 9ec086589..38e0d1b3e 100644 --- a/database/schedule/list_repo.go +++ b/database/schedule/list_repo.go @@ -40,6 +40,7 @@ func (e *engine) ListSchedulesForRepo(ctx context.Context, r *api.Repo, page, pe // send query to the database and store result in variable err = e.client. + WithContext(ctx). Table(constants.TableSchedule). Preload("Repo"). Preload("Repo.Owner"). diff --git a/database/schedule/table.go b/database/schedule/table.go index 82ae8fdaf..86eda10bc 100644 --- a/database/schedule/table.go +++ b/database/schedule/table.go @@ -60,11 +60,15 @@ func (e *engine) CreateScheduleTable(ctx context.Context, driver string) error { switch driver { case constants.DriverPostgres: // create the schedules table for Postgres - return e.client.Exec(CreatePostgresTable).Error + return e.client. + WithContext(ctx). + Exec(CreatePostgresTable).Error case constants.DriverSqlite: fallthrough default: // create the schedules table for Sqlite - return e.client.Exec(CreateSqliteTable).Error + return e.client. + WithContext(ctx). + Exec(CreateSqliteTable).Error } } diff --git a/database/schedule/update.go b/database/schedule/update.go index 7dcc1256d..d2f9cbf33 100644 --- a/database/schedule/update.go +++ b/database/schedule/update.go @@ -32,9 +32,16 @@ func (e *engine) UpdateSchedule(ctx context.Context, s *api.Schedule, fields boo // we do this because Gorm will automatically set `updated_at` with the Save function // and the `updated_at` field should reflect the last time a user updated the record, rather than the scheduler if fields { - err = e.client.Table(constants.TableSchedule).Save(schedule).Error + err = e.client. + WithContext(ctx). + Table(constants.TableSchedule). + Save(schedule).Error } else { - err = e.client.Table(constants.TableSchedule).Model(schedule).UpdateColumn("scheduled_at", s.GetScheduledAt()).Error + err = e.client. + WithContext(ctx). + Table(constants.TableSchedule). + Model(schedule). + UpdateColumn("scheduled_at", s.GetScheduledAt()).Error } if err != nil { diff --git a/database/secret/count.go b/database/secret/count.go index bf91525fa..2b9b36ad0 100644 --- a/database/secret/count.go +++ b/database/secret/count.go @@ -17,6 +17,7 @@ func (e *engine) CountSecrets(ctx context.Context) (int64, error) { // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableSecret). Count(&s). Error diff --git a/database/secret/count_org.go b/database/secret/count_org.go index 9b4a8c263..85fb17624 100644 --- a/database/secret/count_org.go +++ b/database/secret/count_org.go @@ -22,6 +22,7 @@ func (e *engine) CountSecretsForOrg(ctx context.Context, org string, filters map // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableSecret). Where("type = ?", constants.SecretOrg). Where("org = ?", org). diff --git a/database/secret/count_repo.go b/database/secret/count_repo.go index b8edddcb0..6430f7fe9 100644 --- a/database/secret/count_repo.go +++ b/database/secret/count_repo.go @@ -24,6 +24,7 @@ func (e *engine) CountSecretsForRepo(ctx context.Context, r *api.Repo, filters m // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableSecret). Where("type = ?", constants.SecretRepo). Where("org = ?", r.GetOrg()). diff --git a/database/secret/count_team.go b/database/secret/count_team.go index 1b5fc8361..af158dcbc 100644 --- a/database/secret/count_team.go +++ b/database/secret/count_team.go @@ -24,6 +24,7 @@ func (e *engine) CountSecretsForTeam(ctx context.Context, org, team string, filt // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableSecret). Where("type = ?", constants.SecretShared). Where("org = ?", org). @@ -56,6 +57,7 @@ func (e *engine) CountSecretsForTeams(ctx context.Context, org string, teams []s // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableSecret). Where("type = ?", constants.SecretShared). Where("org = ?", org). diff --git a/database/secret/create.go b/database/secret/create.go index be409d304..163e72776 100644 --- a/database/secret/create.go +++ b/database/secret/create.go @@ -61,7 +61,10 @@ func (e *engine) CreateSecret(ctx context.Context, s *library.Secret) (*library. } // create secret record - result := e.client.Table(constants.TableSecret).Create(secret.Nullify()) + result := e.client. + WithContext(ctx). + Table(constants.TableSecret). + Create(secret.Nullify()) if result.Error != nil { return nil, result.Error diff --git a/database/secret/delete.go b/database/secret/delete.go index bc3cba36f..aa87ba1ea 100644 --- a/database/secret/delete.go +++ b/database/secret/delete.go @@ -41,6 +41,7 @@ func (e *engine) DeleteSecret(ctx context.Context, s *library.Secret) error { // send query to the database return e.client. + WithContext(ctx). Table(constants.TableSecret). Delete(secret). Error diff --git a/database/secret/get.go b/database/secret/get.go index 6f5bc7bf9..4f4d04199 100644 --- a/database/secret/get.go +++ b/database/secret/get.go @@ -19,6 +19,7 @@ func (e *engine) GetSecret(ctx context.Context, id int64) (*library.Secret, erro // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableSecret). Where("id = ?", id). Take(s). diff --git a/database/secret/get_org.go b/database/secret/get_org.go index 7d1766c88..473d5a1a6 100644 --- a/database/secret/get_org.go +++ b/database/secret/get_org.go @@ -25,6 +25,7 @@ func (e *engine) GetSecretForOrg(ctx context.Context, org, name string) (*librar // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableSecret). Where("type = ?", constants.SecretOrg). Where("org = ?", org). diff --git a/database/secret/get_repo.go b/database/secret/get_repo.go index 690823c08..27a5f3cfb 100644 --- a/database/secret/get_repo.go +++ b/database/secret/get_repo.go @@ -27,6 +27,7 @@ func (e *engine) GetSecretForRepo(ctx context.Context, name string, r *api.Repo) // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableSecret). Where("type = ?", constants.SecretRepo). Where("org = ?", r.GetOrg()). diff --git a/database/secret/get_team.go b/database/secret/get_team.go index e03845947..ee82409c6 100644 --- a/database/secret/get_team.go +++ b/database/secret/get_team.go @@ -26,6 +26,7 @@ func (e *engine) GetSecretForTeam(ctx context.Context, org, team, name string) ( // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableSecret). Where("type = ?", constants.SecretShared). Where("org = ?", org). diff --git a/database/secret/index.go b/database/secret/index.go index e045031bb..786cad40a 100644 --- a/database/secret/index.go +++ b/database/secret/index.go @@ -36,17 +36,23 @@ func (e *engine) CreateSecretIndexes(ctx context.Context) error { e.logger.Tracef("creating indexes for secrets table") // create the type, org and repo columns index for the secrets table - err := e.client.Exec(CreateTypeOrgRepo).Error + err := e.client. + WithContext(ctx). + Exec(CreateTypeOrgRepo).Error if err != nil { return err } // create the type, org and team columns index for the secrets table - err = e.client.Exec(CreateTypeOrgTeam).Error + err = e.client. + WithContext(ctx). + Exec(CreateTypeOrgTeam).Error if err != nil { return err } // create the type and org columns index for the secrets table - return e.client.Exec(CreateTypeOrg).Error + return e.client. + WithContext(ctx). + Exec(CreateTypeOrg).Error } diff --git a/database/secret/list.go b/database/secret/list.go index a61e2088f..fe2031f89 100644 --- a/database/secret/list.go +++ b/database/secret/list.go @@ -32,6 +32,7 @@ func (e *engine) ListSecrets(ctx context.Context) ([]*library.Secret, error) { // send query to the database and store result in variable err = e.client. + WithContext(ctx). Table(constants.TableSecret). Find(&s). Error diff --git a/database/secret/list_org.go b/database/secret/list_org.go index d8c7ced5a..c75fa8f8d 100644 --- a/database/secret/list_org.go +++ b/database/secret/list_org.go @@ -42,6 +42,7 @@ func (e *engine) ListSecretsForOrg(ctx context.Context, org string, filters map[ // send query to the database and store result in variable err = e.client. + WithContext(ctx). Table(constants.TableSecret). Where("type = ?", constants.SecretOrg). Where("org = ?", org). diff --git a/database/secret/list_repo.go b/database/secret/list_repo.go index ef2fe546c..593139869 100644 --- a/database/secret/list_repo.go +++ b/database/secret/list_repo.go @@ -44,6 +44,7 @@ func (e *engine) ListSecretsForRepo(ctx context.Context, r *api.Repo, filters ma // send query to the database and store result in variable err = e.client. + WithContext(ctx). Table(constants.TableSecret). Where("type = ?", constants.SecretRepo). Where("org = ?", r.GetOrg()). diff --git a/database/secret/list_team.go b/database/secret/list_team.go index 93a5d6db1..2e2a5773c 100644 --- a/database/secret/list_team.go +++ b/database/secret/list_team.go @@ -44,6 +44,7 @@ func (e *engine) ListSecretsForTeam(ctx context.Context, org, team string, filte // send query to the database and store result in variable err = e.client. + WithContext(ctx). Table(constants.TableSecret). Where("type = ?", constants.SecretShared). Where("org = ?", org). @@ -120,6 +121,7 @@ func (e *engine) ListSecretsForTeams(ctx context.Context, org string, teams []st // send query to the database and store result in variable err = e.client. + WithContext(ctx). Table(constants.TableSecret). Where("type = ?", constants.SecretShared). Where("org = ?", org). diff --git a/database/secret/table.go b/database/secret/table.go index e696409c2..650a3f3f4 100644 --- a/database/secret/table.go +++ b/database/secret/table.go @@ -68,11 +68,15 @@ func (e *engine) CreateSecretTable(ctx context.Context, driver string) error { switch driver { case constants.DriverPostgres: // create the secrets table for Postgres - return e.client.Exec(CreatePostgresTable).Error + return e.client. + WithContext(ctx). + Exec(CreatePostgresTable).Error case constants.DriverSqlite: fallthrough default: // create the secrets table for Sqlite - return e.client.Exec(CreateSqliteTable).Error + return e.client. + WithContext(ctx). + Exec(CreateSqliteTable).Error } } diff --git a/database/secret/update.go b/database/secret/update.go index 0bb713e47..c046d18ed 100644 --- a/database/secret/update.go +++ b/database/secret/update.go @@ -60,7 +60,10 @@ func (e *engine) UpdateSecret(ctx context.Context, s *library.Secret) (*library. } } - err = e.client.Table(constants.TableSecret).Save(secret.Nullify()).Error + err = e.client. + WithContext(ctx). + Table(constants.TableSecret). + Save(secret.Nullify()).Error if err != nil { return nil, err } diff --git a/database/service/clean.go b/database/service/clean.go index b4becb0ad..d234b4478 100644 --- a/database/service/clean.go +++ b/database/service/clean.go @@ -26,6 +26,7 @@ func (e *engine) CleanServices(ctx context.Context, msg string, before int64) (i // send query to the database result := e.client. + WithContext(ctx). Table(constants.TableService). Where("created < ?", before). Where("status = 'running' OR status = 'pending'"). diff --git a/database/service/count.go b/database/service/count.go index f8bee25b1..86e76cfe2 100644 --- a/database/service/count.go +++ b/database/service/count.go @@ -17,6 +17,7 @@ func (e *engine) CountServices(ctx context.Context) (int64, error) { // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableService). Count(&s). Error diff --git a/database/service/count_build.go b/database/service/count_build.go index 1e84819a2..0f00403e2 100644 --- a/database/service/count_build.go +++ b/database/service/count_build.go @@ -22,6 +22,7 @@ func (e *engine) CountServicesForBuild(ctx context.Context, b *api.Build, filter // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableService). Where("build_id = ?", b.GetID()). Where(filters). diff --git a/database/service/create.go b/database/service/create.go index 6d2ec8f74..3ecb96e04 100644 --- a/database/service/create.go +++ b/database/service/create.go @@ -32,7 +32,10 @@ func (e *engine) CreateService(ctx context.Context, s *library.Service) (*librar } // send query to the database - result := e.client.Table(constants.TableService).Create(service) + result := e.client. + WithContext(ctx). + Table(constants.TableService). + Create(service) return service.ToLibrary(), result.Error } diff --git a/database/service/delete.go b/database/service/delete.go index 3f0bd331e..835a25992 100644 --- a/database/service/delete.go +++ b/database/service/delete.go @@ -25,6 +25,7 @@ func (e *engine) DeleteService(ctx context.Context, s *library.Service) error { // send query to the database return e.client. + WithContext(ctx). Table(constants.TableService). Delete(service). Error diff --git a/database/service/get.go b/database/service/get.go index eee921123..37cf9a5d0 100644 --- a/database/service/get.go +++ b/database/service/get.go @@ -19,6 +19,7 @@ func (e *engine) GetService(ctx context.Context, id int64) (*library.Service, er // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableService). Where("id = ?", id). Take(s). diff --git a/database/service/get_build.go b/database/service/get_build.go index 81a95e0bc..e85ddc368 100644 --- a/database/service/get_build.go +++ b/database/service/get_build.go @@ -25,6 +25,7 @@ func (e *engine) GetServiceForBuild(ctx context.Context, b *api.Build, number in // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableService). Where("build_id = ?", b.GetID()). Where("number = ?", number). diff --git a/database/service/list.go b/database/service/list.go index 656beee10..6dd70fdd1 100644 --- a/database/service/list.go +++ b/database/service/list.go @@ -32,6 +32,7 @@ func (e *engine) ListServices(ctx context.Context) ([]*library.Service, error) { // send query to the database and store result in variable err = e.client. + WithContext(ctx). Table(constants.TableService). Find(&w). Error diff --git a/database/service/list_build.go b/database/service/list_build.go index 047aba669..faf8c81fb 100644 --- a/database/service/list_build.go +++ b/database/service/list_build.go @@ -40,6 +40,7 @@ func (e *engine) ListServicesForBuild(ctx context.Context, b *api.Build, filters // send query to the database and store result in variable err = e.client. + WithContext(ctx). Table(constants.TableService). Where("build_id = ?", b.GetID()). Where(filters). diff --git a/database/service/list_image.go b/database/service/list_image.go index a94447e6c..dbff3913c 100644 --- a/database/service/list_image.go +++ b/database/service/list_image.go @@ -22,6 +22,7 @@ func (e *engine) ListServiceImageCount(ctx context.Context) (map[string]float64, // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableService). Select("image", " count(image) as count"). Group("image"). diff --git a/database/service/list_status.go b/database/service/list_status.go index 9e5f106fd..b2570b55d 100644 --- a/database/service/list_status.go +++ b/database/service/list_status.go @@ -28,6 +28,7 @@ func (e *engine) ListServiceStatusCount(ctx context.Context) (map[string]float64 // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableService). Select("status", " count(status) as count"). Group("status"). diff --git a/database/service/table.go b/database/service/table.go index 56e78b249..426eb2333 100644 --- a/database/service/table.go +++ b/database/service/table.go @@ -66,11 +66,15 @@ func (e *engine) CreateServiceTable(ctx context.Context, driver string) error { switch driver { case constants.DriverPostgres: // create the services table for Postgres - return e.client.Exec(CreatePostgresTable).Error + return e.client. + WithContext(ctx). + Exec(CreatePostgresTable).Error case constants.DriverSqlite: fallthrough default: // create the services table for Sqlite - return e.client.Exec(CreateSqliteTable).Error + return e.client. + WithContext(ctx). + Exec(CreateSqliteTable).Error } } diff --git a/database/service/update.go b/database/service/update.go index 6eb43a7e2..a53b9ae41 100644 --- a/database/service/update.go +++ b/database/service/update.go @@ -32,7 +32,10 @@ func (e *engine) UpdateService(ctx context.Context, s *library.Service) (*librar } // send query to the database - result := e.client.Table(constants.TableService).Save(service) + result := e.client. + WithContext(ctx). + Table(constants.TableService). + Save(service) return service.ToLibrary(), result.Error } diff --git a/database/settings/create.go b/database/settings/create.go index 8c5747320..1879483b1 100644 --- a/database/settings/create.go +++ b/database/settings/create.go @@ -10,7 +10,7 @@ import ( ) // CreateSettings creates a platform settings record in the database. -func (e *engine) CreateSettings(_ context.Context, s *settings.Platform) (*settings.Platform, error) { +func (e *engine) CreateSettings(ctx context.Context, s *settings.Platform) (*settings.Platform, error) { e.logger.Tracef("creating platform settings with %v", s.String()) // cast the api type to database type @@ -23,7 +23,10 @@ func (e *engine) CreateSettings(_ context.Context, s *settings.Platform) (*setti } // send query to the database - err = e.client.Table(TableSettings).Create(settings.Nullify()).Error + err = e.client. + WithContext(ctx). + Table(TableSettings). + Create(settings.Nullify()).Error if err != nil { return nil, err } diff --git a/database/settings/get.go b/database/settings/get.go index 96bc19ef1..160faf6a4 100644 --- a/database/settings/get.go +++ b/database/settings/get.go @@ -18,6 +18,7 @@ func (e *engine) GetSettings(ctx context.Context) (*settings.Platform, error) { // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(TableSettings). Where("id = ?", 1). Take(s). diff --git a/database/settings/table.go b/database/settings/table.go index 18a4207ab..3eba03cfe 100644 --- a/database/settings/table.go +++ b/database/settings/table.go @@ -43,18 +43,22 @@ settings ( ) // CreateSettingsTable creates the settings table in the database. -func (e *engine) CreateSettingsTable(_ context.Context, driver string) error { +func (e *engine) CreateSettingsTable(ctx context.Context, driver string) error { e.logger.Tracef("creating settings table") // handle the driver provided to create the table switch driver { case constants.DriverPostgres: // create the steps table for Postgres - return e.client.Exec(CreatePostgresTable).Error + return e.client. + WithContext(ctx). + Exec(CreatePostgresTable).Error case constants.DriverSqlite: fallthrough default: // create the steps table for Sqlite - return e.client.Exec(CreateSqliteTable).Error + return e.client. + WithContext(ctx). + Exec(CreateSqliteTable).Error } } diff --git a/database/settings/update.go b/database/settings/update.go index c8a3e1679..e4e2f7f55 100644 --- a/database/settings/update.go +++ b/database/settings/update.go @@ -10,7 +10,7 @@ import ( ) // UpdateSettings updates a platform settings in the database. -func (e *engine) UpdateSettings(_ context.Context, s *settings.Platform) (*settings.Platform, error) { +func (e *engine) UpdateSettings(ctx context.Context, s *settings.Platform) (*settings.Platform, error) { e.logger.Trace("updating platform settings in the database") // cast the api type to database type @@ -23,7 +23,10 @@ func (e *engine) UpdateSettings(_ context.Context, s *settings.Platform) (*setti } // send query to the database - err = e.client.Table(TableSettings).Save(dbS.Nullify()).Error + err = e.client. + WithContext(ctx). + Table(TableSettings). + Save(dbS.Nullify()).Error if err != nil { return nil, err } diff --git a/database/step/clean.go b/database/step/clean.go index 3e75c906b..b7d8cb8f6 100644 --- a/database/step/clean.go +++ b/database/step/clean.go @@ -26,6 +26,7 @@ func (e *engine) CleanSteps(ctx context.Context, msg string, before int64) (int6 // send query to the database result := e.client. + WithContext(ctx). Table(constants.TableStep). Where("created < ?", before). Where("status = 'running' OR status = 'pending'"). diff --git a/database/step/count.go b/database/step/count.go index d5c64ba34..bb9f0ce3a 100644 --- a/database/step/count.go +++ b/database/step/count.go @@ -17,6 +17,7 @@ func (e *engine) CountSteps(ctx context.Context) (int64, error) { // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableStep). Count(&s). Error diff --git a/database/step/count_build.go b/database/step/count_build.go index 6b4d63fc4..4a0cefda5 100644 --- a/database/step/count_build.go +++ b/database/step/count_build.go @@ -22,6 +22,7 @@ func (e *engine) CountStepsForBuild(ctx context.Context, b *api.Build, filters m // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableStep). Where("build_id = ?", b.GetID()). Where(filters). diff --git a/database/step/create.go b/database/step/create.go index 99c9987b4..9e46cf146 100644 --- a/database/step/create.go +++ b/database/step/create.go @@ -32,7 +32,10 @@ func (e *engine) CreateStep(ctx context.Context, s *library.Step) (*library.Step } // send query to the database - result := e.client.Table(constants.TableStep).Create(step) + result := e.client. + WithContext(ctx). + Table(constants.TableStep). + Create(step) return step.ToLibrary(), result.Error } diff --git a/database/step/delete.go b/database/step/delete.go index dfd2d5bfa..7c9139f6b 100644 --- a/database/step/delete.go +++ b/database/step/delete.go @@ -25,6 +25,7 @@ func (e *engine) DeleteStep(ctx context.Context, s *library.Step) error { // send query to the database return e.client. + WithContext(ctx). Table(constants.TableStep). Delete(step). Error diff --git a/database/step/get.go b/database/step/get.go index 7a4e18041..a05a56fce 100644 --- a/database/step/get.go +++ b/database/step/get.go @@ -19,6 +19,7 @@ func (e *engine) GetStep(ctx context.Context, id int64) (*library.Step, error) { // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableStep). Where("id = ?", id). Take(s). diff --git a/database/step/get_build.go b/database/step/get_build.go index 5d32ba582..de847a769 100644 --- a/database/step/get_build.go +++ b/database/step/get_build.go @@ -25,6 +25,7 @@ func (e *engine) GetStepForBuild(ctx context.Context, b *api.Build, number int) // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableStep). Where("build_id = ?", b.GetID()). Where("number = ?", number). diff --git a/database/step/list.go b/database/step/list.go index 0d53297bd..9eb72996c 100644 --- a/database/step/list.go +++ b/database/step/list.go @@ -32,6 +32,7 @@ func (e *engine) ListSteps(ctx context.Context) ([]*library.Step, error) { // send query to the database and store result in variable err = e.client. + WithContext(ctx). Table(constants.TableStep). Find(&w). Error diff --git a/database/step/list_build.go b/database/step/list_build.go index ac0a608d1..1ba16fdb0 100644 --- a/database/step/list_build.go +++ b/database/step/list_build.go @@ -40,6 +40,7 @@ func (e *engine) ListStepsForBuild(ctx context.Context, b *api.Build, filters ma // send query to the database and store result in variable err = e.client. + WithContext(ctx). Table(constants.TableStep). Where("build_id = ?", b.GetID()). Where(filters). diff --git a/database/step/list_image.go b/database/step/list_image.go index 5b0f46aec..c485ec741 100644 --- a/database/step/list_image.go +++ b/database/step/list_image.go @@ -22,6 +22,7 @@ func (e *engine) ListStepImageCount(ctx context.Context) (map[string]float64, er // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableStep). Select("image", " count(image) as count"). Group("image"). diff --git a/database/step/list_status.go b/database/step/list_status.go index c74b8db3c..75c19a805 100644 --- a/database/step/list_status.go +++ b/database/step/list_status.go @@ -28,6 +28,7 @@ func (e *engine) ListStepStatusCount(ctx context.Context) (map[string]float64, e // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableStep). Select("status", " count(status) as count"). Group("status"). diff --git a/database/step/table.go b/database/step/table.go index a7cd7eb74..c7560326d 100644 --- a/database/step/table.go +++ b/database/step/table.go @@ -70,11 +70,15 @@ func (e *engine) CreateStepTable(ctx context.Context, driver string) error { switch driver { case constants.DriverPostgres: // create the steps table for Postgres - return e.client.Exec(CreatePostgresTable).Error + return e.client. + WithContext(ctx). + Exec(CreatePostgresTable).Error case constants.DriverSqlite: fallthrough default: // create the steps table for Sqlite - return e.client.Exec(CreateSqliteTable).Error + return e.client. + WithContext(ctx). + Exec(CreateSqliteTable).Error } } diff --git a/database/step/update.go b/database/step/update.go index 57fee9e74..d467a2b65 100644 --- a/database/step/update.go +++ b/database/step/update.go @@ -32,7 +32,10 @@ func (e *engine) UpdateStep(ctx context.Context, s *library.Step) (*library.Step } // send query to the database - result := e.client.Table(constants.TableStep).Save(step) + result := e.client. + WithContext(ctx). + Table(constants.TableStep). + Save(step) return step.ToLibrary(), result.Error } diff --git a/database/user/count.go b/database/user/count.go index c48fa00ed..b6b686fba 100644 --- a/database/user/count.go +++ b/database/user/count.go @@ -17,6 +17,7 @@ func (e *engine) CountUsers(ctx context.Context) (int64, error) { // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableUser). Count(&u). Error diff --git a/database/user/create.go b/database/user/create.go index e9cf0f2c6..c778349c4 100644 --- a/database/user/create.go +++ b/database/user/create.go @@ -40,7 +40,10 @@ func (e *engine) CreateUser(ctx context.Context, u *api.User) (*api.User, error) } // send query to the database - result := e.client.Table(constants.TableUser).Create(user) + result := e.client. + WithContext(ctx). + Table(constants.TableUser). + Create(user) // decrypt fields to return user err = user.Decrypt(e.config.EncryptionKey) diff --git a/database/user/delete.go b/database/user/delete.go index 3154461e2..28547c07c 100644 --- a/database/user/delete.go +++ b/database/user/delete.go @@ -23,6 +23,7 @@ func (e *engine) DeleteUser(ctx context.Context, u *api.User) error { // send query to the database return e.client. + WithContext(ctx). Table(constants.TableUser). Delete(user). Error diff --git a/database/user/get.go b/database/user/get.go index a2f7d8468..30901c2ff 100644 --- a/database/user/get.go +++ b/database/user/get.go @@ -19,6 +19,7 @@ func (e *engine) GetUser(ctx context.Context, id int64) (*api.User, error) { // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableUser). Where("id = ?", id). Take(u). diff --git a/database/user/get_name.go b/database/user/get_name.go index 8d3633eb8..fb9a90090 100644 --- a/database/user/get_name.go +++ b/database/user/get_name.go @@ -23,6 +23,7 @@ func (e *engine) GetUserForName(ctx context.Context, name string) (*api.User, er // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableUser). Where("name = ?", name). Take(u). diff --git a/database/user/index.go b/database/user/index.go index d35e1accd..37dc9476e 100644 --- a/database/user/index.go +++ b/database/user/index.go @@ -20,5 +20,7 @@ func (e *engine) CreateUserIndexes(ctx context.Context) error { e.logger.Tracef("creating indexes for users table") // create the refresh_token column index for the users table - return e.client.Exec(CreateUserRefreshIndex).Error + return e.client. + WithContext(ctx). + Exec(CreateUserRefreshIndex).Error } diff --git a/database/user/list.go b/database/user/list.go index 80c7f5681..035699489 100644 --- a/database/user/list.go +++ b/database/user/list.go @@ -32,6 +32,7 @@ func (e *engine) ListUsers(ctx context.Context) ([]*api.User, error) { // send query to the database and store result in variable err = e.client. + WithContext(ctx). Table(constants.TableUser). Find(&u). Error diff --git a/database/user/list_lite.go b/database/user/list_lite.go index 1a5c570f9..c961fe483 100644 --- a/database/user/list_lite.go +++ b/database/user/list_lite.go @@ -36,6 +36,7 @@ func (e *engine) ListLiteUsers(ctx context.Context, page, perPage int) ([]*api.U offset := perPage * (page - 1) err = e.client. + WithContext(ctx). Table(constants.TableUser). Select("id", "name"). Limit(perPage). diff --git a/database/user/table.go b/database/user/table.go index 183390b43..de1f964a7 100644 --- a/database/user/table.go +++ b/database/user/table.go @@ -52,11 +52,15 @@ func (e *engine) CreateUserTable(ctx context.Context, driver string) error { switch driver { case constants.DriverPostgres: // create the users table for Postgres - return e.client.Exec(CreatePostgresTable).Error + return e.client. + WithContext(ctx). + Exec(CreatePostgresTable).Error case constants.DriverSqlite: fallthrough default: // create the users table for Sqlite - return e.client.Exec(CreateSqliteTable).Error + return e.client. + WithContext(ctx). + Exec(CreateSqliteTable).Error } } diff --git a/database/user/update.go b/database/user/update.go index 19f653f8d..d860e3293 100644 --- a/database/user/update.go +++ b/database/user/update.go @@ -36,7 +36,10 @@ func (e *engine) UpdateUser(ctx context.Context, u *api.User) (*api.User, error) } // send query to the database - result := e.client.Table(constants.TableUser).Save(user) + result := e.client. + WithContext(ctx). + Table(constants.TableUser). + Save(user) // decrypt fields to return user err = user.Decrypt(e.config.EncryptionKey) diff --git a/database/worker/count.go b/database/worker/count.go index 0d992cdca..6c440637c 100644 --- a/database/worker/count.go +++ b/database/worker/count.go @@ -17,6 +17,7 @@ func (e *engine) CountWorkers(ctx context.Context) (int64, error) { // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableWorker). Count(&w). Error diff --git a/database/worker/create.go b/database/worker/create.go index 445669deb..180ee7ef6 100644 --- a/database/worker/create.go +++ b/database/worker/create.go @@ -32,7 +32,10 @@ func (e *engine) CreateWorker(ctx context.Context, w *api.Worker) (*api.Worker, } // send query to the database - result := e.client.Table(constants.TableWorker).Create(worker) + result := e.client. + WithContext(ctx). + Table(constants.TableWorker). + Create(worker) return worker.ToAPI(w.GetRunningBuilds()), result.Error } diff --git a/database/worker/delete.go b/database/worker/delete.go index 8df8ff5e0..252dd7831 100644 --- a/database/worker/delete.go +++ b/database/worker/delete.go @@ -25,6 +25,7 @@ func (e *engine) DeleteWorker(ctx context.Context, w *api.Worker) error { // send query to the database return e.client. + WithContext(ctx). Table(constants.TableWorker). Delete(worker). Error diff --git a/database/worker/get.go b/database/worker/get.go index cde920413..47be938a1 100644 --- a/database/worker/get.go +++ b/database/worker/get.go @@ -19,6 +19,7 @@ func (e *engine) GetWorker(ctx context.Context, id int64) (*api.Worker, error) { // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableWorker). Where("id = ?", id). Take(w). diff --git a/database/worker/get_hostname.go b/database/worker/get_hostname.go index 1646e262e..d1150f80d 100644 --- a/database/worker/get_hostname.go +++ b/database/worker/get_hostname.go @@ -23,6 +23,7 @@ func (e *engine) GetWorkerForHostname(ctx context.Context, hostname string) (*ap // send query to the database and store result in variable err := e.client. + WithContext(ctx). Table(constants.TableWorker). Where("hostname = ?", hostname). Take(w). diff --git a/database/worker/index.go b/database/worker/index.go index 65fe7326f..6e1fc58e3 100644 --- a/database/worker/index.go +++ b/database/worker/index.go @@ -20,5 +20,7 @@ func (e *engine) CreateWorkerIndexes(ctx context.Context) error { e.logger.Tracef("creating indexes for workers table") // create the hostname and address columns index for the workers table - return e.client.Exec(CreateHostnameAddressIndex).Error + return e.client. + WithContext(ctx). + Exec(CreateHostnameAddressIndex).Error } diff --git a/database/worker/list.go b/database/worker/list.go index e2af759dd..34fc2ef79 100644 --- a/database/worker/list.go +++ b/database/worker/list.go @@ -21,7 +21,9 @@ func (e *engine) ListWorkers(ctx context.Context, active string, before, after i workers := []*api.Worker{} // build query with checked in constraints - query := e.client.Table(constants.TableWorker). + query := e.client. + WithContext(ctx). + Table(constants.TableWorker). Where("last_checked_in < ?", before). Where("last_checked_in > ?", after) diff --git a/database/worker/table.go b/database/worker/table.go index 403dd5ad3..921734f38 100644 --- a/database/worker/table.go +++ b/database/worker/table.go @@ -59,11 +59,15 @@ func (e *engine) CreateWorkerTable(ctx context.Context, driver string) error { switch driver { case constants.DriverPostgres: // create the workers table for Postgres - return e.client.Exec(CreatePostgresTable).Error + return e.client. + WithContext(ctx). + Exec(CreatePostgresTable).Error case constants.DriverSqlite: fallthrough default: // create the workers table for Sqlite - return e.client.Exec(CreateSqliteTable).Error + return e.client. + WithContext(ctx). + Exec(CreateSqliteTable).Error } } diff --git a/database/worker/update.go b/database/worker/update.go index 872d9c82d..49c78e420 100644 --- a/database/worker/update.go +++ b/database/worker/update.go @@ -32,7 +32,10 @@ func (e *engine) UpdateWorker(ctx context.Context, w *api.Worker) (*api.Worker, } // send query to the database - result := e.client.Table(constants.TableWorker).Save(worker) + result := e.client. + WithContext(ctx). + Table(constants.TableWorker). + Save(worker) return worker.ToAPI(w.GetRunningBuilds()), result.Error }