Description
Add the Insert method implementation for BadgerDB at
|
func (m *ResourceModel) Insert(name string, resourceType string, resource []byte) error { |
This method is responsible for persisting a new resource and initializing its versioning history within the local key-value store.
Requirements
- File Location:
internal/models/resource.go
- Transactionality: The operation must be wrapped in a BadgerDB Update transaction to ensure atomicity between saving the primary record and the initial version record.
- Uniqueness Constraint: The method must verify if a resource with the same name and type already exists. If the key is present, it must return a clear "already exists" error to prevent accidental overwrites.
- Versioning Initialization: Upon a successful insert, the method must create two distinct entries:
- The primary resource entry at the path:
/resources/{resourceType}/{name}.
- The initial version entry at the path:
/resources/{resourceType}/{name}/1.
- Dependency Injection: The
ResourceModel struct must be updated to use the *badger.DB instance instead of the etcd client.
- Testing: A corresponding test case must be created in
internal/models/resource_test.go (or a similar test file) to verify the migration.
Success Criteria
Description
Add the
Insertmethod implementation for BadgerDB atconveyor/internal/models/resource.go
Line 31 in 2572f4c
This method is responsible for persisting a new resource and initializing its versioning history within the local key-value store.
Requirements
internal/models/resource.go/resources/{resourceType}/{name}./resources/{resourceType}/{name}/1.ResourceModelstruct must be updated to use the*badger.DBinstance instead of the etcd client.internal/models/resource_test.go(or a similar test file) to verify the migration.Success Criteria
Insertmethod successfully writes to BadgerDB using a write transaction./1version key are verifiable in the database after execution.