Description
Extend the PipelineModel struct by adding a new standalone query method called BadgerDBGetPipeline. To ensure backward compatibility across existing services and workers, do not refactor, rename, or drop the current etcd-based GetPipeline implementation. This method will introduce native support to fetch and unmarshal a specific pipeline configuration record directly from BadgerDB.
Requirements
- File Location:
internal/models/pipeline.go
- Method Signature Strategy: Introduce a new method named
BadgerDBGetPipeline(name string) (*types.Pipeline, error) on the PipelineModel struct.
- Transactionality: Execute the fetch operation inside a BadgerDB View (read-only) transaction.
- Key Generation: Calculate the target key using the established convention:
/pipelines/{name}.
- Data Retrieval & Deserialization:
- Query the item matching the formatted key inside the transaction boundary.
- Safely unpack or copy the raw byte payload from the database item context (e.g., using
item.ValueCopy()) to comply with BadgerDB's standard memory lifecycle constraints.
- Use the standard
json.Unmarshal package to deserialize the JSON bytes back into a native *types.Pipeline struct reference.
- Error Handling: If the target key does not exist inside BadgerDB (
errors.Is(err, badger.ErrKeyNotFound)), bubble up a descriptive custom error: fmt.Errorf("pipeline not found") to guarantee strict error parity with the historical etcd implementation.
- Testing: Create a dedicated unit test case inside
internal/models/pipeline_test.go to validate standalone dataset retrieval and missing key handling using an ephemeral, in-memory BadgerDB instance.
Success Criteria
Description
Extend the
PipelineModelstruct by adding a new standalone query method calledBadgerDBGetPipeline. To ensure backward compatibility across existing services and workers, do not refactor, rename, or drop the current etcd-basedGetPipelineimplementation. This method will introduce native support to fetch and unmarshal a specific pipeline configuration record directly from BadgerDB.Requirements
internal/models/pipeline.goBadgerDBGetPipeline(name string) (*types.Pipeline, error)on thePipelineModelstruct./pipelines/{name}.item.ValueCopy()) to comply with BadgerDB's standard memory lifecycle constraints.json.Unmarshalpackage to deserialize the JSON bytes back into a native*types.Pipelinestruct reference.errors.Is(err, badger.ErrKeyNotFound)), bubble up a descriptive custom error:fmt.Errorf("pipeline not found")to guarantee strict error parity with the historical etcd implementation.internal/models/pipeline_test.goto validate standalone dataset retrieval and missing key handling using an ephemeral, in-memory BadgerDB instance.Success Criteria
BadgerDBGetPipelinemethod is added cleanly alongside legacy methods without altering current external structural signatures.Viewtransaction.pipeline not found.BadgerDBGetPipelineusing the designated object name.