Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit c836d6a

Browse files
authored
Backend: remove EnterpriseDB (#54699)
This moves a bunch of stuff out of enterprise. Notably, the final result is `EnterpriseDB` no longer exists. This is one of the biggest sticking points for moving other stuff out of the `enterprise` directory, so this should help speed up future cleanups.
1 parent b89a22a commit c836d6a

File tree

246 files changed

+41076
-48348
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

246 files changed

+41076
-48348
lines changed

cmd/worker/shared/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import (
3737

3838
const addr = ":3189"
3939

40-
type EnterpriseInit = func(ossDB database.DB)
40+
type EnterpriseInit = func(db database.DB)
4141

4242
type namedBackgroundRoutine struct {
4343
Routine goroutine.BackgroundRoutine

doc/dev/background-information/codemonitoring/index.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ actions.
1919

2020
## Starting up your environment
2121

22-
Code monitoring is an enterprise functionality. To run it locally you need to start Sourcegraph as enterprise service:
22+
To run it locally you need to start Sourcegraph:
2323

2424
```bash
2525
sg start # which defaults to `sg start enterprise`
@@ -102,7 +102,7 @@ action.
102102
The back end of code monitoring is split into two parts, the GraphQL API, running
103103
on _frontend_, and the background workers, running on _repo-updater_. Both rely
104104
on the
105-
[store](https://github.com/sourcegraph/sourcegraph/blob/main/enterprise/internal/codemonitors/store.go)
105+
[store](https://github.com/sourcegraph/sourcegraph/blob/main/internal/codemonitors/store.go)
106106
to access the database.
107107

108108
### GraphQL API
@@ -111,13 +111,13 @@ The GraphQL API is defined
111111
[here](https://github.com/sourcegraph/sourcegraph/blob/main/cmd/frontend/graphqlbackend/schema.graphql).
112112
The interfaces and stub-resolvers are defined
113113
[here](https://github.com/sourcegraph/sourcegraph/blob/main/cmd/frontend/graphqlbackend/code_monitors.go),
114-
while the enterprise resolvers are defined
115-
[here](https://github.com/sourcegraph/sourcegraph/blob/main/enterprise/internal/codemonitors/resolvers/resolvers.go).
114+
while the resolvers are defined
115+
[here](https://github.com/sourcegraph/sourcegraph/blob/main/internal/codemonitors/resolvers/resolvers.go).
116116

117117
### Background workers
118118

119119
The [background
120-
workers](https://github.com/sourcegraph/sourcegraph/blob/main/enterprise/internal/codemonitors/background/background.go)
120+
workers](https://github.com/sourcegraph/sourcegraph/blob/main/internal/codemonitors/background/background.go)
121121
utilize our `internal/workerutil` framework to [run as background jobs on
122122
`repo-updater`](https://github.com/sourcegraph/sourcegraph/blob/main/enterprise/cmd/repo-updater/main.go#L49).
123123

@@ -131,10 +131,10 @@ utilize our `internal/workerutil` framework to [run as background jobs on
131131
resolvers](https://github.com/sourcegraph/sourcegraph/blob/main/cmd/frontend/graphqlbackend/code_monitors.go)
132132
and understand how they relate to the [GraphQL
133133
schema](https://github.com/sourcegraph/sourcegraph/blob/main/cmd/frontend/graphqlbackend/code_monitors.go).
134-
3. Do the same for the [enterprise
134+
3. Do the same for the [
135135
resolvers](https://github.com/sourcegraph/sourcegraph/blob/main/cmd/frontend/graphqlbackend/code_monitors.go).
136136
4. Take a look at the [background
137-
workers](https://github.com/sourcegraph/sourcegraph/blob/main/enterprise/internal/codemonitors/background/background.go)
137+
workers](https://github.com/sourcegraph/sourcegraph/blob/main/internal/codemonitors/background/background.go)
138138
and look through each of the jobs that run in the background.
139139
5. Start up Sourcegraph locally, connect to your local db instance, create a
140140
code monitor from the UI and follow its life cycle in the db. Start by

enterprise/cmd/embeddings/qa/context_data.tsv

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ In the sourcegraph repository, what does InternalDoer do? internal/httpcli/clien
44
In my codebase, what does InternalDoer do? internal/httpcli/client.go
55
Is the crewjam/saml package used in my repository? go.mod
66
Where is the vscode Cody extension implemented? client/cody/README.md
7-
Where in the code do we send Slack notifications for code monitoring? enterprise/internal/codemonitors/background/slack.go
7+
Where in the code do we send Slack notifications for code monitoring? internal/codemonitors/background/slack.go

enterprise/cmd/embeddings/shared/BUILD.bazel

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

enterprise/cmd/embeddings/shared/main.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616

1717
eiauthz "github.com/sourcegraph/sourcegraph/enterprise/internal/authz"
1818
srp "github.com/sourcegraph/sourcegraph/enterprise/internal/authz/subrepoperms"
19-
edb "github.com/sourcegraph/sourcegraph/enterprise/internal/database"
2019
"github.com/sourcegraph/sourcegraph/internal/actor"
2120
"github.com/sourcegraph/sourcegraph/internal/authz"
2221
"github.com/sourcegraph/sourcegraph/internal/conf"
@@ -62,7 +61,7 @@ func Main(ctx context.Context, observationCtx *observation.Context, ready servic
6261
return err
6362
}
6463

65-
authz.DefaultSubRepoPermsChecker, err = srp.NewSubRepoPermsClient(edb.NewEnterpriseDB(db).SubRepoPerms())
64+
authz.DefaultSubRepoPermsChecker, err = srp.NewSubRepoPermsClient(db.SubRepoPerms())
6665
if err != nil {
6766
return errors.Wrap(err, "creating sub-repo client")
6867
}

enterprise/cmd/frontend/internal/auth/githubappauth/BUILD.bazel

+4-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

enterprise/cmd/frontend/internal/auth/githubappauth/init.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/sourcegraph/log"
77

88
"github.com/sourcegraph/sourcegraph/cmd/frontend/enterprise"
9-
edb "github.com/sourcegraph/sourcegraph/enterprise/internal/database"
109
"github.com/sourcegraph/sourcegraph/internal/codeintel"
1110
"github.com/sourcegraph/sourcegraph/internal/conf/conftypes"
1211
"github.com/sourcegraph/sourcegraph/internal/database"
@@ -21,6 +20,6 @@ func Init(
2120
_ conftypes.UnifiedWatchable,
2221
enterpriseServices *enterprise.Services,
2322
) error {
24-
enterpriseServices.GitHubAppsResolver = NewResolver(log.Scoped("GitHubAppsResolver", ""), edb.NewEnterpriseDB(db))
23+
enterpriseServices.GitHubAppsResolver = NewResolver(log.Scoped("GitHubAppsResolver", ""), db)
2524
return nil
2625
}

enterprise/cmd/frontend/internal/auth/githubappauth/middleware.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ import (
2121

2222
"github.com/sourcegraph/sourcegraph/cmd/frontend/auth"
2323
"github.com/sourcegraph/sourcegraph/cmd/frontend/backend"
24-
edb "github.com/sourcegraph/sourcegraph/enterprise/internal/database"
25-
ghaauth "github.com/sourcegraph/sourcegraph/enterprise/internal/github_apps/auth"
26-
ghtypes "github.com/sourcegraph/sourcegraph/enterprise/internal/github_apps/types"
2724
authcheck "github.com/sourcegraph/sourcegraph/internal/auth"
2825
"github.com/sourcegraph/sourcegraph/internal/database"
2926
"github.com/sourcegraph/sourcegraph/internal/encryption"
3027
"github.com/sourcegraph/sourcegraph/internal/encryption/keyring"
3128
"github.com/sourcegraph/sourcegraph/internal/extsvc"
3229
"github.com/sourcegraph/sourcegraph/internal/extsvc/github"
30+
ghaauth "github.com/sourcegraph/sourcegraph/internal/github_apps/auth"
31+
ghtypes "github.com/sourcegraph/sourcegraph/internal/github_apps/types"
3332
"github.com/sourcegraph/sourcegraph/internal/rcache"
3433
"github.com/sourcegraph/sourcegraph/internal/trace"
3534
"github.com/sourcegraph/sourcegraph/internal/types"
@@ -51,8 +50,7 @@ func Middleware(db database.DB) *auth.Middleware {
5150

5251
const cacheTTLSeconds = 60 * 60 // 1 hour
5352

54-
func newMiddleware(ossDB database.DB, authPrefix string, isAPIHandler bool, next http.Handler) http.Handler {
55-
db := edb.NewEnterpriseDB(ossDB)
53+
func newMiddleware(db database.DB, authPrefix string, isAPIHandler bool, next http.Handler) http.Handler {
5654
ghAppState := rcache.NewWithTTL("github_app_state", cacheTTLSeconds)
5755
handler := newServeMux(db, authPrefix, ghAppState)
5856

@@ -72,7 +70,7 @@ func newMiddleware(ossDB database.DB, authPrefix string, isAPIHandler bool, next
7270
}
7371

7472
// checkSiteAdmin checks if the current user is a site admin and sets http error if not
75-
func checkSiteAdmin(db edb.EnterpriseDB, w http.ResponseWriter, req *http.Request) error {
73+
func checkSiteAdmin(db database.DB, w http.ResponseWriter, req *http.Request) error {
7674
err := authcheck.CheckCurrentUserIsSiteAdmin(req.Context(), db)
7775
if err == nil {
7876
return nil
@@ -117,7 +115,7 @@ type gitHubAppStateDetails struct {
117115
AppID int `json:"app_id,omitempty"`
118116
}
119117

120-
func newServeMux(db edb.EnterpriseDB, prefix string, cache *rcache.Cache) http.Handler {
118+
func newServeMux(db database.DB, prefix string, cache *rcache.Cache) http.Handler {
121119
r := mux.NewRouter()
122120

123121
r.Path(prefix + "/state").Methods("GET").HandlerFunc(func(w http.ResponseWriter, req *http.Request) {

enterprise/cmd/frontend/internal/auth/githubappauth/middleware_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ import (
1212
"github.com/google/uuid"
1313
"github.com/stretchr/testify/require"
1414

15-
edb "github.com/sourcegraph/sourcegraph/enterprise/internal/database"
16-
"github.com/sourcegraph/sourcegraph/enterprise/internal/github_apps/store"
17-
ghtypes "github.com/sourcegraph/sourcegraph/enterprise/internal/github_apps/types"
1815
"github.com/sourcegraph/sourcegraph/internal/actor"
1916
"github.com/sourcegraph/sourcegraph/internal/database"
2017
"github.com/sourcegraph/sourcegraph/internal/encryption"
18+
"github.com/sourcegraph/sourcegraph/internal/github_apps/store"
19+
ghtypes "github.com/sourcegraph/sourcegraph/internal/github_apps/types"
2120
"github.com/sourcegraph/sourcegraph/internal/rcache"
2221
"github.com/sourcegraph/sourcegraph/internal/types"
2322
)
@@ -118,7 +117,7 @@ func TestGithubAppAuthMiddleware(t *testing.T) {
118117
}, nil
119118
})
120119

121-
db := edb.NewMockEnterpriseDB()
120+
db := database.NewMockDB()
122121

123122
db.UsersFunc.SetDefaultReturn(mockUserStore)
124123
db.WebhooksFunc.SetDefaultReturn(mockWebhookStore)

enterprise/cmd/frontend/internal/auth/githubappauth/resolver.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,27 @@ import (
1313

1414
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
1515
"github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/repos/webhooks/resolvers"
16-
edb "github.com/sourcegraph/sourcegraph/enterprise/internal/database"
17-
ghauth "github.com/sourcegraph/sourcegraph/enterprise/internal/github_apps/auth"
18-
"github.com/sourcegraph/sourcegraph/enterprise/internal/github_apps/types"
1916
"github.com/sourcegraph/sourcegraph/internal/auth"
2017
"github.com/sourcegraph/sourcegraph/internal/database"
2118
"github.com/sourcegraph/sourcegraph/internal/encryption/keyring"
2219
"github.com/sourcegraph/sourcegraph/internal/extsvc"
2320
"github.com/sourcegraph/sourcegraph/internal/extsvc/github"
21+
ghauth "github.com/sourcegraph/sourcegraph/internal/github_apps/auth"
22+
"github.com/sourcegraph/sourcegraph/internal/github_apps/types"
2423
"github.com/sourcegraph/sourcegraph/internal/gqlutil"
2524
itypes "github.com/sourcegraph/sourcegraph/internal/types"
2625
"github.com/sourcegraph/sourcegraph/lib/errors"
2726
"github.com/sourcegraph/sourcegraph/schema"
2827
)
2928

3029
// NewResolver returns a new Resolver that uses the given database
31-
func NewResolver(logger log.Logger, db edb.EnterpriseDB) graphqlbackend.GitHubAppsResolver {
30+
func NewResolver(logger log.Logger, db database.DB) graphqlbackend.GitHubAppsResolver {
3231
return &resolver{logger: logger, db: db}
3332
}
3433

3534
type resolver struct {
3635
logger log.Logger
37-
db edb.EnterpriseDB
36+
db database.DB
3837
}
3938

4039
const gitHubAppIDKind = "GitHubApp"
@@ -177,7 +176,7 @@ func (r *resolver) gitHubAppByAppID(ctx context.Context, appID int, baseURL stri
177176
}
178177

179178
// NewGitHubAppResolver creates a new GitHubAppResolver from a GitHubApp.
180-
func NewGitHubAppResolver(db edb.EnterpriseDB, app *types.GitHubApp, logger log.Logger) *gitHubAppResolver {
179+
func NewGitHubAppResolver(db database.DB, app *types.GitHubApp, logger log.Logger) *gitHubAppResolver {
181180
return &gitHubAppResolver{app: app, db: db, logger: logger}
182181
}
183182

@@ -198,7 +197,7 @@ func (r *gitHubAppConnectionResolver) TotalCount(ctx context.Context) int32 {
198197
type gitHubAppResolver struct {
199198
logger log.Logger
200199
app *types.GitHubApp
201-
db edb.EnterpriseDB
200+
db database.DB
202201

203202
once sync.Once
204203
installations []graphqlbackend.GitHubAppInstallation

enterprise/cmd/frontend/internal/auth/githubappauth/resolver_test.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ import (
1212
gqlerrors "github.com/graph-gophers/graphql-go/errors"
1313

1414
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
15-
edb "github.com/sourcegraph/sourcegraph/enterprise/internal/database"
16-
"github.com/sourcegraph/sourcegraph/enterprise/internal/github_apps/store"
17-
ghtypes "github.com/sourcegraph/sourcegraph/enterprise/internal/github_apps/types"
1815
"github.com/sourcegraph/sourcegraph/internal/actor"
1916
"github.com/sourcegraph/sourcegraph/internal/database"
17+
"github.com/sourcegraph/sourcegraph/internal/github_apps/store"
18+
ghtypes "github.com/sourcegraph/sourcegraph/internal/github_apps/types"
2019
"github.com/sourcegraph/sourcegraph/internal/gitserver"
2120
"github.com/sourcegraph/sourcegraph/internal/types"
2221
)
@@ -53,7 +52,7 @@ func TestResolver_DeleteGitHubApp(t *testing.T) {
5352
return nil
5453
})
5554

56-
db := edb.NewStrictMockEnterpriseDB()
55+
db := database.NewStrictMockDB()
5756

5857
db.GitHubAppsFunc.SetDefaultReturn(gitHubAppsStore)
5958
db.UsersFunc.SetDefaultReturn(userStore)
@@ -129,7 +128,7 @@ func TestResolver_GitHubApps(t *testing.T) {
129128
return []*ghtypes.GitHubApp{{ID: 1}, {ID: 2}}, nil
130129
})
131130

132-
db := edb.NewStrictMockEnterpriseDB()
131+
db := database.NewStrictMockDB()
133132

134133
db.GitHubAppsFunc.SetDefaultReturn(gitHubAppsStore)
135134
db.UsersFunc.SetDefaultReturn(userStore)
@@ -227,7 +226,7 @@ func TestResolver_GitHubApp(t *testing.T) {
227226
BaseURL: "https://github.com",
228227
}, nil)
229228

230-
db := edb.NewStrictMockEnterpriseDB()
229+
db := database.NewStrictMockDB()
231230

232231
db.GitHubAppsFunc.SetDefaultReturn(gitHubAppsStore)
233232
db.UsersFunc.SetDefaultReturn(userStore)
@@ -296,7 +295,7 @@ func TestResolver_GitHubAppByAppID(t *testing.T) {
296295
Name: name,
297296
}, nil)
298297

299-
db := edb.NewStrictMockEnterpriseDB()
298+
db := database.NewStrictMockDB()
300299

301300
db.GitHubAppsFunc.SetDefaultReturn(gitHubAppsStore)
302301
db.UsersFunc.SetDefaultReturn(userStore)

enterprise/cmd/frontend/internal/auth/sourcegraphoperator/BUILD.bazel

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

enterprise/cmd/frontend/internal/auth/sourcegraphoperator/associate_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import (
1212
"github.com/sourcegraph/log/logtest"
1313

1414
"github.com/sourcegraph/sourcegraph/enterprise/cmd/worker/shared/sourcegraphoperator"
15-
"github.com/sourcegraph/sourcegraph/enterprise/internal/cloud"
1615
"github.com/sourcegraph/sourcegraph/internal/actor"
1716
"github.com/sourcegraph/sourcegraph/internal/auth"
1817
"github.com/sourcegraph/sourcegraph/internal/auth/providers"
18+
"github.com/sourcegraph/sourcegraph/internal/cloud"
1919
"github.com/sourcegraph/sourcegraph/internal/database"
2020
"github.com/sourcegraph/sourcegraph/internal/database/dbtest"
2121
"github.com/sourcegraph/sourcegraph/internal/extsvc"

enterprise/cmd/frontend/internal/auth/sourcegraphoperator/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77

88
"github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/auth/openidconnect"
99
osssourcegraphoperator "github.com/sourcegraph/sourcegraph/enterprise/cmd/worker/shared/sourcegraphoperator"
10-
"github.com/sourcegraph/sourcegraph/enterprise/internal/cloud"
1110
"github.com/sourcegraph/sourcegraph/internal/auth"
1211
"github.com/sourcegraph/sourcegraph/internal/auth/providers"
12+
"github.com/sourcegraph/sourcegraph/internal/cloud"
1313
"github.com/sourcegraph/sourcegraph/internal/conf"
1414
"github.com/sourcegraph/sourcegraph/internal/conf/conftypes"
1515
)

enterprise/cmd/frontend/internal/auth/sourcegraphoperator/config_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package sourcegraphoperator
33
import (
44
"testing"
55

6-
"github.com/sourcegraph/sourcegraph/enterprise/internal/cloud"
6+
"github.com/sourcegraph/sourcegraph/internal/cloud"
77
"github.com/sourcegraph/sourcegraph/internal/conf"
88
"github.com/sourcegraph/sourcegraph/schema"
99
)

enterprise/cmd/frontend/internal/auth/sourcegraphoperator/middleware_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import (
2121
"github.com/sourcegraph/sourcegraph/cmd/frontend/auth"
2222
"github.com/sourcegraph/sourcegraph/cmd/frontend/external/session"
2323
"github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/auth/openidconnect"
24-
"github.com/sourcegraph/sourcegraph/enterprise/internal/cloud"
2524
"github.com/sourcegraph/sourcegraph/internal/actor"
2625
internalauth "github.com/sourcegraph/sourcegraph/internal/auth"
2726
"github.com/sourcegraph/sourcegraph/internal/auth/providers"
27+
"github.com/sourcegraph/sourcegraph/internal/cloud"
2828
"github.com/sourcegraph/sourcegraph/internal/database"
2929
"github.com/sourcegraph/sourcegraph/internal/extsvc"
3030
"github.com/sourcegraph/sourcegraph/internal/types"

enterprise/cmd/frontend/internal/auth/sourcegraphoperator/provider.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ import (
55

66
feAuth "github.com/sourcegraph/sourcegraph/cmd/frontend/auth"
77
"github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/auth/openidconnect"
8-
"github.com/sourcegraph/sourcegraph/enterprise/internal/cloud"
98
"github.com/sourcegraph/sourcegraph/internal/auth"
109
"github.com/sourcegraph/sourcegraph/internal/auth/providers"
10+
"github.com/sourcegraph/sourcegraph/internal/cloud"
1111
"github.com/sourcegraph/sourcegraph/schema"
1212
)
1313

1414
// provider is an implementation of providers.Provider for the Sourcegraph
1515
// Operator authentication, also referred to as "SOAP". There can only ever be
1616
// one provider of this type, and it can only be provisioned through Cloud site
17-
// configuration (see github.com/sourcegraph/sourcegraph/enterprise/internal/cloud)
17+
// configuration (see github.com/sourcegraph/sourcegraph/internal/cloud)
1818
//
1919
// SOAP is used to provision accounts for Sourcegraph teammates in Sourcegraph
2020
// Cloud - for more details, refer to

0 commit comments

Comments
 (0)