Skip to content

Commit

Permalink
db: rename store constructors (#17506)
Browse files Browse the repository at this point in the history
  • Loading branch information
asdine committed Jan 21, 2021
1 parent 6dda334 commit eeb83e1
Show file tree
Hide file tree
Showing 50 changed files with 137 additions and 137 deletions.
2 changes: 1 addition & 1 deletion cmd/frontend/internal/httpapi/httpapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func NewHandler(m *mux.Router, schema *graphql.Schema, githubWebhook webhooks.Re
m.Get(apirouter.RepoRefresh).Handler(trace.TraceRoute(handler(serveRepoRefresh)))

gh := webhooks.GitHubWebhook{
ExternalServices: db.NewExternalServicesStoreWithDB(dbconn.Global),
ExternalServices: db.ExternalServices(dbconn.Global),
}

webhookhandlers.Init(&gh)
Expand Down
2 changes: 1 addition & 1 deletion cmd/frontend/webhooks/github_webhooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestGithubWebhookExternalServices(t *testing.T) {
ctx := context.Background()

secret := "secret"
esStore := idb.NewExternalServicesStoreWithDB(db)
esStore := idb.ExternalServices(db)
extSvc := &types.ExternalService{
Kind: extsvc.KindGitHub,
DisplayName: "GitHub",
Expand Down
2 changes: 1 addition & 1 deletion cmd/gitserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,5 @@ func getRepoStore() (*db.RepoStore, error) {
return nil, err
}

return db.NewRepoStoreWithDB(h), nil
return db.Repos(h), nil
}
2 changes: 1 addition & 1 deletion cmd/repo-updater/shared/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ func watchSyncer(ctx context.Context, syncer *repos.Syncer, sched scheduler, gps
// update the scheduler with the list. It also ensures that if any of our default
// repos are missing from the cloned list they will be added for cloning ASAP.
func syncScheduler(ctx context.Context, sched scheduler, gitserverClient *gitserver.Client, store *repos.Store) {
baseRepoStore := idb.NewRepoStoreWith(store)
baseRepoStore := idb.ReposWith(store)

doSync := func() {
cloned, err := gitserverClient.ListCloned(ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func NewAfterCreateUserHook() func(context.Context, dbutil.DB, *types.User) erro

// Nil info indicates no license, thus Free tier
if info == nil {
store := db.NewUserStoreWithDB(tx)
store := db.Users(tx)
user.SiteAdmin = true
if err := store.SetIsSiteAdmin(ctx, user.ID, user.SiteAdmin); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions enterprise/internal/campaigns/background.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func InitBackgroundJobs(
) {
cstore := store.NewWithClock(db, timeutil.Now)

repoStore := ossDB.NewRepoStoreWith(cstore)
esStore := ossDB.NewExternalServicesStoreWith(cstore)
repoStore := ossDB.ReposWith(cstore)
esStore := ossDB.ExternalServicesWith(cstore)

// We use an internal actor so that we can freely load dependencies from
// the database without repository permissions being enforced.
Expand Down
2 changes: 1 addition & 1 deletion enterprise/internal/campaigns/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func InitFrontend(ctx context.Context, enterpriseServices *enterprise.Services)
}

cstore := store.NewWithClock(dbconn.Global, timeutil.Now)
esStore := db.NewExternalServicesStoreWithDB(dbconn.Global)
esStore := db.ExternalServices(dbconn.Global)

enterpriseServices.CampaignsResolver = resolvers.New(dbconn.Global)
enterpriseServices.GitHubWebhook = webhooks.NewGitHubWebhook(cstore, esStore, timeutil.Now)
Expand Down
4 changes: 2 additions & 2 deletions enterprise/internal/campaigns/reconciler/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ func (e *executor) Run(ctx context.Context, plan *Plan) (err error) {
return nil
}

reposStore := db.NewRepoStoreWith(e.tx)
reposStore := db.ReposWith(e.tx)

e.repo, err = loadRepo(ctx, reposStore, e.ch.RepoID)
if err != nil {
return errors.Wrap(err, "failed to load repository")
}

esStore := db.NewExternalServicesStoreWith(e.tx)
esStore := db.ExternalServicesWith(e.tx)

e.extSvc, err = loadExternalService(ctx, esStore, e.repo)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func TestCampaignConnectionResolver(t *testing.T) {
userID := ct.CreateTestUser(t, true).ID

cstore := store.New(dbconn.Global)
repoStore := db.NewRepoStoreWith(cstore)
esStore := db.NewExternalServicesStoreWith(cstore)
repoStore := db.ReposWith(cstore)
esStore := db.ExternalServicesWith(cstore)

repo := newGitHubTestRepo("github.com/sourcegraph/campaign-connection-test", newGitHubExternalService(t, esStore))
if err := repoStore.Create(ctx, repo); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions enterprise/internal/campaigns/resolvers/campaign_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func TestCampaignSpecResolver(t *testing.T) {
dbtesting.SetupGlobalTestDB(t)

cstore := store.New(dbconn.Global)
repoStore := db.NewRepoStoreWith(cstore)
esStore := db.NewExternalServicesStoreWith(cstore)
repoStore := db.ReposWith(cstore)
esStore := db.ExternalServicesWith(cstore)

repo := newGitHubTestRepo("github.com/sourcegraph/campaign-spec-test", newGitHubExternalService(t, esStore))
if err := repoStore.Create(ctx, repo); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func TestChangesetApplyPreviewConnectionResolver(t *testing.T) {
t.Fatal(err)
}

esStore := db.NewExternalServicesStoreWith(cstore)
repoStore := db.NewRepoStoreWith(cstore)
esStore := db.ExternalServicesWith(cstore)
repoStore := db.ReposWith(cstore)

rs := make([]*types.Repo, 0, 3)
for i := 0; i < cap(rs); i++ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func TestChangesetApplyPreviewResolver(t *testing.T) {
campaign := ct.CreateCampaign(t, ctx, cstore, campaignName, userID, oldCampaignSpec.ID)
campaignSpec := ct.CreateCampaignSpec(t, ctx, cstore, campaignName, userID)

esStore := db.NewExternalServicesStoreWith(cstore)
repoStore := db.NewRepoStoreWith(cstore)
esStore := db.ExternalServicesWith(cstore)
repoStore := db.ReposWith(cstore)

rs := make([]*types.Repo, 0, 3)
for i := 0; i < cap(rs); i++ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func TestChangesetConnectionResolver(t *testing.T) {
userID := ct.CreateTestUser(t, false).ID

cstore := store.New(dbconn.Global)
repoStore := db.NewRepoStoreWith(cstore)
esStore := db.NewExternalServicesStoreWith(cstore)
repoStore := db.ReposWith(cstore)
esStore := db.ExternalServicesWith(cstore)

repo := newGitHubTestRepo("github.com/sourcegraph/changeset-connection-test", newGitHubExternalService(t, esStore))
inaccessibleRepo := newGitHubTestRepo("github.com/sourcegraph/private", newGitHubExternalService(t, esStore))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ func TestChangesetCountsOverTimeIntegration(t *testing.T) {

userID := ct.CreateTestUser(t, false).ID

repoStore := db.NewRepoStoreWithDB(dbconn.Global)
esStore := db.NewExternalServicesStoreWithDB(dbconn.Global)
repoStore := db.Repos(dbconn.Global)
esStore := db.ExternalServices(dbconn.Global)

githubExtSvc := &types.ExternalService{
Kind: extsvc.KindGitHub,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func TestChangesetEventConnectionResolver(t *testing.T) {
now := timeutil.Now()
clock := func() time.Time { return now }
cstore := store.NewWithClock(dbconn.Global, clock)
repoStore := db.NewRepoStoreWith(cstore)
esStore := db.NewExternalServicesStoreWith(cstore)
repoStore := db.ReposWith(cstore)
esStore := db.ExternalServicesWith(cstore)

repo := newGitHubTestRepo("github.com/sourcegraph/changeset-event-connection-test", newGitHubExternalService(t, esStore))
if err := repoStore.Create(ctx, repo); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func TestChangesetSpecConnectionResolver(t *testing.T) {
t.Fatal(err)
}

repoStore := db.NewRepoStoreWith(cstore)
esStore := db.NewExternalServicesStoreWith(cstore)
repoStore := db.ReposWith(cstore)
esStore := db.ExternalServicesWith(cstore)

rs := make([]*types.Repo, 0, 3)
for i := 0; i < cap(rs); i++ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestChangesetSpecResolver(t *testing.T) {
userID := ct.CreateTestUser(t, false).ID

cstore := store.New(dbconn.Global)
esStore := db.NewExternalServicesStoreWith(cstore)
esStore := db.ExternalServicesWith(cstore)

// Creating user with matching email to the changeset spec author.
user, err := db.GlobalUsers.Create(ctx, db.NewUser{
Expand All @@ -44,7 +44,7 @@ func TestChangesetSpecResolver(t *testing.T) {
t.Fatal(err)
}

repoStore := db.NewRepoStoreWith(cstore)
repoStore := db.ReposWith(cstore)
repo := newGitHubTestRepo("github.com/sourcegraph/changeset-spec-resolver-test", newGitHubExternalService(t, esStore))
if err := repoStore.Create(ctx, repo); err != nil {
t.Fatal(err)
Expand Down
4 changes: 2 additions & 2 deletions enterprise/internal/campaigns/resolvers/changeset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func TestChangesetResolver(t *testing.T) {
now := timeutil.Now()
clock := func() time.Time { return now }
cstore := store.NewWithClock(dbconn.Global, clock)
esStore := db.NewExternalServicesStoreWith(cstore)
repoStore := db.NewRepoStoreWith(cstore)
esStore := db.ExternalServicesWith(cstore)
repoStore := db.ReposWith(cstore)

repo := newGitHubTestRepo("github.com/sourcegraph/changeset-resolver-test", newGitHubExternalService(t, esStore))
if err := repoStore.Create(ctx, repo); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions enterprise/internal/campaigns/resolvers/permissions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func TestPermissionLevels(t *testing.T) {
adminID := ct.CreateTestUser(t, true).ID
userID := ct.CreateTestUser(t, false).ID

repoStore := db.NewRepoStoreWith(cstore)
esStore := db.NewExternalServicesStoreWith(cstore)
repoStore := db.ReposWith(cstore)
esStore := db.ExternalServicesWith(cstore)

repo := newGitHubTestRepo("github.com/sourcegraph/permission-levels-test", newGitHubExternalService(t, esStore))
if err := repoStore.Create(ctx, repo); err != nil {
Expand Down Expand Up @@ -771,8 +771,8 @@ func TestRepositoryPermissions(t *testing.T) {
// Global test data that we reuse in every test
userID := ct.CreateTestUser(t, false).ID

repoStore := db.NewRepoStoreWith(cstore)
esStore := db.NewExternalServicesStoreWith(cstore)
repoStore := db.ReposWith(cstore)
esStore := db.ExternalServicesWith(cstore)

// Create 2 repositories
repos := make([]*types.Repo, 0, 2)
Expand Down
12 changes: 6 additions & 6 deletions enterprise/internal/campaigns/resolvers/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ func TestCreateCampaignSpec(t *testing.T) {
userID := user.ID

cstore := store.New(dbconn.Global)
repoStore := db.NewRepoStoreWith(cstore)
esStore := db.NewExternalServicesStoreWith(cstore)
repoStore := db.ReposWith(cstore)
esStore := db.ExternalServicesWith(cstore)

repo := newGitHubTestRepo("github.com/sourcegraph/create-campaign-spec-test", newGitHubExternalService(t, esStore))
if err := repoStore.Create(ctx, repo); err != nil {
Expand Down Expand Up @@ -267,8 +267,8 @@ func TestCreateChangesetSpec(t *testing.T) {
userID := ct.CreateTestUser(t, true).ID

cstore := store.New(dbconn.Global)
repoStore := db.NewRepoStoreWith(cstore)
esStore := db.NewExternalServicesStoreWith(cstore)
repoStore := db.ReposWith(cstore)
esStore := db.ExternalServicesWith(cstore)

repo := newGitHubTestRepo("github.com/sourcegraph/create-changeset-spec-test", newGitHubExternalService(t, esStore))
if err := repoStore.Create(ctx, repo); err != nil {
Expand Down Expand Up @@ -342,8 +342,8 @@ func TestApplyCampaign(t *testing.T) {
now := timeutil.Now()
clock := func() time.Time { return now }
cstore := store.NewWithClock(dbconn.Global, clock)
repoStore := db.NewRepoStoreWith(cstore)
esStore := db.NewExternalServicesStoreWith(cstore)
repoStore := db.ReposWith(cstore)
esStore := db.ExternalServicesWith(cstore)

repo := newGitHubTestRepo("github.com/sourcegraph/apply-campaign-test", newGitHubExternalService(t, esStore))
if err := repoStore.Create(ctx, repo); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion enterprise/internal/campaigns/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ func (s *Service) FetchUsernameForBitbucketServerToken(ctx context.Context, exte
return "", err
}

esStore := db.NewExternalServicesStoreWith(s.store)
esStore := db.ExternalServicesWith(s.store)
externalService, err := esStore.GetByID(ctx, extSvcID)
if err != nil {
if errcode.IsNotFound(err) {
Expand Down
8 changes: 4 additions & 4 deletions enterprise/internal/campaigns/store/changeset_specs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
)

func testStoreChangesetSpecs(t *testing.T, ctx context.Context, s *Store, clock ct.Clock) {
repoStore := db.NewRepoStoreWith(s)
esStore := db.NewExternalServicesStoreWith(s)
repoStore := db.ReposWith(s)
esStore := db.ExternalServicesWith(s)

repo := ct.TestRepo(t, esStore, extsvc.KindGitHub)
deletedRepo := ct.TestRepo(t, esStore, extsvc.KindGitHub).With(types.Opt.RepoDeletedAt(clock.Now()))
Expand Down Expand Up @@ -678,8 +678,8 @@ func testStoreChangesetSpecs(t *testing.T, ctx context.Context, s *Store, clock
}

func testStoreChangesetSpecsTextSearch(t *testing.T, ctx context.Context, s *Store, clock ct.Clock) {
repoStore := db.NewRepoStoreWith(s)
esStore := db.NewExternalServicesStoreWith(s)
repoStore := db.ReposWith(s)
esStore := db.ExternalServicesWith(s)

// OK, let's set up an interesting scenario. We're going to set up a
// campaign that tracks two changesets in different repositories, and
Expand Down
12 changes: 6 additions & 6 deletions enterprise/internal/campaigns/store/changesets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func testStoreChangesets(t *testing.T, ctx context.Context, s *Store, clock ct.C
HeadRefName: "campaigns/test",
}

rs := db.NewRepoStoreWith(s)
es := db.NewExternalServicesStoreWith(s)
rs := db.ReposWith(s)
es := db.ExternalServicesWith(s)

repo := ct.TestRepo(t, es, extsvc.KindGitHub)
otherRepo := ct.TestRepo(t, es, extsvc.KindGitHub)
Expand Down Expand Up @@ -1222,8 +1222,8 @@ func testStoreListChangesetSyncData(t *testing.T, ctx context.Context, s *Store,
IncludesCreatedEdit: false,
}

rs := db.NewRepoStoreWith(s)
es := db.NewExternalServicesStoreWith(s)
rs := db.ReposWith(s)
es := db.ExternalServicesWith(s)

githubRepo := ct.TestRepo(t, es, extsvc.KindGitHub)
gitlabRepo := ct.TestRepo(t, es, extsvc.KindGitLab)
Expand Down Expand Up @@ -1490,8 +1490,8 @@ func testStoreListChangesetsTextSearch(t *testing.T, ctx context.Context, s *Sto
return cs
}

rs := db.NewRepoStoreWith(s)
es := db.NewExternalServicesStoreWith(s)
rs := db.ReposWith(s)
es := db.ExternalServicesWith(s)

// Set up repositories for each code host type we want to test.
var (
Expand Down
4 changes: 2 additions & 2 deletions enterprise/internal/campaigns/store/codehost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
)

func testStoreCodeHost(t *testing.T, ctx context.Context, s *Store, clock ct.Clock) {
rs := db.NewRepoStoreWith(s.Store)
es := db.NewExternalServicesStoreWith(s.Store)
rs := db.ReposWith(s.Store)
es := db.ExternalServicesWith(s.Store)

repo := ct.TestRepo(t, es, extsvc.KindGitHub)
otherRepo := ct.TestRepo(t, es, extsvc.KindGitHub)
Expand Down
12 changes: 6 additions & 6 deletions enterprise/internal/campaigns/testing/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func TestRepo(t *testing.T, store *idb.ExternalServiceStore, serviceKind string)
func CreateTestRepos(t *testing.T, ctx context.Context, db *sql.DB, count int) ([]*types.Repo, *types.ExternalService) {
t.Helper()

repoStore := idb.NewRepoStoreWithDB(db)
esStore := idb.NewExternalServicesStoreWithDB(db)
repoStore := idb.Repos(db)
esStore := idb.ExternalServices(db)

ext := &types.ExternalService{
Kind: extsvc.KindGitHub,
Expand Down Expand Up @@ -101,8 +101,8 @@ func CreateTestRepos(t *testing.T, ctx context.Context, db *sql.DB, count int) (
func CreateGitlabTestRepos(t *testing.T, ctx context.Context, db *sql.DB, count int) ([]*types.Repo, *types.ExternalService) {
t.Helper()

repoStore := idb.NewRepoStoreWithDB(db)
esStore := idb.NewExternalServicesStoreWithDB(db)
repoStore := idb.Repos(db)
esStore := idb.ExternalServices(db)

ext := &types.ExternalService{
Kind: extsvc.KindGitLab,
Expand Down Expand Up @@ -170,8 +170,8 @@ func createBbsRepos(t *testing.T, ctx context.Context, db *sql.DB, ext *types.Ex

t.Helper()

repoStore := idb.NewRepoStoreWithDB(db)
esStore := idb.NewExternalServicesStoreWithDB(db)
repoStore := idb.Repos(db)
esStore := idb.ExternalServices(db)

if err := esStore.Upsert(ctx, ext); err != nil {
t.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion enterprise/internal/campaigns/webhooks/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (h Webhook) getRepoForPR(
pr PR,
externalServiceID string,
) (*types.Repo, error) {
reposTx := db.NewRepoStoreWith(tx)
reposTx := db.ReposWith(tx)
rs, err := reposTx.List(ctx, db.ReposListOptions{
ExternalRepos: []api.ExternalRepoSpec{
{
Expand Down
Loading

0 comments on commit eeb83e1

Please sign in to comment.