Skip to content

Commit 5d15395

Browse files
authored
feat: Adds 'all' datastore config option (#579)
Adds a new `datastore: all` configuration option to `domain.yaml`. When `datastore: all` is set: - **Reads**: During env loading Initial data is read from remote catalog - **Writes**: Merge operations write to both local and remote catalog ## Configuration Example ```yaml environments: example: network_types: - testnet protected: false datastore: all ```
1 parent b301941 commit 5d15395

4 files changed

Lines changed: 54 additions & 7 deletions

File tree

.changeset/ten-readers-dance.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"chainlink-deployments-framework": minor
3+
---
4+
5+
feat: adds 'all' datastore config option

engine/cld/config/domain/domain.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ const (
1717
DatastoreTypeFile DatastoreType = "file"
1818
// DatastoreTypeCatalog indicates data should be persisted to the remote catalog service.
1919
DatastoreTypeCatalog DatastoreType = "catalog"
20+
// DatastoreTypeAll indicates data should be persisted to both local JSON files and the remote catalog service.
21+
// This is useful to keep backward compatibility during the transition period from file-based to remote catalog.
22+
DatastoreTypeAll DatastoreType = "all"
2023
)
2124

2225
// String returns the string representation of the DatastoreType.
@@ -26,7 +29,7 @@ func (d DatastoreType) String() string {
2629

2730
// IsValid checks if the DatastoreType is a valid value.
2831
func (d DatastoreType) IsValid() bool {
29-
return d == DatastoreTypeFile || d == DatastoreTypeCatalog
32+
return d == DatastoreTypeFile || d == DatastoreTypeCatalog || d == DatastoreTypeAll
3033
}
3134

3235
// Environment represents a single environment configuration.
@@ -59,7 +62,7 @@ func (e *Environment) validate() error {
5962

6063
// Validate datastore field if provided
6164
if e.Datastore != "" && !e.Datastore.IsValid() {
62-
return fmt.Errorf("invalid datastore value: %s (must be 'file' or 'catalog')", e.Datastore)
65+
return fmt.Errorf("invalid datastore value: %s (must be 'file', 'catalog', or 'all')", e.Datastore)
6366
}
6467

6568
return nil

engine/cld/config/domain/domain_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ func TestDatastoreType_IsValid(t *testing.T) {
6666
datastore: DatastoreTypeCatalog,
6767
expected: true,
6868
},
69+
{
70+
name: "all is valid",
71+
datastore: DatastoreTypeAll,
72+
expected: true,
73+
},
6974
{
7075
name: "invalid value",
7176
datastore: DatastoreType("invalid"),
@@ -133,6 +138,14 @@ func TestEnvironment_Validate(t *testing.T) {
133138
},
134139
wantErr: false,
135140
},
141+
{
142+
name: "valid environment with all datastore",
143+
environment: Environment{
144+
NetworkTypes: []string{"testnet"},
145+
Datastore: DatastoreTypeAll,
146+
},
147+
wantErr: false,
148+
},
136149
{
137150
name: "valid environment without datastore (optional field)",
138151
environment: Environment{

engine/cld/legacy/cli/commands/migration.go

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -497,17 +497,17 @@ func (Commands) newMigrationDataStoreMerge(domain domain.Domain) *cobra.Command
497497
}
498498

499499
// Determine which merge method to use based on datastore configuration
500-
if cfg.DatastoreType == cfgdomain.DatastoreTypeCatalog {
501-
ctx := cmd.Context()
500+
switch cfg.DatastoreType {
501+
case cfgdomain.DatastoreTypeCatalog:
502502
// Catalog mode - merge to catalog service
503503
cmd.Printf("📡 Using catalog datastore mode (endpoint: %s)\n", cfg.Env.Catalog.GRPC)
504504

505-
catalog, catalogErr := cldcatalog.LoadCatalog(ctx, envKey, cfg, domain)
505+
catalog, catalogErr := cldcatalog.LoadCatalog(cmd.Context(), envKey, cfg, domain)
506506
if catalogErr != nil {
507507
return fmt.Errorf("failed to load catalog: %w", catalogErr)
508508
}
509509

510-
if err := envDir.MergeMigrationDataStoreCatalog(ctx, migrationName, timestamp, catalog); err != nil {
510+
if err := envDir.MergeMigrationDataStoreCatalog(cmd.Context(), migrationName, timestamp, catalog); err != nil {
511511
return fmt.Errorf("error during data store merge to catalog for %s %s %s: %w",
512512
domain, envKey, migrationName, err,
513513
)
@@ -516,7 +516,7 @@ func (Commands) newMigrationDataStoreMerge(domain domain.Domain) *cobra.Command
516516
cmd.Printf("✅ Merged data stores to catalog for %s %s %s\n",
517517
domain, envKey, migrationName,
518518
)
519-
} else {
519+
case cfgdomain.DatastoreTypeFile:
520520
// File mode - merge to local files
521521
cmd.Printf("📁 Using file-based datastore mode\n")
522522

@@ -529,6 +529,32 @@ func (Commands) newMigrationDataStoreMerge(domain domain.Domain) *cobra.Command
529529
cmd.Printf("✅ Merged data stores to local files for %s %s %s\n",
530530
domain, envKey, migrationName,
531531
)
532+
case cfgdomain.DatastoreTypeAll:
533+
// All mode - merge to both catalog and local files
534+
cmd.Printf("📡 Using all datastore mode (catalog: %s, file: %s)\n", cfg.Env.Catalog.GRPC, envDir.DataStoreDirPath())
535+
536+
catalog, catalogErr := cldcatalog.LoadCatalog(cmd.Context(), envKey, cfg, domain)
537+
if catalogErr != nil {
538+
return fmt.Errorf("failed to load catalog: %w", catalogErr)
539+
}
540+
541+
if err := envDir.MergeMigrationDataStoreCatalog(cmd.Context(), migrationName, timestamp, catalog); err != nil {
542+
return fmt.Errorf("error during data store merge to catalog for %s %s %s: %w",
543+
domain, envKey, migrationName, err,
544+
)
545+
}
546+
547+
if err := envDir.MergeMigrationDataStore(migrationName, timestamp); err != nil {
548+
return fmt.Errorf("error during data store merge to file for %s %s %s: %w",
549+
domain, envKey, migrationName, err,
550+
)
551+
}
552+
553+
cmd.Printf("✅ Merged data stores to both catalog and local files for %s %s %s\n",
554+
domain, envKey, migrationName,
555+
)
556+
default:
557+
return fmt.Errorf("invalid datastore type: %s", cfg.DatastoreType)
532558
}
533559

534560
return nil

0 commit comments

Comments
 (0)