Description
Add the Delete method implementation for BadgerDB in
|
func (m *ResourceModel) Delete(name string, resourceType string) error { |
This method is responsible for removing a resource and its associated metadata from the local key-value store.
Requirements
- File Location:
internal/models/resource.go
- Transactionality: Use a BadgerDB Update transaction to perform the deletion.
- Key Generation: Utilize the existing
key(name, resourceType) helper to identify the target record.
- Deletion Scope: * Remove the primary resource key:
/resources/{resourceType}/{name}.
- Note: Ensure the implementation considers whether associated version keys (e.g.,
/resources/{resourceType}/{name}/1) should also be purged to prevent "orphan" data in the local KV store.
- Error Handling: Gracefully handle cases where the key does not exist. While etcd's delete is idempotent, BadgerDB's
txn.Delete returns an error if the key is not found; this should be handled to match current application expectations.
- 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
Deletemethod implementation forBadgerDBinconveyor/internal/models/resource.go
Line 82 in 2572f4c
This method is responsible for removing a resource and its associated metadata from the local key-value store.
Requirements
internal/models/resource.gokey(name, resourceType)helper to identify the target record./resources/{resourceType}/{name}./resources/{resourceType}/{name}/1) should also be purged to prevent "orphan" data in the local KV store.txn.Deletereturns an error if the key is not found; this should be handled to match current application expectations.*badger.DBinstance injected into theResourceModel.internal/models/resource_test.go.Success Criteria
Deletemethod successfully removes the specified resource from BadgerDB.Deletefor that specific resource.GetorFindOnecall for that key returns a "not found" error.