Description
Extend the ResourceDefinitionModel struct by implementing a new standalone method called BadgerDBFindAll. To maintain strict backward compatibility across the rest of the engine, do not modify or deprecate the existing etcd-based FindAll implementation. This new method will introduce standalone support to iterate through and retrieve all resource definitions stored under the specified namespace prefix directly from BadgerDB.
Requirements
- File Location:
internal/models/resource_definitions.go
- Method Signature Strategy: Introduce a new method named
BadgerDBFindAll() ([]string, error) on the ResourceDefinitionModel struct.
- Transactionality: Execute the prefix scan entirely within a BadgerDB View (read-only) transaction.
- Prefix Scanning:
- Instantiate a database iterator using default options via
txn.NewIterator(badger.DefaultIteratorOptions).
- Prefix scan using the standard byte boundary matching the legacy prefix namespace:
/resource_definitions/.
- Data Processing & Lifecycle Rules:
- Loop through matched database items, retrieving the raw payloads safely.
- Ensure you adhere to BadgerDB's item evaluation lifecycle rules by copying data safely out of the transaction scope (e.g., using
item.ValueCopy()).
- Append the string representation of each definition payload to a collection slice.
- Error Handling: If no keys match the designated prefix context, return a descriptive custom error:
fmt.Errorf("no resource definitions found") to guarantee parity with the etcd counterpart.
- Testing: Write a dedicated unit test suite inside
internal/models/resource_definitions_test.go to validate standalone dataset discovery.
Success Criteria
Description
Extend the
ResourceDefinitionModelstruct by implementing a new standalone method calledBadgerDBFindAll. To maintain strict backward compatibility across the rest of the engine, do not modify or deprecate the existing etcd-basedFindAllimplementation. This new method will introduce standalone support to iterate through and retrieve all resource definitions stored under the specified namespace prefix directly from BadgerDB.Requirements
internal/models/resource_definitions.goBadgerDBFindAll() ([]string, error)on theResourceDefinitionModelstruct.txn.NewIterator(badger.DefaultIteratorOptions)./resource_definitions/.item.ValueCopy()).fmt.Errorf("no resource definitions found")to guarantee parity with the etcd counterpart.internal/models/resource_definitions_test.goto validate standalone dataset discovery.Success Criteria
BadgerDBFindAllmethod is successfully added to the data layer model alongside legacy paths without modifying existing API signatures./resource_definitions/byte prefix.BadgerDBFindAlland verifies the array length matches the seeded database state perfectly.