Skip to content

Add BadgerDBCreatePipeline method for PipelineModel #255

Description

@jim-junior

Description

Extend the PipelineModel struct by implementing a new standalone method called BadgerDBCreatePipeline. To prevent breaking changes across the codebase, do not refactor or replace the existing etcd-based CreatePipeline implementation. This method introduces native support for serializing and persisting a new pipeline payload directly inside BadgerDB.

Requirements

  • File Location: internal/models/pipeline.go
  • Method Signature Strategy: Introduce a new method named BadgerDBCreatePipeline(pipeline *types.Pipeline) error on the PipelineModel struct.
  • Transactionality: Execute both the duplication check and the write sequence within a single BadgerDB Update (write) transaction to guarantee execution safety.
  • Uniqueness Constraint: * Before saving the bytes, inspect the database to check if the calculated lookup key already exists.
    • If the key exists, return a descriptive custom error indicating that a pipeline with that name is already defined, preventing accidental overwrites.
  • Serialization & Key Generation: * Generate the targeted storage key using the format: /pipelines/{pipeline.Name}.
    • Marshal the incoming *types.Pipeline struct into JSON bytes using the standard json.Marshal library.
  • Testing: Add a dedicated unit test suite inside internal/models/pipeline_test.go to validate successful creation workflows, persistence checks, and key-conflict validation pathways using an in-memory database instance.

Success Criteria

  • The BadgerDBCreatePipeline method is added cleanly alongside legacy methods without breaking public structure boundaries.
  • The existence lookups and persistence writes occur atomically within an exclusive write transaction block.
  • Attempting to write a pipeline name that is already allocated correctly triggers a duplicate error barrier.
  • Test Case implementation: A comprehensive unit test is provided that:
    • Sets up an isolated, in-memory BadgerDB instance.
    • Successfully calls BadgerDBCreatePipeline with a valid mock pipeline object.
    • Confirms that the output is accurately stored as unmarshaled JSON data matching the input properties.
    • Asserts that submitting an identical pipeline struct second-in-line accurately rejects the write with a key collision error response.

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