Skip to content

Add BadgerDBListPipelines method for PipelineModel #259

Description

@jim-junior

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

  • The BadgerDBListPipelines method is added cleanly to the model file without breaking the legacy codebase.
  • Stored item iterations correctly utilize a read-only transaction iterator scoped precisely to the /pipelines/ byte boundary.
  • Calling the listing method on an empty database successfully handles the fallback without dropping execution panics or unhandled errors.
  • Test Case implementation: A comprehensive unit test is provided that:
    • Seeds an isolated, in-memory BadgerDB database with multiple disparate marshaled JSON pipeline mock structs.
    • Executes BadgerDBListPipelines and verifies that the output matches the expected length of seeded items.
    • Evaluates fields within the returned slice to guarantee that property fields match the source configurations exactly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    goPull requests that update go code

    Type

    Fields

    No fields configured for Task.

    Projects

    Status
    No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions