mirror of
https://github.com/harness/drone.git
synced 2025-05-10 22:21:22 +08:00

This change is a follow up on the effort to remove transactions and sync stores from the database layer, and move them in the application layer. It is addressing the repo + space store. The following changes are included: - Introduce PathStore storing resource paths (repo + space) - Add foreign key from path.repo_id/space_id to repo.id/space.id - Add foreign key from repo/space.parent_id to space.id - Remove repo_sync and space_sync - Move path creation logic to repo/space controller (for both creating primary paths for new repos/spaces, as well as creating alias spaces) - Reimplement repo/space moving on controller layer
105 lines
3.1 KiB
Go
105 lines
3.1 KiB
Go
// Copyright 2022 Harness Inc. All rights reserved.
|
|
// Use of this source code is governed by the Polyform Free Trial License
|
|
// that can be found in the LICENSE.md file for this repository.
|
|
|
|
package database
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/harness/gitness/internal/store"
|
|
"github.com/harness/gitness/types"
|
|
|
|
"github.com/google/wire"
|
|
"github.com/jmoiron/sqlx"
|
|
)
|
|
|
|
// WireSet provides a wire set for this package.
|
|
var WireSet = wire.NewSet(
|
|
ProvideDatabase,
|
|
ProvidePrincipalStore,
|
|
ProvidePrincipalInfoView,
|
|
ProvidePathStore,
|
|
ProvideSpaceStore,
|
|
ProvideRepoStore,
|
|
ProvideTokenStore,
|
|
ProvidePullReqStore,
|
|
ProvidePullReqActivityStore,
|
|
ProvidePullReqReviewStore,
|
|
ProvidePullReqReviewerStore,
|
|
ProvideWebhookStore,
|
|
ProvideWebhookExecutionStore,
|
|
)
|
|
|
|
// ProvideDatabase provides a database connection.
|
|
func ProvideDatabase(ctx context.Context, config *types.Config) (*sqlx.DB, error) {
|
|
return Connect(
|
|
ctx,
|
|
config.Database.Driver,
|
|
config.Database.Datasource,
|
|
)
|
|
}
|
|
|
|
// ProvidePrincipalStore provides a principal store.
|
|
func ProvidePrincipalStore(db *sqlx.DB, uidTransformation store.PrincipalUIDTransformation) store.PrincipalStore {
|
|
return NewPrincipalStore(db, uidTransformation)
|
|
}
|
|
|
|
// ProvidePrincipalInfoView provides a principal info store.
|
|
func ProvidePrincipalInfoView(db *sqlx.DB) store.PrincipalInfoView {
|
|
return NewPrincipalInfoView(db)
|
|
}
|
|
|
|
// ProvidePathStore provides a path store.
|
|
func ProvidePathStore(db *sqlx.DB, pathTransformation store.PathTransformation) store.PathStore {
|
|
return NewPathStore(db, pathTransformation)
|
|
}
|
|
|
|
// ProvideSpaceStore provides a space store.
|
|
func ProvideSpaceStore(db *sqlx.DB, pathCache store.PathCache) store.SpaceStore {
|
|
return NewSpaceStore(db, pathCache)
|
|
}
|
|
|
|
// ProvideRepoStore provides a repo store.
|
|
func ProvideRepoStore(db *sqlx.DB, pathCache store.PathCache) store.RepoStore {
|
|
return NewRepoStore(db, pathCache)
|
|
}
|
|
|
|
// ProvideTokenStore provides a token store.
|
|
func ProvideTokenStore(db *sqlx.DB) store.TokenStore {
|
|
return NewTokenStore(db)
|
|
}
|
|
|
|
// ProvidePullReqStore provides a pull request store.
|
|
func ProvidePullReqStore(db *sqlx.DB,
|
|
principalInfoCache store.PrincipalInfoCache) store.PullReqStore {
|
|
return NewPullReqStore(db, principalInfoCache)
|
|
}
|
|
|
|
// ProvidePullReqActivityStore provides a pull request activity store.
|
|
func ProvidePullReqActivityStore(db *sqlx.DB,
|
|
principalInfoCache store.PrincipalInfoCache) store.PullReqActivityStore {
|
|
return NewPullReqActivityStore(db, principalInfoCache)
|
|
}
|
|
|
|
// ProvidePullReqReviewStore provides a pull request review store.
|
|
func ProvidePullReqReviewStore(db *sqlx.DB) store.PullReqReviewStore {
|
|
return NewPullReqReviewStore(db)
|
|
}
|
|
|
|
// ProvidePullReqReviewerStore provides a pull request reviewer store.
|
|
func ProvidePullReqReviewerStore(db *sqlx.DB,
|
|
principalInfoCache store.PrincipalInfoCache) store.PullReqReviewerStore {
|
|
return NewPullReqReviewerStore(db, principalInfoCache)
|
|
}
|
|
|
|
// ProvideWebhookStore provides a webhook store.
|
|
func ProvideWebhookStore(db *sqlx.DB) store.WebhookStore {
|
|
return NewWebhookStore(db)
|
|
}
|
|
|
|
// ProvideWebhookExecutionStore provides a webhook execution store.
|
|
func ProvideWebhookExecutionStore(db *sqlx.DB) store.WebhookExecutionStore {
|
|
return NewWebhookExecutionStore(db)
|
|
}
|