Description
Add the Update method implementation for BadgerDB. This method is responsible for updating an existing resource, incrementing its metadata version, and persisting both the current state and a new versioned entry in the local key-value store.
|
func (m *ResourceModel) Update(name string, resourceType string, resource types.Resource) (types.Resource, error) { |
Requirements
- File Location:
internal/models/resource.go
- Transactionality: The entire operation must be wrapped in a BadgerDB Update transaction to ensure the version increment and dual-key writes (primary and versioned) are atomic.
- Existence Check: The method must first verify that the resource exists. If not found, it should return a "not found" error.
- Versioning Logic:
- Retrieve the current version from the existing resource's metadata.
- Increment the version number.
- Update the
Metadata["version"] field in the resource object.
- Dual-Key Write: The method must update two entries:
- The primary resource key:
/resources/{resourceType}/{name}.
- A new versioned key:
/resources/{resourceType}/{name}/{newVersionNumber}.
- Dependency Injection: The method must use the
*badger.DB instance injected into the ResourceModel.
- Testing: A corresponding test case must be created in
internal/models/resource_test.go.
Success Criteria
Description
Add the
Updatemethod implementation forBadgerDB. This method is responsible for updating an existing resource, incrementing its metadata version, and persisting both the current state and a new versioned entry in the local key-value store.conveyor/internal/models/resource.go
Line 114 in 2572f4c
Requirements
internal/models/resource.goMetadata["version"]field in the resource object./resources/{resourceType}/{name}./resources/{resourceType}/{name}/{newVersionNumber}.*badger.DBinstance injected into theResourceModel.internal/models/resource_test.go.Success Criteria
Updatemethod successfully modifies records in BadgerDB within an atomic transaction./2) exist in the database after the update.Updatewith modified data./2has been created.