sourcegraph/cmd/worker/shared/init/codeintel/db.go
Erik Seliger 8de09ddbc7
chore: Cleanup more cross-cmd imports (#64259)
This PR fixes a few more imports from /internal/ packages using /cmd/... contents.

Test plan: Mainly moved code around and CI still passes.
2024-08-08 10:10:58 +02:00

36 lines
1.2 KiB
Go

package codeintel
import (
"database/sql"
codeintelshared "github.com/sourcegraph/sourcegraph/internal/codeintel/shared"
"github.com/sourcegraph/sourcegraph/internal/conf"
"github.com/sourcegraph/sourcegraph/internal/conf/conftypes"
connections "github.com/sourcegraph/sourcegraph/internal/database/connections/live"
"github.com/sourcegraph/sourcegraph/internal/memo"
"github.com/sourcegraph/sourcegraph/internal/observation"
"github.com/sourcegraph/sourcegraph/lib/errors"
)
func InitDB(observationCtx *observation.Context) (codeintelshared.CodeIntelDB, error) {
rawDB, err := initDBMemo.Init(observationCtx)
if err != nil {
return nil, err
}
return codeintelshared.NewCodeIntelDB(observationCtx.Logger, rawDB), nil
}
var initDBMemo = memo.NewMemoizedConstructorWithArg(func(observationCtx *observation.Context) (*sql.DB, error) {
dsn := conf.GetServiceConnectionValueAndRestartOnChange(func(serviceConnections conftypes.ServiceConnections) string {
return serviceConnections.CodeIntelPostgresDSN
})
db, err := connections.EnsureNewCodeIntelDB(observationCtx, dsn, "worker")
if err != nil {
return nil, errors.Errorf("failed to connect to codeintel database: %s", err)
}
return db, nil
})