diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d4a102dcd1db..ac8cbc923830c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ All notable changes to Sourcegraph are documented in this file. - Login form can now be configured with ordering and limit of auth providers. [See docs](https://docs.sourcegraph.com/admin/auth/login_form). [#50586](https://github.com/sourcegraph/sourcegraph/pull/50586), [50284](https://github.com/sourcegraph/sourcegraph/pull/50284) and [#50705](https://github.com/sourcegraph/sourcegraph/pull/50705) - When creating a new batch change, spaces are automatically replaced with dashes in the name field. [#50825](https://github.com/sourcegraph/sourcegraph/pull/50825) and [51071](https://github.com/sourcegraph/sourcegraph/pull/51071) - Support for custom HTML injection behind an environment variable (`ENABLE_INJECT_HTML`). This allows users to enable or disable HTML customization as needed, which is now disabled by default. [#51400](https://github.com/sourcegraph/sourcegraph/pull/51400) +- Added the ability to block auto-indexing scheduling and inference via the `codeintel_autoindexing_exceptions` Postgres table. [#51578](https://github.com/sourcegraph/sourcegraph/pull/51578) ### Changed diff --git a/enterprise/internal/codeintel/autoindexing/internal/background/dependencies/mocks_test.go b/enterprise/internal/codeintel/autoindexing/internal/background/dependencies/mocks_test.go index 11a7aab17ace5..103468d2fa42e 100644 --- a/enterprise/internal/codeintel/autoindexing/internal/background/dependencies/mocks_test.go +++ b/enterprise/internal/codeintel/autoindexing/internal/background/dependencies/mocks_test.go @@ -1958,6 +1958,9 @@ type MockStore struct { // QueueRepoRevFunc is an instance of a mock function object controlling // the behavior of the method QueueRepoRev. QueueRepoRevFunc *StoreQueueRepoRevFunc + // RepositoryExceptionsFunc is an instance of a mock function object + // controlling the behavior of the method RepositoryExceptions. + RepositoryExceptionsFunc *StoreRepositoryExceptionsFunc // RepositoryIDsWithConfigurationFunc is an instance of a mock function // object controlling the behavior of the method // RepositoryIDsWithConfiguration. @@ -1968,6 +1971,9 @@ type MockStore struct { // SetInferenceScriptFunc is an instance of a mock function object // controlling the behavior of the method SetInferenceScript. SetInferenceScriptFunc *StoreSetInferenceScriptFunc + // SetRepositoryExceptionsFunc is an instance of a mock function object + // controlling the behavior of the method SetRepositoryExceptions. + SetRepositoryExceptionsFunc *StoreSetRepositoryExceptionsFunc // TopRepositoriesToConfigureFunc is an instance of a mock function // object controlling the behavior of the method // TopRepositoriesToConfigure. @@ -2044,6 +2050,11 @@ func NewMockStore() *MockStore { return }, }, + RepositoryExceptionsFunc: &StoreRepositoryExceptionsFunc{ + defaultHook: func(context.Context, int) (r0 bool, r1 bool, r2 error) { + return + }, + }, RepositoryIDsWithConfigurationFunc: &StoreRepositoryIDsWithConfigurationFunc{ defaultHook: func(context.Context, int, int) (r0 []shared1.RepositoryWithAvailableIndexers, r1 int, r2 error) { return @@ -2059,6 +2070,11 @@ func NewMockStore() *MockStore { return }, }, + SetRepositoryExceptionsFunc: &StoreSetRepositoryExceptionsFunc{ + defaultHook: func(context.Context, int, bool, bool) (r0 error) { + return + }, + }, TopRepositoriesToConfigureFunc: &StoreTopRepositoriesToConfigureFunc{ defaultHook: func(context.Context, int) (r0 []shared1.RepositoryWithCount, r1 error) { return @@ -2141,6 +2157,11 @@ func NewStrictMockStore() *MockStore { panic("unexpected invocation of MockStore.QueueRepoRev") }, }, + RepositoryExceptionsFunc: &StoreRepositoryExceptionsFunc{ + defaultHook: func(context.Context, int) (bool, bool, error) { + panic("unexpected invocation of MockStore.RepositoryExceptions") + }, + }, RepositoryIDsWithConfigurationFunc: &StoreRepositoryIDsWithConfigurationFunc{ defaultHook: func(context.Context, int, int) ([]shared1.RepositoryWithAvailableIndexers, int, error) { panic("unexpected invocation of MockStore.RepositoryIDsWithConfiguration") @@ -2156,6 +2177,11 @@ func NewStrictMockStore() *MockStore { panic("unexpected invocation of MockStore.SetInferenceScript") }, }, + SetRepositoryExceptionsFunc: &StoreSetRepositoryExceptionsFunc{ + defaultHook: func(context.Context, int, bool, bool) error { + panic("unexpected invocation of MockStore.SetRepositoryExceptions") + }, + }, TopRepositoriesToConfigureFunc: &StoreTopRepositoriesToConfigureFunc{ defaultHook: func(context.Context, int) ([]shared1.RepositoryWithCount, error) { panic("unexpected invocation of MockStore.TopRepositoriesToConfigure") @@ -2216,6 +2242,9 @@ func NewMockStoreFrom(i store.Store) *MockStore { QueueRepoRevFunc: &StoreQueueRepoRevFunc{ defaultHook: i.QueueRepoRev, }, + RepositoryExceptionsFunc: &StoreRepositoryExceptionsFunc{ + defaultHook: i.RepositoryExceptions, + }, RepositoryIDsWithConfigurationFunc: &StoreRepositoryIDsWithConfigurationFunc{ defaultHook: i.RepositoryIDsWithConfiguration, }, @@ -2225,6 +2254,9 @@ func NewMockStoreFrom(i store.Store) *MockStore { SetInferenceScriptFunc: &StoreSetInferenceScriptFunc{ defaultHook: i.SetInferenceScript, }, + SetRepositoryExceptionsFunc: &StoreSetRepositoryExceptionsFunc{ + defaultHook: i.SetRepositoryExceptions, + }, TopRepositoriesToConfigureFunc: &StoreTopRepositoriesToConfigureFunc{ defaultHook: i.TopRepositoriesToConfigure, }, @@ -3467,6 +3499,117 @@ func (c StoreQueueRepoRevFuncCall) Results() []interface{} { return []interface{}{c.Result0} } +// StoreRepositoryExceptionsFunc describes the behavior when the +// RepositoryExceptions method of the parent MockStore instance is invoked. +type StoreRepositoryExceptionsFunc struct { + defaultHook func(context.Context, int) (bool, bool, error) + hooks []func(context.Context, int) (bool, bool, error) + history []StoreRepositoryExceptionsFuncCall + mutex sync.Mutex +} + +// RepositoryExceptions delegates to the next hook function in the queue and +// stores the parameter and result values of this invocation. +func (m *MockStore) RepositoryExceptions(v0 context.Context, v1 int) (bool, bool, error) { + r0, r1, r2 := m.RepositoryExceptionsFunc.nextHook()(v0, v1) + m.RepositoryExceptionsFunc.appendCall(StoreRepositoryExceptionsFuncCall{v0, v1, r0, r1, r2}) + return r0, r1, r2 +} + +// SetDefaultHook sets function that is called when the RepositoryExceptions +// method of the parent MockStore instance is invoked and the hook queue is +// empty. +func (f *StoreRepositoryExceptionsFunc) SetDefaultHook(hook func(context.Context, int) (bool, bool, error)) { + f.defaultHook = hook +} + +// PushHook adds a function to the end of hook queue. Each invocation of the +// RepositoryExceptions method of the parent MockStore instance invokes the +// hook at the front of the queue and discards it. After the queue is empty, +// the default hook function is invoked for any future action. +func (f *StoreRepositoryExceptionsFunc) PushHook(hook func(context.Context, int) (bool, bool, error)) { + f.mutex.Lock() + f.hooks = append(f.hooks, hook) + f.mutex.Unlock() +} + +// SetDefaultReturn calls SetDefaultHook with a function that returns the +// given values. +func (f *StoreRepositoryExceptionsFunc) SetDefaultReturn(r0 bool, r1 bool, r2 error) { + f.SetDefaultHook(func(context.Context, int) (bool, bool, error) { + return r0, r1, r2 + }) +} + +// PushReturn calls PushHook with a function that returns the given values. +func (f *StoreRepositoryExceptionsFunc) PushReturn(r0 bool, r1 bool, r2 error) { + f.PushHook(func(context.Context, int) (bool, bool, error) { + return r0, r1, r2 + }) +} + +func (f *StoreRepositoryExceptionsFunc) nextHook() func(context.Context, int) (bool, bool, error) { + f.mutex.Lock() + defer f.mutex.Unlock() + + if len(f.hooks) == 0 { + return f.defaultHook + } + + hook := f.hooks[0] + f.hooks = f.hooks[1:] + return hook +} + +func (f *StoreRepositoryExceptionsFunc) appendCall(r0 StoreRepositoryExceptionsFuncCall) { + f.mutex.Lock() + f.history = append(f.history, r0) + f.mutex.Unlock() +} + +// History returns a sequence of StoreRepositoryExceptionsFuncCall objects +// describing the invocations of this function. +func (f *StoreRepositoryExceptionsFunc) History() []StoreRepositoryExceptionsFuncCall { + f.mutex.Lock() + history := make([]StoreRepositoryExceptionsFuncCall, len(f.history)) + copy(history, f.history) + f.mutex.Unlock() + + return history +} + +// StoreRepositoryExceptionsFuncCall is an object that describes an +// invocation of method RepositoryExceptions on an instance of MockStore. +type StoreRepositoryExceptionsFuncCall struct { + // Arg0 is the value of the 1st argument passed to this method + // invocation. + Arg0 context.Context + // Arg1 is the value of the 2nd argument passed to this method + // invocation. + Arg1 int + // Result0 is the value of the 1st result returned from this method + // invocation. + Result0 bool + // Result1 is the value of the 2nd result returned from this method + // invocation. + Result1 bool + // Result2 is the value of the 3rd result returned from this method + // invocation. + Result2 error +} + +// Args returns an interface slice containing the arguments of this +// invocation. +func (c StoreRepositoryExceptionsFuncCall) Args() []interface{} { + return []interface{}{c.Arg0, c.Arg1} +} + +// Results returns an interface slice containing the results of this +// invocation. +func (c StoreRepositoryExceptionsFuncCall) Results() []interface{} { + return []interface{}{c.Result0, c.Result1, c.Result2} +} + // StoreRepositoryIDsWithConfigurationFunc describes the behavior when the // RepositoryIDsWithConfiguration method of the parent MockStore instance is // invoked. @@ -3801,6 +3944,118 @@ func (c StoreSetInferenceScriptFuncCall) Results() []interface{} { return []interface{}{c.Result0} } +// StoreSetRepositoryExceptionsFunc describes the behavior when the +// SetRepositoryExceptions method of the parent MockStore instance is +// invoked. +type StoreSetRepositoryExceptionsFunc struct { + defaultHook func(context.Context, int, bool, bool) error + hooks []func(context.Context, int, bool, bool) error + history []StoreSetRepositoryExceptionsFuncCall + mutex sync.Mutex +} + +// SetRepositoryExceptions delegates to the next hook function in the queue +// and stores the parameter and result values of this invocation. +func (m *MockStore) SetRepositoryExceptions(v0 context.Context, v1 int, v2 bool, v3 bool) error { + r0 := m.SetRepositoryExceptionsFunc.nextHook()(v0, v1, v2, v3) + m.SetRepositoryExceptionsFunc.appendCall(StoreSetRepositoryExceptionsFuncCall{v0, v1, v2, v3, r0}) + return r0 +} + +// SetDefaultHook sets function that is called when the +// SetRepositoryExceptions method of the parent MockStore instance is +// invoked and the hook queue is empty. +func (f *StoreSetRepositoryExceptionsFunc) SetDefaultHook(hook func(context.Context, int, bool, bool) error) { + f.defaultHook = hook +} + +// PushHook adds a function to the end of hook queue. Each invocation of the +// SetRepositoryExceptions method of the parent MockStore instance invokes +// the hook at the front of the queue and discards it. After the queue is +// empty, the default hook function is invoked for any future action. +func (f *StoreSetRepositoryExceptionsFunc) PushHook(hook func(context.Context, int, bool, bool) error) { + f.mutex.Lock() + f.hooks = append(f.hooks, hook) + f.mutex.Unlock() +} + +// SetDefaultReturn calls SetDefaultHook with a function that returns the +// given values. +func (f *StoreSetRepositoryExceptionsFunc) SetDefaultReturn(r0 error) { + f.SetDefaultHook(func(context.Context, int, bool, bool) error { + return r0 + }) +} + +// PushReturn calls PushHook with a function that returns the given values. +func (f *StoreSetRepositoryExceptionsFunc) PushReturn(r0 error) { + f.PushHook(func(context.Context, int, bool, bool) error { + return r0 + }) +} + +func (f *StoreSetRepositoryExceptionsFunc) nextHook() func(context.Context, int, bool, bool) error { + f.mutex.Lock() + defer f.mutex.Unlock() + + if len(f.hooks) == 0 { + return f.defaultHook + } + + hook := f.hooks[0] + f.hooks = f.hooks[1:] + return hook +} + +func (f *StoreSetRepositoryExceptionsFunc) appendCall(r0 StoreSetRepositoryExceptionsFuncCall) { + f.mutex.Lock() + f.history = append(f.history, r0) + f.mutex.Unlock() +} + +// History returns a sequence of StoreSetRepositoryExceptionsFuncCall +// objects describing the invocations of this function. +func (f *StoreSetRepositoryExceptionsFunc) History() []StoreSetRepositoryExceptionsFuncCall { + f.mutex.Lock() + history := make([]StoreSetRepositoryExceptionsFuncCall, len(f.history)) + copy(history, f.history) + f.mutex.Unlock() + + return history +} + +// StoreSetRepositoryExceptionsFuncCall is an object that describes an +// invocation of method SetRepositoryExceptions on an instance of MockStore. +type StoreSetRepositoryExceptionsFuncCall struct { + // Arg0 is the value of the 1st argument passed to this method + // invocation. + Arg0 context.Context + // Arg1 is the value of the 2nd argument passed to this method + // invocation. + Arg1 int + // Arg2 is the value of the 3rd argument passed to this method + // invocation. + Arg2 bool + // Arg3 is the value of the 4th argument passed to this method + // invocation. + Arg3 bool + // Result0 is the value of the 1st result returned from this method + // invocation. + Result0 error +} + +// Args returns an interface slice containing the arguments of this +// invocation. +func (c StoreSetRepositoryExceptionsFuncCall) Args() []interface{} { + return []interface{}{c.Arg0, c.Arg1, c.Arg2, c.Arg3} +} + +// Results returns an interface slice containing the results of this +// invocation. +func (c StoreSetRepositoryExceptionsFuncCall) Results() []interface{} { + return []interface{}{c.Result0} +} + // StoreTopRepositoriesToConfigureFunc describes the behavior when the // TopRepositoriesToConfigure method of the parent MockStore instance is // invoked. diff --git a/enterprise/internal/codeintel/autoindexing/internal/jobselector/job_selector.go b/enterprise/internal/codeintel/autoindexing/internal/jobselector/job_selector.go index a26a9992fed02..35a26b47ed9db 100644 --- a/enterprise/internal/codeintel/autoindexing/internal/jobselector/job_selector.go +++ b/enterprise/internal/codeintel/autoindexing/internal/jobselector/job_selector.go @@ -64,6 +64,13 @@ func (s *JobSelector) InferIndexJobsFromRepositoryStructure(ctx context.Context, script = localOverrideScript } + if _, canInfer, err := s.store.RepositoryExceptions(ctx, repositoryID); err != nil { + return nil, err + } else if !canInfer { + s.logger.Warn("Auto-indexing job inference for this repo is disabled", log.Int("repositoryID", repositoryID), log.String("repoName", string(repo.Name))) + return nil, nil + } + indexes, err := s.inferenceSvc.InferIndexJobs(ctx, repo.Name, commit, script) if err != nil { return nil, err @@ -78,7 +85,14 @@ func (s *JobSelector) InferIndexJobsFromRepositoryStructure(ctx context.Context, } // inferIndexJobsFromRepositoryStructure collects the result of InferIndexJobHints over all registered recognizers. -func (s *JobSelector) InferIndexJobHintsFromRepositoryStructure(ctx context.Context, repoName api.RepoName, commit string) ([]config.IndexJobHint, error) { +func (s *JobSelector) InferIndexJobHintsFromRepositoryStructure(ctx context.Context, repositoryID int, repoName api.RepoName, commit string) ([]config.IndexJobHint, error) { + if _, canInfer, err := s.store.RepositoryExceptions(ctx, repositoryID); err != nil { + return nil, err + } else if !canInfer { + s.logger.Warn("Auto-indexing job inference for this repo is disabled", log.Int("repositoryID", repositoryID), log.String("repoName", string(repoName))) + return nil, nil + } + indexes, err := s.inferenceSvc.InferIndexJobHints(ctx, repoName, commit, overrideScript) if err != nil { return nil, err @@ -97,6 +111,13 @@ type configurationFactoryFunc func(ctx context.Context, repositoryID int, commit // - committed to `sourcegraph.yaml` in the repository // - inferred from the repository structure func (s *JobSelector) GetIndexRecords(ctx context.Context, repositoryID int, commit, configuration string, bypassLimit bool) ([]uploadsshared.Index, error) { + if canSchedule, _, err := s.store.RepositoryExceptions(ctx, repositoryID); err != nil { + return nil, err + } else if !canSchedule { + s.logger.Warn("Auto-indexing scheduling for this repo is disabled", log.Int("repositoryID", repositoryID)) + return nil, nil + } + fns := []configurationFactoryFunc{ makeExplicitConfigurationFactory(configuration), s.getIndexRecordsFromConfigurationInDatabase, diff --git a/enterprise/internal/codeintel/autoindexing/internal/store/config_repo.go b/enterprise/internal/codeintel/autoindexing/internal/store/config_repo.go index 2dd545cef6968..4c58406fa0509 100644 --- a/enterprise/internal/codeintel/autoindexing/internal/store/config_repo.go +++ b/enterprise/internal/codeintel/autoindexing/internal/store/config_repo.go @@ -12,6 +12,58 @@ import ( "github.com/sourcegraph/sourcegraph/internal/observation" ) +func (s *store) RepositoryExceptions(ctx context.Context, repositoryID int) (canSchedule, canInfer bool, err error) { + ctx, _, endObservation := s.operations.repositoryExceptions.With(ctx, &err, observation.Args{LogFields: []log.Field{ + log.Int("repositoryID", repositoryID), + }}) + defer endObservation(1, observation.Args{}) + + rows, err := s.db.Query(ctx, sqlf.Sprintf(repositoryExceptionsQuery, repositoryID)) + if err != nil { + return false, false, err + } + defer func() { err = basestore.CloseRows(rows, err) }() + + var disableSchedule, disableInference bool + for rows.Next() { + if err := rows.Scan(&disableSchedule, &disableInference); err != nil { + return false, false, err + } + } + + return !disableSchedule, !disableInference, rows.Err() +} + +const repositoryExceptionsQuery = ` +SELECT + cae.disable_scheduling, + cae.disable_inference +FROM codeintel_autoindexing_exceptions cae +WHERE cae.repository_id = %s +` + +func (s *store) SetRepositoryExceptions(ctx context.Context, repositoryID int, canSchedule, canInfer bool) (err error) { + ctx, _, endObservation := s.operations.setRepositoryExceptions.With(ctx, &err, observation.Args{LogFields: []log.Field{ + log.Int("repositoryID", repositoryID), + }}) + defer endObservation(1, observation.Args{}) + + return s.db.Exec(ctx, sqlf.Sprintf( + setRepositoryExceptionsQuery, + repositoryID, + !canSchedule, !canInfer, + !canSchedule, !canInfer, + )) +} + +const setRepositoryExceptionsQuery = ` +INSERT INTO codeintel_autoindexing_exceptions (repository_id, disable_scheduling, disable_inference) +VALUES (%s, %s, %s) +ON CONFLICT (repository_id) DO UPDATE SET + disable_scheduling = %s, + disable_inference = %s +` + func (s *store) GetIndexConfigurationByRepositoryID(ctx context.Context, repositoryID int) (_ shared.IndexConfiguration, _ bool, err error) { ctx, _, endObservation := s.operations.getIndexConfigurationByRepositoryID.With(ctx, &err, observation.Args{LogFields: []log.Field{ log.Int("repositoryID", repositoryID), diff --git a/enterprise/internal/codeintel/autoindexing/internal/store/config_repo_test.go b/enterprise/internal/codeintel/autoindexing/internal/store/config_repo_test.go index aebaf70dab2a7..34360d47d499e 100644 --- a/enterprise/internal/codeintel/autoindexing/internal/store/config_repo_test.go +++ b/enterprise/internal/codeintel/autoindexing/internal/store/config_repo_test.go @@ -13,6 +13,46 @@ import ( "github.com/sourcegraph/sourcegraph/internal/observation" ) +func TestRepositoryExceptions(t *testing.T) { + logger := logtest.Scoped(t) + db := database.NewDB(logger, dbtest.NewDB(logger, t)) + store := New(&observation.TestContext, db) + + query := sqlf.Sprintf( + `INSERT INTO repo (id, name) VALUES (%s, %s)`, + 42, + "github.com/baz/honk", + ) + if _, err := db.ExecContext(context.Background(), query.Query(sqlf.PostgresBindVar), query.Args()...); err != nil { + t.Fatalf("unexpected error inserting repo: %s", err) + } + + for _, testCase := range []struct { + canSchedule bool + canInfer bool + }{ + {true, false}, + {false, true}, + {false, false}, + {true, true}, + } { + if err := store.SetRepositoryExceptions(context.Background(), 42, testCase.canSchedule, testCase.canInfer); err != nil { + t.Fatalf("failed to update repository exception: %s", err) + } + + canSchedule, canInfer, err := store.RepositoryExceptions(context.Background(), 42) + if err != nil { + t.Fatalf("unexpected error getting repository exceptions: %s", err) + } + if canSchedule != testCase.canSchedule { + t.Errorf("unexpected exception for can_schedule. want=%v have=%v", testCase.canSchedule, canSchedule) + } + if canInfer != testCase.canInfer { + t.Errorf("unexpected exception for can_infer. want=%v have=%v", testCase.canInfer, canInfer) + } + } +} + func TestGetIndexConfigurationByRepositoryID(t *testing.T) { logger := logtest.Scoped(t) db := database.NewDB(logger, dbtest.NewDB(logger, t)) diff --git a/enterprise/internal/codeintel/autoindexing/internal/store/observability.go b/enterprise/internal/codeintel/autoindexing/internal/store/observability.go index ce0327bc6cbb4..42646ad2edc76 100644 --- a/enterprise/internal/codeintel/autoindexing/internal/store/observability.go +++ b/enterprise/internal/codeintel/autoindexing/internal/store/observability.go @@ -13,6 +13,8 @@ import ( type operations struct { getInferenceScript *observation.Operation setInferenceScript *observation.Operation + repositoryExceptions *observation.Operation + setRepositoryExceptions *observation.Operation getIndexConfigurationByRepositoryID *observation.Operation updateIndexConfigurationByRepositoryID *observation.Operation topRepositoriesToConfigure *observation.Operation @@ -67,6 +69,8 @@ func newOperations(observationCtx *observation.Context) *operations { return &operations{ getInferenceScript: op("GetInferenceScript"), setInferenceScript: op("SetInferenceScript"), + repositoryExceptions: op("RepositoryExceptions"), + setRepositoryExceptions: op("SetRepositoryExceptions"), getIndexConfigurationByRepositoryID: op("GetIndexConfigurationByRepositoryID"), updateIndexConfigurationByRepositoryID: op("UpdateIndexConfigurationByRepositoryID"), topRepositoriesToConfigure: op("TopRepositoriesToConfigure"), diff --git a/enterprise/internal/codeintel/autoindexing/internal/store/store.go b/enterprise/internal/codeintel/autoindexing/internal/store/store.go index 3f8d8a5d31005..3778fcdca98d6 100644 --- a/enterprise/internal/codeintel/autoindexing/internal/store/store.go +++ b/enterprise/internal/codeintel/autoindexing/internal/store/store.go @@ -21,6 +21,8 @@ type Store interface { SetInferenceScript(ctx context.Context, script string) error // Repository configuration + RepositoryExceptions(ctx context.Context, repositoryID int) (canSchedule, canInfer bool, _ error) + SetRepositoryExceptions(ctx context.Context, repositoryID int, canSchedule, canInfer bool) error GetIndexConfigurationByRepositoryID(ctx context.Context, repositoryID int) (shared.IndexConfiguration, bool, error) UpdateIndexConfigurationByRepositoryID(ctx context.Context, repositoryID int, data []byte) error diff --git a/enterprise/internal/codeintel/autoindexing/mocks_test.go b/enterprise/internal/codeintel/autoindexing/mocks_test.go index ba03c4b58f096..5c91c5d8f133d 100644 --- a/enterprise/internal/codeintel/autoindexing/mocks_test.go +++ b/enterprise/internal/codeintel/autoindexing/mocks_test.go @@ -61,6 +61,9 @@ type MockStore struct { // QueueRepoRevFunc is an instance of a mock function object controlling // the behavior of the method QueueRepoRev. QueueRepoRevFunc *StoreQueueRepoRevFunc + // RepositoryExceptionsFunc is an instance of a mock function object + // controlling the behavior of the method RepositoryExceptions. + RepositoryExceptionsFunc *StoreRepositoryExceptionsFunc // RepositoryIDsWithConfigurationFunc is an instance of a mock function // object controlling the behavior of the method // RepositoryIDsWithConfiguration. @@ -71,6 +74,9 @@ type MockStore struct { // SetInferenceScriptFunc is an instance of a mock function object // controlling the behavior of the method SetInferenceScript. SetInferenceScriptFunc *StoreSetInferenceScriptFunc + // SetRepositoryExceptionsFunc is an instance of a mock function object + // controlling the behavior of the method SetRepositoryExceptions. + SetRepositoryExceptionsFunc *StoreSetRepositoryExceptionsFunc // TopRepositoriesToConfigureFunc is an instance of a mock function // object controlling the behavior of the method // TopRepositoriesToConfigure. @@ -147,6 +153,11 @@ func NewMockStore() *MockStore { return }, }, + RepositoryExceptionsFunc: &StoreRepositoryExceptionsFunc{ + defaultHook: func(context.Context, int) (r0 bool, r1 bool, r2 error) { + return + }, + }, RepositoryIDsWithConfigurationFunc: &StoreRepositoryIDsWithConfigurationFunc{ defaultHook: func(context.Context, int, int) (r0 []shared1.RepositoryWithAvailableIndexers, r1 int, r2 error) { return @@ -162,6 +173,11 @@ func NewMockStore() *MockStore { return }, }, + SetRepositoryExceptionsFunc: &StoreSetRepositoryExceptionsFunc{ + defaultHook: func(context.Context, int, bool, bool) (r0 error) { + return + }, + }, TopRepositoriesToConfigureFunc: &StoreTopRepositoriesToConfigureFunc{ defaultHook: func(context.Context, int) (r0 []shared1.RepositoryWithCount, r1 error) { return @@ -244,6 +260,11 @@ func NewStrictMockStore() *MockStore { panic("unexpected invocation of MockStore.QueueRepoRev") }, }, + RepositoryExceptionsFunc: &StoreRepositoryExceptionsFunc{ + defaultHook: func(context.Context, int) (bool, bool, error) { + panic("unexpected invocation of MockStore.RepositoryExceptions") + }, + }, RepositoryIDsWithConfigurationFunc: &StoreRepositoryIDsWithConfigurationFunc{ defaultHook: func(context.Context, int, int) ([]shared1.RepositoryWithAvailableIndexers, int, error) { panic("unexpected invocation of MockStore.RepositoryIDsWithConfiguration") @@ -259,6 +280,11 @@ func NewStrictMockStore() *MockStore { panic("unexpected invocation of MockStore.SetInferenceScript") }, }, + SetRepositoryExceptionsFunc: &StoreSetRepositoryExceptionsFunc{ + defaultHook: func(context.Context, int, bool, bool) error { + panic("unexpected invocation of MockStore.SetRepositoryExceptions") + }, + }, TopRepositoriesToConfigureFunc: &StoreTopRepositoriesToConfigureFunc{ defaultHook: func(context.Context, int) ([]shared1.RepositoryWithCount, error) { panic("unexpected invocation of MockStore.TopRepositoriesToConfigure") @@ -319,6 +345,9 @@ func NewMockStoreFrom(i store.Store) *MockStore { QueueRepoRevFunc: &StoreQueueRepoRevFunc{ defaultHook: i.QueueRepoRev, }, + RepositoryExceptionsFunc: &StoreRepositoryExceptionsFunc{ + defaultHook: i.RepositoryExceptions, + }, RepositoryIDsWithConfigurationFunc: &StoreRepositoryIDsWithConfigurationFunc{ defaultHook: i.RepositoryIDsWithConfiguration, }, @@ -328,6 +357,9 @@ func NewMockStoreFrom(i store.Store) *MockStore { SetInferenceScriptFunc: &StoreSetInferenceScriptFunc{ defaultHook: i.SetInferenceScript, }, + SetRepositoryExceptionsFunc: &StoreSetRepositoryExceptionsFunc{ + defaultHook: i.SetRepositoryExceptions, + }, TopRepositoriesToConfigureFunc: &StoreTopRepositoriesToConfigureFunc{ defaultHook: i.TopRepositoriesToConfigure, }, @@ -1570,6 +1602,117 @@ func (c StoreQueueRepoRevFuncCall) Results() []interface{} { return []interface{}{c.Result0} } +// StoreRepositoryExceptionsFunc describes the behavior when the +// RepositoryExceptions method of the parent MockStore instance is invoked. +type StoreRepositoryExceptionsFunc struct { + defaultHook func(context.Context, int) (bool, bool, error) + hooks []func(context.Context, int) (bool, bool, error) + history []StoreRepositoryExceptionsFuncCall + mutex sync.Mutex +} + +// RepositoryExceptions delegates to the next hook function in the queue and +// stores the parameter and result values of this invocation. +func (m *MockStore) RepositoryExceptions(v0 context.Context, v1 int) (bool, bool, error) { + r0, r1, r2 := m.RepositoryExceptionsFunc.nextHook()(v0, v1) + m.RepositoryExceptionsFunc.appendCall(StoreRepositoryExceptionsFuncCall{v0, v1, r0, r1, r2}) + return r0, r1, r2 +} + +// SetDefaultHook sets function that is called when the RepositoryExceptions +// method of the parent MockStore instance is invoked and the hook queue is +// empty. +func (f *StoreRepositoryExceptionsFunc) SetDefaultHook(hook func(context.Context, int) (bool, bool, error)) { + f.defaultHook = hook +} + +// PushHook adds a function to the end of hook queue. Each invocation of the +// RepositoryExceptions method of the parent MockStore instance invokes the +// hook at the front of the queue and discards it. After the queue is empty, +// the default hook function is invoked for any future action. +func (f *StoreRepositoryExceptionsFunc) PushHook(hook func(context.Context, int) (bool, bool, error)) { + f.mutex.Lock() + f.hooks = append(f.hooks, hook) + f.mutex.Unlock() +} + +// SetDefaultReturn calls SetDefaultHook with a function that returns the +// given values. +func (f *StoreRepositoryExceptionsFunc) SetDefaultReturn(r0 bool, r1 bool, r2 error) { + f.SetDefaultHook(func(context.Context, int) (bool, bool, error) { + return r0, r1, r2 + }) +} + +// PushReturn calls PushHook with a function that returns the given values. +func (f *StoreRepositoryExceptionsFunc) PushReturn(r0 bool, r1 bool, r2 error) { + f.PushHook(func(context.Context, int) (bool, bool, error) { + return r0, r1, r2 + }) +} + +func (f *StoreRepositoryExceptionsFunc) nextHook() func(context.Context, int) (bool, bool, error) { + f.mutex.Lock() + defer f.mutex.Unlock() + + if len(f.hooks) == 0 { + return f.defaultHook + } + + hook := f.hooks[0] + f.hooks = f.hooks[1:] + return hook +} + +func (f *StoreRepositoryExceptionsFunc) appendCall(r0 StoreRepositoryExceptionsFuncCall) { + f.mutex.Lock() + f.history = append(f.history, r0) + f.mutex.Unlock() +} + +// History returns a sequence of StoreRepositoryExceptionsFuncCall objects +// describing the invocations of this function. +func (f *StoreRepositoryExceptionsFunc) History() []StoreRepositoryExceptionsFuncCall { + f.mutex.Lock() + history := make([]StoreRepositoryExceptionsFuncCall, len(f.history)) + copy(history, f.history) + f.mutex.Unlock() + + return history +} + +// StoreRepositoryExceptionsFuncCall is an object that describes an +// invocation of method RepositoryExceptions on an instance of MockStore. +type StoreRepositoryExceptionsFuncCall struct { + // Arg0 is the value of the 1st argument passed to this method + // invocation. + Arg0 context.Context + // Arg1 is the value of the 2nd argument passed to this method + // invocation. + Arg1 int + // Result0 is the value of the 1st result returned from this method + // invocation. + Result0 bool + // Result1 is the value of the 2nd result returned from this method + // invocation. + Result1 bool + // Result2 is the value of the 3rd result returned from this method + // invocation. + Result2 error +} + +// Args returns an interface slice containing the arguments of this +// invocation. +func (c StoreRepositoryExceptionsFuncCall) Args() []interface{} { + return []interface{}{c.Arg0, c.Arg1} +} + +// Results returns an interface slice containing the results of this +// invocation. +func (c StoreRepositoryExceptionsFuncCall) Results() []interface{} { + return []interface{}{c.Result0, c.Result1, c.Result2} +} + // StoreRepositoryIDsWithConfigurationFunc describes the behavior when the // RepositoryIDsWithConfiguration method of the parent MockStore instance is // invoked. @@ -1904,6 +2047,118 @@ func (c StoreSetInferenceScriptFuncCall) Results() []interface{} { return []interface{}{c.Result0} } +// StoreSetRepositoryExceptionsFunc describes the behavior when the +// SetRepositoryExceptions method of the parent MockStore instance is +// invoked. +type StoreSetRepositoryExceptionsFunc struct { + defaultHook func(context.Context, int, bool, bool) error + hooks []func(context.Context, int, bool, bool) error + history []StoreSetRepositoryExceptionsFuncCall + mutex sync.Mutex +} + +// SetRepositoryExceptions delegates to the next hook function in the queue +// and stores the parameter and result values of this invocation. +func (m *MockStore) SetRepositoryExceptions(v0 context.Context, v1 int, v2 bool, v3 bool) error { + r0 := m.SetRepositoryExceptionsFunc.nextHook()(v0, v1, v2, v3) + m.SetRepositoryExceptionsFunc.appendCall(StoreSetRepositoryExceptionsFuncCall{v0, v1, v2, v3, r0}) + return r0 +} + +// SetDefaultHook sets function that is called when the +// SetRepositoryExceptions method of the parent MockStore instance is +// invoked and the hook queue is empty. +func (f *StoreSetRepositoryExceptionsFunc) SetDefaultHook(hook func(context.Context, int, bool, bool) error) { + f.defaultHook = hook +} + +// PushHook adds a function to the end of hook queue. Each invocation of the +// SetRepositoryExceptions method of the parent MockStore instance invokes +// the hook at the front of the queue and discards it. After the queue is +// empty, the default hook function is invoked for any future action. +func (f *StoreSetRepositoryExceptionsFunc) PushHook(hook func(context.Context, int, bool, bool) error) { + f.mutex.Lock() + f.hooks = append(f.hooks, hook) + f.mutex.Unlock() +} + +// SetDefaultReturn calls SetDefaultHook with a function that returns the +// given values. +func (f *StoreSetRepositoryExceptionsFunc) SetDefaultReturn(r0 error) { + f.SetDefaultHook(func(context.Context, int, bool, bool) error { + return r0 + }) +} + +// PushReturn calls PushHook with a function that returns the given values. +func (f *StoreSetRepositoryExceptionsFunc) PushReturn(r0 error) { + f.PushHook(func(context.Context, int, bool, bool) error { + return r0 + }) +} + +func (f *StoreSetRepositoryExceptionsFunc) nextHook() func(context.Context, int, bool, bool) error { + f.mutex.Lock() + defer f.mutex.Unlock() + + if len(f.hooks) == 0 { + return f.defaultHook + } + + hook := f.hooks[0] + f.hooks = f.hooks[1:] + return hook +} + +func (f *StoreSetRepositoryExceptionsFunc) appendCall(r0 StoreSetRepositoryExceptionsFuncCall) { + f.mutex.Lock() + f.history = append(f.history, r0) + f.mutex.Unlock() +} + +// History returns a sequence of StoreSetRepositoryExceptionsFuncCall +// objects describing the invocations of this function. +func (f *StoreSetRepositoryExceptionsFunc) History() []StoreSetRepositoryExceptionsFuncCall { + f.mutex.Lock() + history := make([]StoreSetRepositoryExceptionsFuncCall, len(f.history)) + copy(history, f.history) + f.mutex.Unlock() + + return history +} + +// StoreSetRepositoryExceptionsFuncCall is an object that describes an +// invocation of method SetRepositoryExceptions on an instance of MockStore. +type StoreSetRepositoryExceptionsFuncCall struct { + // Arg0 is the value of the 1st argument passed to this method + // invocation. + Arg0 context.Context + // Arg1 is the value of the 2nd argument passed to this method + // invocation. + Arg1 int + // Arg2 is the value of the 3rd argument passed to this method + // invocation. + Arg2 bool + // Arg3 is the value of the 4th argument passed to this method + // invocation. + Arg3 bool + // Result0 is the value of the 1st result returned from this method + // invocation. + Result0 error +} + +// Args returns an interface slice containing the arguments of this +// invocation. +func (c StoreSetRepositoryExceptionsFuncCall) Args() []interface{} { + return []interface{}{c.Arg0, c.Arg1, c.Arg2, c.Arg3} +} + +// Results returns an interface slice containing the results of this +// invocation. +func (c StoreSetRepositoryExceptionsFuncCall) Results() []interface{} { + return []interface{}{c.Result0} +} + // StoreTopRepositoriesToConfigureFunc describes the behavior when the // TopRepositoriesToConfigure method of the parent MockStore instance is // invoked. diff --git a/enterprise/internal/codeintel/autoindexing/service.go b/enterprise/internal/codeintel/autoindexing/service.go index bb40681d6858b..5405d13c21d79 100644 --- a/enterprise/internal/codeintel/autoindexing/service.go +++ b/enterprise/internal/codeintel/autoindexing/service.go @@ -117,7 +117,7 @@ func (s *Service) InferIndexConfiguration(ctx context.Context, repositoryID int, return nil, nil, err } - indexJobHints, err := s.jobSelector.InferIndexJobHintsFromRepositoryStructure(ctx, repo.Name, commit) + indexJobHints, err := s.jobSelector.InferIndexJobHintsFromRepositoryStructure(ctx, repositoryID, repo.Name, commit) if err != nil { return nil, nil, err } diff --git a/enterprise/internal/codeintel/autoindexing/service_test.go b/enterprise/internal/codeintel/autoindexing/service_test.go index 6c0aa79ae50b2..2c5929e7a59d8 100644 --- a/enterprise/internal/codeintel/autoindexing/service_test.go +++ b/enterprise/internal/codeintel/autoindexing/service_test.go @@ -53,6 +53,8 @@ func TestQueueIndexesExplicit(t *testing.T) { mockDBStore.InsertIndexesFunc.SetDefaultHook(func(ctx context.Context, indexes []uploadsshared.Index) ([]uploadsshared.Index, error) { return indexes, nil }) + mockDBStore.RepositoryExceptionsFunc.SetDefaultReturn(true, true, nil) + mockGitserverClient := gitserver.NewMockClient() mockGitserverClient.ResolveRevisionFunc.SetDefaultHook(func(ctx context.Context, repo api.RepoName, rev string, opts gitserver.ResolveRevisionOptions) (api.CommitID, error) { return api.CommitID(fmt.Sprintf("c%s", repo)), nil @@ -151,6 +153,7 @@ func TestQueueIndexesInDatabase(t *testing.T) { return indexes, nil }) mockDBStore.GetIndexConfigurationByRepositoryIDFunc.SetDefaultReturn(indexConfiguration, true, nil) + mockDBStore.RepositoryExceptionsFunc.SetDefaultReturn(true, true, nil) mockGitserverClient := gitserver.NewMockClient() mockGitserverClient.ResolveRevisionFunc.SetDefaultHook(func(ctx context.Context, repo api.RepoName, rev string, opts gitserver.ResolveRevisionOptions) (api.CommitID, error) { @@ -253,6 +256,7 @@ func TestQueueIndexesInRepository(t *testing.T) { mockDBStore.InsertIndexesFunc.SetDefaultHook(func(ctx context.Context, indexes []uploadsshared.Index) ([]uploadsshared.Index, error) { return indexes, nil }) + mockDBStore.RepositoryExceptionsFunc.SetDefaultReturn(true, true, nil) gitserverClient := gitserver.NewMockClient() gitserverClient.ResolveRevisionFunc.SetDefaultHook(func(ctx context.Context, repo api.RepoName, rev string, opts gitserver.ResolveRevisionOptions) (api.CommitID, error) { @@ -328,6 +332,7 @@ func TestQueueIndexesInferred(t *testing.T) { mockDBStore.InsertIndexesFunc.SetDefaultHook(func(ctx context.Context, indexes []uploadsshared.Index) ([]uploadsshared.Index, error) { return indexes, nil }) + mockDBStore.RepositoryExceptionsFunc.SetDefaultReturn(true, true, nil) gitserverClient := gitserver.NewMockClient() gitserverClient.ResolveRevisionFunc.SetDefaultHook(func(ctx context.Context, repo api.RepoName, rev string, opts gitserver.ResolveRevisionOptions) (api.CommitID, error) { @@ -398,6 +403,7 @@ func TestQueueIndexesForPackage(t *testing.T) { return indexes, nil }) mockDBStore.IsQueuedFunc.SetDefaultReturn(false, nil) + mockDBStore.RepositoryExceptionsFunc.SetDefaultReturn(true, true, nil) gitserverClient := gitserver.NewMockClient() gitserverClient.ResolveRevisionFunc.SetDefaultHook(func(ctx context.Context, repo api.RepoName, versionString string, opts gitserver.ResolveRevisionOptions) (api.CommitID, error) { diff --git a/internal/database/schema.json b/internal/database/schema.json index b809da9e56b1c..6fc8914a29938 100755 --- a/internal/database/schema.json +++ b/internal/database/schema.json @@ -420,6 +420,15 @@ "Increment": 1, "CycleOption": "NO" }, + { + "Name": "codeintel_autoindexing_exceptions_id_seq", + "TypeName": "integer", + "StartValue": 1, + "MinimumValue": 1, + "MaximumValue": 2147483647, + "Increment": 1, + "CycleOption": "NO" + }, { "Name": "codeintel_initial_path_ranks_id_seq", "TypeName": "bigint", @@ -6959,6 +6968,96 @@ "Constraints": null, "Triggers": [] }, + { + "Name": "codeintel_autoindexing_exceptions", + "Comment": "", + "Columns": [ + { + "Name": "disable_inference", + "Index": 4, + "TypeName": "boolean", + "IsNullable": false, + "Default": "false", + "CharacterMaximumLength": 0, + "IsIdentity": false, + "IdentityGeneration": "", + "IsGenerated": "NEVER", + "GenerationExpression": "", + "Comment": "" + }, + { + "Name": "disable_scheduling", + "Index": 3, + "TypeName": "boolean", + "IsNullable": false, + "Default": "false", + "CharacterMaximumLength": 0, + "IsIdentity": false, + "IdentityGeneration": "", + "IsGenerated": "NEVER", + "GenerationExpression": "", + "Comment": "" + }, + { + "Name": "id", + "Index": 1, + "TypeName": "integer", + "IsNullable": false, + "Default": "nextval('codeintel_autoindexing_exceptions_id_seq'::regclass)", + "CharacterMaximumLength": 0, + "IsIdentity": false, + "IdentityGeneration": "", + "IsGenerated": "NEVER", + "GenerationExpression": "", + "Comment": "" + }, + { + "Name": "repository_id", + "Index": 2, + "TypeName": "integer", + "IsNullable": false, + "Default": "", + "CharacterMaximumLength": 0, + "IsIdentity": false, + "IdentityGeneration": "", + "IsGenerated": "NEVER", + "GenerationExpression": "", + "Comment": "" + } + ], + "Indexes": [ + { + "Name": "codeintel_autoindexing_exceptions_pkey", + "IsPrimaryKey": true, + "IsUnique": true, + "IsExclusion": false, + "IsDeferrable": false, + "IndexDefinition": "CREATE UNIQUE INDEX codeintel_autoindexing_exceptions_pkey ON codeintel_autoindexing_exceptions USING btree (id)", + "ConstraintType": "p", + "ConstraintDefinition": "PRIMARY KEY (id)" + }, + { + "Name": "codeintel_autoindexing_exceptions_repository_id_key", + "IsPrimaryKey": false, + "IsUnique": true, + "IsExclusion": false, + "IsDeferrable": false, + "IndexDefinition": "CREATE UNIQUE INDEX codeintel_autoindexing_exceptions_repository_id_key ON codeintel_autoindexing_exceptions USING btree (repository_id)", + "ConstraintType": "u", + "ConstraintDefinition": "UNIQUE (repository_id)" + } + ], + "Constraints": [ + { + "Name": "codeintel_autoindexing_exceptions_repository_id_fkey", + "ConstraintType": "f", + "RefTableName": "repo", + "IsDeferrable": false, + "ConstraintDefinition": "FOREIGN KEY (repository_id) REFERENCES repo(id) ON DELETE CASCADE" + } + ], + "Triggers": [] + }, { "Name": "codeintel_commit_dates", "Comment": "Maps commits within a repository to the commit date as reported by gitserver.", diff --git a/internal/database/schema.md b/internal/database/schema.md index 68fd67badc1b6..d69a745d28dd6 100755 --- a/internal/database/schema.md +++ b/internal/database/schema.md @@ -795,6 +795,22 @@ Indexes: ``` +# Table "public.codeintel_autoindexing_exceptions" +``` + Column | Type | Collation | Nullable | Default +--------------------+---------+-----------+----------+--------------------------------------------------------------- + id | integer | | not null | nextval('codeintel_autoindexing_exceptions_id_seq'::regclass) + repository_id | integer | | not null | + disable_scheduling | boolean | | not null | false + disable_inference | boolean | | not null | false +Indexes: + "codeintel_autoindexing_exceptions_pkey" PRIMARY KEY, btree (id) + "codeintel_autoindexing_exceptions_repository_id_key" UNIQUE CONSTRAINT, btree (repository_id) +Foreign-key constraints: + "codeintel_autoindexing_exceptions_repository_id_fkey" FOREIGN KEY (repository_id) REFERENCES repo(id) ON DELETE CASCADE + +``` + # Table "public.codeintel_commit_dates" ``` Column | Type | Collation | Nullable | Default @@ -3210,6 +3226,7 @@ Referenced by: TABLE "changeset_specs" CONSTRAINT "changeset_specs_repo_id_fkey" FOREIGN KEY (repo_id) REFERENCES repo(id) DEFERRABLE TABLE "changesets" CONSTRAINT "changesets_repo_id_fkey" FOREIGN KEY (repo_id) REFERENCES repo(id) ON DELETE CASCADE DEFERRABLE TABLE "cm_last_searched" CONSTRAINT "cm_last_searched_repo_id_fkey" FOREIGN KEY (repo_id) REFERENCES repo(id) ON DELETE CASCADE + TABLE "codeintel_autoindexing_exceptions" CONSTRAINT "codeintel_autoindexing_exceptions_repository_id_fkey" FOREIGN KEY (repository_id) REFERENCES repo(id) ON DELETE CASCADE TABLE "codeowners" CONSTRAINT "codeowners_repo_id_fkey" FOREIGN KEY (repo_id) REFERENCES repo(id) ON DELETE CASCADE TABLE "discussion_threads_target_repo" CONSTRAINT "discussion_threads_target_repo_repo_id_fkey" FOREIGN KEY (repo_id) REFERENCES repo(id) ON DELETE CASCADE TABLE "external_service_repos" CONSTRAINT "external_service_repos_repo_id_fkey" FOREIGN KEY (repo_id) REFERENCES repo(id) ON DELETE CASCADE DEFERRABLE diff --git a/migrations/BUILD.bazel b/migrations/BUILD.bazel index 37accdf590384..5efbcce847ed8 100644 --- a/migrations/BUILD.bazel +++ b/migrations/BUILD.bazel @@ -919,6 +919,9 @@ go_library( "frontend/1683290474_user_code_completions_quota/down.sql", "frontend/1683290474_user_code_completions_quota/metadata.yaml", "frontend/1683290474_user_code_completions_quota/up.sql", + "frontend/1683561153_add_autoindexing_repo_exceptions_table/down.sql", + "frontend/1683561153_add_autoindexing_repo_exceptions_table/metadata.yaml", + "frontend/1683561153_add_autoindexing_repo_exceptions_table/up.sql", "frontend/1683246005_llmproxynoaccesstokenenable/down.sql", "frontend/1683246005_llmproxynoaccesstokenenable/metadata.yaml", "frontend/1683246005_llmproxynoaccesstokenenable/up.sql", diff --git a/migrations/frontend/1683561153_add_autoindexing_repo_exceptions_table/down.sql b/migrations/frontend/1683561153_add_autoindexing_repo_exceptions_table/down.sql new file mode 100644 index 0000000000000..5751103c149dd --- /dev/null +++ b/migrations/frontend/1683561153_add_autoindexing_repo_exceptions_table/down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS codeintel_autoindexing_exceptions; diff --git a/migrations/frontend/1683561153_add_autoindexing_repo_exceptions_table/metadata.yaml b/migrations/frontend/1683561153_add_autoindexing_repo_exceptions_table/metadata.yaml new file mode 100644 index 0000000000000..6e609a3c1b6d7 --- /dev/null +++ b/migrations/frontend/1683561153_add_autoindexing_repo_exceptions_table/metadata.yaml @@ -0,0 +1,2 @@ +name: Add autoindexing repo exceptions table +parents: [1683290474, 1683295546] diff --git a/migrations/frontend/1683561153_add_autoindexing_repo_exceptions_table/up.sql b/migrations/frontend/1683561153_add_autoindexing_repo_exceptions_table/up.sql new file mode 100644 index 0000000000000..fad9cd4864a30 --- /dev/null +++ b/migrations/frontend/1683561153_add_autoindexing_repo_exceptions_table/up.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS codeintel_autoindexing_exceptions( + id SERIAL PRIMARY KEY, + repository_id INTEGER NOT NULL UNIQUE, + disable_scheduling BOOLEAN NOT NULL DEFAULT FALSE, + disable_inference BOOLEAN NOT NULL DEFAULT FALSE, + FOREIGN KEY (repository_id) REFERENCES repo(id) ON DELETE CASCADE +); diff --git a/migrations/frontend/squashed.sql b/migrations/frontend/squashed.sql index 39426ae57e886..9a519e7135688 100755 --- a/migrations/frontend/squashed.sql +++ b/migrations/frontend/squashed.sql @@ -1629,6 +1629,23 @@ CREATE SEQUENCE codeintel_autoindex_queue_id_seq ALTER SEQUENCE codeintel_autoindex_queue_id_seq OWNED BY codeintel_autoindex_queue.id; +CREATE TABLE codeintel_autoindexing_exceptions ( + id integer NOT NULL, + repository_id integer NOT NULL, + disable_scheduling boolean DEFAULT false NOT NULL, + disable_inference boolean DEFAULT false NOT NULL +); + +CREATE SEQUENCE codeintel_autoindexing_exceptions_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE codeintel_autoindexing_exceptions_id_seq OWNED BY codeintel_autoindexing_exceptions.id; + CREATE TABLE codeintel_commit_dates ( repository_id integer NOT NULL, commit_bytea bytea NOT NULL, @@ -4640,6 +4657,8 @@ ALTER TABLE ONLY cm_webhooks ALTER COLUMN id SET DEFAULT nextval('cm_webhooks_id ALTER TABLE ONLY codeintel_autoindex_queue ALTER COLUMN id SET DEFAULT nextval('codeintel_autoindex_queue_id_seq'::regclass); +ALTER TABLE ONLY codeintel_autoindexing_exceptions ALTER COLUMN id SET DEFAULT nextval('codeintel_autoindexing_exceptions_id_seq'::regclass); + ALTER TABLE ONLY codeintel_initial_path_ranks ALTER COLUMN id SET DEFAULT nextval('codeintel_initial_path_ranks_id_seq'::regclass); ALTER TABLE ONLY codeintel_initial_path_ranks_processed ALTER COLUMN id SET DEFAULT nextval('codeintel_initial_path_ranks_processed_id_seq'::regclass); @@ -4917,6 +4936,12 @@ ALTER TABLE ONLY cm_webhooks ALTER TABLE ONLY codeintel_autoindex_queue ADD CONSTRAINT codeintel_autoindex_queue_pkey PRIMARY KEY (id); +ALTER TABLE ONLY codeintel_autoindexing_exceptions + ADD CONSTRAINT codeintel_autoindexing_exceptions_pkey PRIMARY KEY (id); + +ALTER TABLE ONLY codeintel_autoindexing_exceptions + ADD CONSTRAINT codeintel_autoindexing_exceptions_repository_id_key UNIQUE (repository_id); + ALTER TABLE ONLY codeintel_commit_dates ADD CONSTRAINT codeintel_commit_dates_pkey PRIMARY KEY (repository_id, commit_bytea); @@ -6030,6 +6055,9 @@ ALTER TABLE ONLY cm_webhooks ALTER TABLE ONLY cm_webhooks ADD CONSTRAINT cm_webhooks_monitor_fkey FOREIGN KEY (monitor) REFERENCES cm_monitors(id) ON DELETE CASCADE; +ALTER TABLE ONLY codeintel_autoindexing_exceptions + ADD CONSTRAINT codeintel_autoindexing_exceptions_repository_id_fkey FOREIGN KEY (repository_id) REFERENCES repo(id) ON DELETE CASCADE; + ALTER TABLE ONLY codeintel_ranking_exports ADD CONSTRAINT codeintel_ranking_exports_upload_id_fkey FOREIGN KEY (upload_id) REFERENCES lsif_uploads(id) ON DELETE SET NULL;