Skip to content

Commit 29cc9ea

Browse files
authored
OAS-10519 Expose OldRev Document Metadata (#659)
1 parent 747def4 commit 29cc9ea

7 files changed

+82
-23
lines changed

v2/arangodb/collection_documents_replace.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type CollectionDocumentReplaceResponseReader interface {
6565
}
6666

6767
type CollectionDocumentReplaceResponse struct {
68-
DocumentMeta
68+
DocumentMetaWithOldRev
6969
shared.ResponseStruct `json:",inline"`
7070
Old, New interface{}
7171
}

v2/arangodb/collection_documents_replace_impl.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023-2025 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -59,13 +59,13 @@ func (c collectionDocumentReplace) ReplaceDocumentWithOptions(ctx context.Contex
5959
}
6060

6161
response := struct {
62-
*DocumentMeta `json:",inline"`
63-
*shared.ResponseStruct `json:",inline"`
64-
Old *UnmarshalInto `json:"old,omitempty"`
65-
New *UnmarshalInto `json:"new,omitempty"`
62+
*DocumentMetaWithOldRev `json:",inline"`
63+
*shared.ResponseStruct `json:",inline"`
64+
Old *UnmarshalInto `json:"old,omitempty"`
65+
New *UnmarshalInto `json:"new,omitempty"`
6666
}{
67-
DocumentMeta: &meta.DocumentMeta,
68-
ResponseStruct: &meta.ResponseStruct,
67+
DocumentMetaWithOldRev: &meta.DocumentMetaWithOldRev,
68+
ResponseStruct: &meta.ResponseStruct,
6969

7070
Old: newUnmarshalInto(meta.Old),
7171
New: newUnmarshalInto(meta.New),
@@ -142,7 +142,7 @@ type collectionDocumentReplaceResponseReader struct {
142142
array *connection.Array
143143
options *CollectionDocumentReplaceOptions
144144
response struct {
145-
*DocumentMeta
145+
*DocumentMetaWithOldRev
146146
*shared.ResponseStruct `json:",inline"`
147147
Old *UnmarshalInto `json:"old,omitempty"`
148148
New *UnmarshalInto `json:"new,omitempty"`
@@ -161,7 +161,7 @@ func (c *collectionDocumentReplaceResponseReader) Read() (CollectionDocumentRepl
161161
meta.New = c.options.NewObject
162162
}
163163

164-
c.response.DocumentMeta = &meta.DocumentMeta
164+
c.response.DocumentMetaWithOldRev = &meta.DocumentMetaWithOldRev
165165
c.response.ResponseStruct = &meta.ResponseStruct
166166

167167
if err := c.array.Unmarshal(&c.response); err != nil {

v2/arangodb/collection_documents_update.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type CollectionDocumentUpdateResponseReader interface {
6666
}
6767

6868
type CollectionDocumentUpdateResponse struct {
69-
DocumentMeta
69+
DocumentMetaWithOldRev
7070
shared.ResponseStruct `json:",inline"`
7171
Old, New interface{}
7272
}

v2/arangodb/collection_documents_update_impl.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2020-2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2020-2025 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -59,13 +59,13 @@ func (c collectionDocumentUpdate) UpdateDocumentWithOptions(ctx context.Context,
5959
}
6060

6161
response := struct {
62-
*DocumentMeta `json:",inline"`
63-
*shared.ResponseStruct `json:",inline"`
64-
Old *UnmarshalInto `json:"old,omitempty"`
65-
New *UnmarshalInto `json:"new,omitempty"`
62+
*DocumentMetaWithOldRev `json:",inline"`
63+
*shared.ResponseStruct `json:",inline"`
64+
Old *UnmarshalInto `json:"old,omitempty"`
65+
New *UnmarshalInto `json:"new,omitempty"`
6666
}{
67-
DocumentMeta: &meta.DocumentMeta,
68-
ResponseStruct: &meta.ResponseStruct,
67+
DocumentMetaWithOldRev: &meta.DocumentMetaWithOldRev,
68+
ResponseStruct: &meta.ResponseStruct,
6969

7070
Old: newUnmarshalInto(meta.Old),
7171
New: newUnmarshalInto(meta.New),
@@ -142,7 +142,7 @@ type collectionDocumentUpdateResponseReader struct {
142142
array *connection.Array
143143
options *CollectionDocumentUpdateOptions
144144
response struct {
145-
*DocumentMeta
145+
*DocumentMetaWithOldRev
146146
*shared.ResponseStruct `json:",inline"`
147147
Old *UnmarshalInto `json:"old,omitempty"`
148148
New *UnmarshalInto `json:"new,omitempty"`
@@ -161,7 +161,7 @@ func (c *collectionDocumentUpdateResponseReader) Read() (CollectionDocumentUpdat
161161
meta.New = c.options.NewObject
162162
}
163163

164-
c.response.DocumentMeta = &meta.DocumentMeta
164+
c.response.DocumentMetaWithOldRev = &meta.DocumentMetaWithOldRev
165165
c.response.ResponseStruct = &meta.ResponseStruct
166166

167167
if err := c.array.Unmarshal(&c.response); err != nil {

v2/arangodb/meta.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2020-2021 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2020-2025 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -44,6 +44,11 @@ type DocumentMeta struct {
4444
Rev string `json:"_rev,omitempty"`
4545
}
4646

47+
type DocumentMetaWithOldRev struct {
48+
DocumentMeta
49+
OldRev string `json:"_oldRev,omitempty"`
50+
}
51+
4752
// validateKey returns an error if the given key is empty otherwise invalid.
4853
func validateKey(key string) error {
4954
if key == "" {

v2/tests/database_collection_doc_replace_test.go

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023-2025 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -126,6 +126,33 @@ func Test_DatabaseCollectionDocReplaceIgnoreRevs(t *testing.T) {
126126
})
127127
}
128128

129+
func Test_DatabaseCollectionDocReplaceReturnOldRev(t *testing.T) {
130+
Wrap(t, func(t *testing.T, client arangodb.Client) {
131+
WithDatabase(t, client, nil, func(db arangodb.Database) {
132+
WithCollection(t, db, nil, func(col arangodb.Collection) {
133+
withContextT(t, defaultTestTimeout, func(ctx context.Context, tb testing.TB) {
134+
doc := DocWithRev{
135+
Name: "test-ORG",
136+
}
137+
138+
metaOrg, err := col.CreateDocument(ctx, doc)
139+
require.NoError(t, err)
140+
141+
docReplace := DocWithRev{
142+
Name: "test-REPLACED",
143+
}
144+
145+
t.Run("OldRev should match", func(t *testing.T) {
146+
metaRep, err := col.ReplaceDocumentWithOptions(ctx, metaOrg.Key, docReplace, nil)
147+
require.NoError(t, err)
148+
require.Equal(t, metaOrg.Rev, metaRep.OldRev)
149+
})
150+
})
151+
})
152+
})
153+
})
154+
}
155+
129156
func Test_DatabaseCollectionDocReplaceSilent(t *testing.T) {
130157
Wrap(t, func(t *testing.T, client arangodb.Client) {
131158
WithDatabase(t, client, nil, func(db arangodb.Database) {

v2/tests/database_collection_doc_update_test.go

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023-2025 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -126,6 +126,33 @@ func Test_DatabaseCollectionDocUpdateIgnoreRevs(t *testing.T) {
126126
})
127127
}
128128

129+
func Test_DatabaseCollectionDocUpdateReturnOldRev(t *testing.T) {
130+
Wrap(t, func(t *testing.T, client arangodb.Client) {
131+
WithDatabase(t, client, nil, func(db arangodb.Database) {
132+
WithCollection(t, db, nil, func(col arangodb.Collection) {
133+
withContextT(t, defaultTestTimeout, func(ctx context.Context, tb testing.TB) {
134+
doc := DocWithRev{
135+
Name: "test-ORG",
136+
}
137+
138+
metaOrg, err := col.CreateDocument(ctx, doc)
139+
require.NoError(t, err)
140+
141+
docUpdate := DocWithRev{
142+
Name: "test-UPDATED",
143+
}
144+
145+
t.Run("OldRev should match", func(t *testing.T) {
146+
metaRep, err := col.UpdateDocumentWithOptions(ctx, metaOrg.Key, docUpdate, nil)
147+
require.NoError(t, err)
148+
require.Equal(t, metaOrg.Rev, metaRep.OldRev)
149+
})
150+
})
151+
})
152+
})
153+
})
154+
}
155+
129156
func Test_DatabaseCollectionDocUpdateKeepNull(t *testing.T) {
130157
Wrap(t, func(t *testing.T, client arangodb.Client) {
131158
WithDatabase(t, client, nil, func(db arangodb.Database) {

0 commit comments

Comments
 (0)