Description
Extend the PipelineModel struct by implementing a new standalone query method called BadgerDBListPipelines. To ensure backwards compatibility across current services and APIs, do not refactor, rename, or delete the legacy etcd-based ListPipelines implementation. This new addition introduces native support to perform a prefix scan and return a deserialized slice of all stored pipelines inside BadgerDB.
Requirements
- File Location:
internal/models/pipeline.go
- Method Signature Strategy: Introduce a new method named
BadgerDBListPipelines() ([]*types.Pipeline, error) on the PipelineModel struct.
- Transactionality: Perform the scan operation entirely inside a BadgerDB View (read-only) transaction boundary.
- Prefix Scanning Mechanics:
- Create a database iterator using
txn.NewIterator(badger.DefaultIteratorOptions).
- Target keys matching the structural prefix:
/pipelines/.
- Data Processing & Lifecycle Rules:
- Iterate through matched items and extract the configuration payload using BadgerDB item lifecycle best practices (e.g., calling
item.ValueCopy()).
- Unmarshal each retrieved JSON payload back into a separate instance of
types.Pipeline using the standard json.Unmarshal package.
- Append pointers of these populated structures to a result slice.
- Error Handling: If no pipelines exist under the targeted namespace prefix, return an empty slice and a
nil error to achieve functional consistency with how list variants typically drop out when no data is found.
- Testing: Author a dedicated unit test suite inside
internal/models/pipeline_test.go to validate prefix parsing, payload unmarshaling, and array aggregation using an in-memory BadgerDB instance.
Success Criteria
Description
Extend the
PipelineModelstruct by implementing a new standalone query method calledBadgerDBListPipelines. To ensure backwards compatibility across current services and APIs, do not refactor, rename, or delete the legacy etcd-basedListPipelinesimplementation. This new addition introduces native support to perform a prefix scan and return a deserialized slice of all stored pipelines inside BadgerDB.Requirements
internal/models/pipeline.goBadgerDBListPipelines() ([]*types.Pipeline, error)on thePipelineModelstruct.txn.NewIterator(badger.DefaultIteratorOptions)./pipelines/.item.ValueCopy()).types.Pipelineusing the standardjson.Unmarshalpackage.nilerror to achieve functional consistency with how list variants typically drop out when no data is found.internal/models/pipeline_test.goto validate prefix parsing, payload unmarshaling, and array aggregation using an in-memory BadgerDB instance.Success Criteria
BadgerDBListPipelinesmethod is added cleanly to the model file without breaking the legacy codebase./pipelines/byte boundary.BadgerDBListPipelinesand verifies that the output matches the expected length of seeded items.