Skip to content

Commit 82fe19d

Browse files
authored
fix(init): remove components from the database if they no longer exist in the definition list (#1049)
Because - When a component is removed from the definition list, it should also be removed from the definition index table. This commit - removes components from the database if they no longer exist in the definition list.
1 parent 9de0b03 commit 82fe19d

20 files changed

+788
-19
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ integration-test: ## Run integration test
136136

137137
.PHONY: gen-mock
138138
gen-mock: ## Generate mock files
139-
@go install github.com/gojuno/minimock/v3/cmd/minimock@v3.4.0
139+
@go install github.com/gojuno/minimock/v3/cmd/minimock@v3.4.5
140140
@go generate -run minimock ./...
141141

142142
.PHONY: gen-component-doc

cmd/init/definitionupdater/updater.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/gofrs/uuid"
99
"github.com/launchdarkly/go-semver"
10+
"go.uber.org/zap"
1011

1112
"github.com/instill-ai/pipeline-backend/pkg/datamodel"
1213
"github.com/instill-ai/pipeline-backend/pkg/repository"
@@ -25,13 +26,34 @@ func UpdateComponentDefinitionIndex(ctx context.Context, repo repository.Reposit
2526
defs := componentstore.Init(componentstore.InitParams{
2627
Logger: logger,
2728
}).ListDefinitions(nil, true)
28-
for _, def := range defs {
2929

30+
// Create a map of UIDs from the current definitions for quick lookup
31+
currentDefUIDs := make(map[string]bool)
32+
for _, def := range defs {
33+
currentDefUIDs[def.GetUid()] = true
3034
if err := updateComponentDefinition(ctx, def, repo); err != nil {
3135
return err
3236
}
3337
}
3438

39+
// Get all component definitions from the database
40+
dbDefs, err := repo.ListAllComponentDefinitions(ctx)
41+
if err != nil {
42+
return fmt.Errorf("failed to get component definitions from database: %w", err)
43+
}
44+
45+
// Delete component definitions that don't exist in the current definitions
46+
for _, dbDef := range dbDefs {
47+
if !currentDefUIDs[dbDef.UID.String()] {
48+
logger.Info("Deleting component definition that no longer exists",
49+
zap.String("uid", dbDef.UID.String()),
50+
zap.String("id", dbDef.ID))
51+
if err := repo.DeleteComponentDefinition(ctx, dbDef.UID); err != nil {
52+
return fmt.Errorf("failed to delete component definition %s: %w", dbDef.ID, err)
53+
}
54+
}
55+
}
56+
3557
return nil
3658
}
3759

pkg/component/ai/fireworksai/v0/fireworks_client_interface_mock_test.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/component/ai/groq/v0/groq_client_interface_mock_test.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/component/ai/ollama/v0/ollama_client_interface_mock.gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/component/application/freshdesk/v0/freshdesk_interface_mock_test.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/component/data/instillartifact/v0/README.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,10 @@ search the chunks in the catalog.
359359
| Namespace (required) | `namespace` | string | Fill in your namespace, you can get namespace through the tab of switching namespace. |
360360
| Text Prompt (required) | `text-prompt` | string | The prompt string to search the chunks. |
361361
| Top K | `top-k` | integer | The number of top chunks to return. The range is from 1~20, and default is 5. |
362-
| Filename | `filename` | string | File name to filter, empty for all. |
362+
| File UID | `file-uid` | string | Optional filter by file. |
363363
| File Media Type | `file-media-type` | string | The media type to filter, empty for all. <br/><details><summary><strong>Enum values</strong></summary><ul><li>`document`</li><li>`image`</li><li>`audio`</li><li>`video`</li></ul></details> |
364364
| Content Type | `content-type` | string | The content type to filter, empty for all. <br/><details><summary><strong>Enum values</strong></summary><ul><li>`chunk`</li><li>`summary`</li><li>`augmented`</li></ul></details> |
365+
| Filename | `filename` | string | File name to filter, empty for all. This field is deprecated and the file UID should be used instead. The filename isn't unique by catalog and therefore the filter might produce unexpected results. |
365366
</div>
366367

367368

@@ -388,6 +389,7 @@ search the chunks in the catalog.
388389
| Chunk UID | `chunk-uid` | string | The unique identifier of the chunk. |
389390
| Similarity | `similarity-score` | number | The similarity score of the chunk. |
390391
| Source File Name | `source-file-name` | string | The name of the source file. |
392+
| Source File UID | `source-file-uid` | string | The UID of the source file. |
391393
| Text Content | `text-content` | string | The text content of the chunk. |
392394
</div>
393395
</details>
@@ -433,6 +435,7 @@ Reply the questions based on the files in the catalog.
433435
| Chunk UID | `chunk-uid` | string | The unique identifier of the chunk. |
434436
| Similarity | `similarity-score` | number | The similarity score of the chunk. |
435437
| Source File Name | `source-file-name` | string | The name of the source file. |
438+
| Source File UID | `source-file-uid` | string | The UID of the source file. |
436439
| Text Content | `text-content` | string | The text content of the chunk. |
437440
</div>
438441
</details>

pkg/component/internal/mock/artifact_public_service_client_mock.gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/component/internal/mock/artifact_public_service_server_mock.gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/component/internal/mock/error_handler_mock.gen.go

Lines changed: 23 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)