-
Notifications
You must be signed in to change notification settings - Fork 3
feat(cmd): add catalog syncer #552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --- | ||
| "chainlink-deployments-framework": minor | ||
| --- | ||
|
|
||
| feat: add catalog service integration for datastore operations | ||
|
|
||
| Features: | ||
| - Add catalog service support for datastore management as alternative to local file storage | ||
| - Add `MergeMigrationDataStoreCatalog` method for catalog-based datastore persistence | ||
| - Existing `MergeMigrationDataStore` method continues to work for file-based storage (no breaking changes) | ||
| - Add unified `MergeDataStoreToCatalog` function for both initial migration and ongoing merge operations | ||
| - All catalog operations are transactional to prevent data inconsistencies | ||
| - Add `DatastoreType` configuration option (`file`/`catalog`) in domain.yaml to control storage backend | ||
| - Add new CLI command `datastore sync-to-catalog` for initial migration from file-based to catalog storage in CI | ||
| - Add `SyncDataStoreToCatalog` method to sync entire local datastore to catalog | ||
| - CLI automatically selects the appropriate merge method based on domain.yaml configuration | ||
| - Catalog mode does not modify local files - all updates go directly to the catalog service | ||
|
|
||
| Configuration: | ||
| - Set `datastore: catalog` in domain.yaml to enable catalog mode | ||
| - Set `datastore: file` or omit the setting to use traditional file-based storage | ||
| - CLI commands automatically detect the configuration and use the appropriate storage backend |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package datastore | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| ) | ||
|
|
||
| // MergeDataStoreToCatalog merges data from a source DataStore (either full local state or migration-specific) | ||
| // into a remote CatalogStore within a transaction. This ensures atomic updates - either all data is | ||
| // successfully merged or the entire operation is rolled back on failure. | ||
| // | ||
| // This function serves two purposes: | ||
| // 1. Initial migration: sync entire local datastore to catalog (full state push) | ||
| // 2. Ongoing operations: merge migration/changeset artifacts into catalog (incremental updates) | ||
| // | ||
| // The operation is transactional to prevent partial failures that could lead to data inconsistencies. | ||
| func MergeDataStoreToCatalog(ctx context.Context, sourceDS DataStore, catalog CatalogStore) error { | ||
| return catalog.WithTransaction(ctx, func(ctx context.Context, txCatalog BaseCatalogStore) error { | ||
| // Merge all address references to the catalog | ||
| addressRefs, err := sourceDS.Addresses().Fetch() | ||
| if err != nil { | ||
| return fmt.Errorf("failed to fetch address references from source store: %w", err) | ||
| } | ||
|
|
||
| for _, ref := range addressRefs { | ||
| if upsertErr := txCatalog.Addresses().Upsert(ctx, ref); upsertErr != nil { | ||
| return fmt.Errorf("failed to upsert address reference to catalog: %w", upsertErr) | ||
| } | ||
| } | ||
|
|
||
| // Merge all chain metadata to the catalog | ||
| chainMetadata, err := sourceDS.ChainMetadata().Fetch() | ||
| if err != nil { | ||
| return fmt.Errorf("failed to fetch chain metadata from source store: %w", err) | ||
| } | ||
|
|
||
| for _, metadata := range chainMetadata { | ||
| key := NewChainMetadataKey(metadata.ChainSelector) | ||
| if upsertErr := txCatalog.ChainMetadata().Upsert(ctx, key, metadata.Metadata); upsertErr != nil { | ||
| return fmt.Errorf("failed to upsert chain metadata to catalog: %w", upsertErr) | ||
| } | ||
| } | ||
|
|
||
| // Merge all contract metadata to the catalog | ||
| contractMetadata, err := sourceDS.ContractMetadata().Fetch() | ||
| if err != nil { | ||
| return fmt.Errorf("failed to fetch contract metadata from source store: %w", err) | ||
| } | ||
|
|
||
| for _, metadata := range contractMetadata { | ||
| key := NewContractMetadataKey(metadata.ChainSelector, metadata.Address) | ||
| if upsertErr := txCatalog.ContractMetadata().Upsert(ctx, key, metadata.Metadata); upsertErr != nil { | ||
| return fmt.Errorf("failed to upsert contract metadata to catalog: %w", upsertErr) | ||
| } | ||
| } | ||
|
|
||
| // Merge environment metadata to the catalog | ||
| envMetadata, err := sourceDS.EnvMetadata().Get() | ||
| if err != nil { | ||
| if !errors.Is(err, ErrEnvMetadataNotSet) { | ||
| return fmt.Errorf("failed to fetch environment metadata from source store: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // Merge the environment metadata (upsert semantics) | ||
| if setErr := txCatalog.EnvMetadata().Set(ctx, envMetadata.Metadata); setErr != nil { | ||
| return fmt.Errorf("failed to set environment metadata in catalog: %w", setErr) | ||
| } | ||
|
|
||
|
ajaskolski marked this conversation as resolved.
|
||
| return nil | ||
| }) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.