Skip to content

Commit

Permalink
GOCBC-1562: Support protostellar collection updating
Browse files Browse the repository at this point in the history
Motivation
----------
We are adding support for collection updating into Stellar
Gateway, so we also need to extend the support to the gosdk.

Changes
-------
Implement UpdateCollecton for protostellar.

Change-Id: I310980dda21873ec7f7556f18d5e6ba65837076b
Reviewed-on: https://review.couchbase.org/c/gocb/+/201865
Reviewed-by: Charles Dixon <chvckd@gmail.com>
Tested-by: Jack Westwood <jack.westwood@couchbase.com>
  • Loading branch information
Westwooo committed Dec 21, 2023
1 parent b4c4683 commit adc0193
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion collectionsmgmtprovider_ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,42 @@ func (cm *collectionsManagementProviderPs) CreateCollection(spec CollectionSpec,
}

func (cm *collectionsManagementProviderPs) UpdateCollection(spec CollectionSpec, opts *UpdateCollectionOptions) error {
return ErrFeatureNotAvailable
manager := cm.newOpManager(opts.ParentSpan, "manager_collections_update_collection", map[string]interface{}{
"db.name": cm.bucketName,
"db.couchbase.scope": spec.ScopeName,
"db.couchbase.collection": spec.Name,
"db.operation": "UpdateCollection",
})
defer manager.Finish(false)

manager.SetContext(opts.Context)
manager.SetIsIdempotent(false)
manager.SetRetryStrategy(opts.RetryStrategy)
manager.SetTimeout(opts.Timeout)

if err := manager.CheckReadyForOp(); err != nil {
return err
}

req := &admin_collection_v1.UpdateCollectionRequest{
BucketName: cm.bucketName,
ScopeName: spec.ScopeName,
CollectionName: spec.Name,
}
if spec.MaxExpiry > 0 {
expiry := uint32(spec.MaxExpiry.Seconds())
req.MaxExpirySecs = &expiry
}
if spec.History != nil {
req.HistoryRetentionEnabled = &spec.History.Enabled
}

_, err := wrapPSOp(manager, req, cm.provider.UpdateCollection)
if err != nil {
return err
}

return nil
}

// DropCollection removes a collection.
Expand Down

0 comments on commit adc0193

Please sign in to comment.