Skip to content

Commit 8cf6ccd

Browse files
authored
refactor: Rename 'Schema' to 'Collection' terminology (#4591)
## Relevant issue(s) Resolves ##3994 ## Description - Rename `schema add` to `collection add` - Rename Collection api - Rename old schema terminology to collection
1 parent d377c58 commit 8cf6ccd

File tree

730 files changed

+5820
-6090
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

730 files changed

+5820
-6090
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ start:
123123
client\:dump:
124124
./build/defradb client dump
125125

126-
.PHONY: client\:add-schema
127-
client\:add-schema:
128-
./build/defradb client schema add -f examples/schema/bookauthpub.graphql
126+
.PHONY: client\:collection-add
127+
client\:collection-add:
128+
./build/defradb client collection add -f examples/collection/bookauthpub.graphql
129129

130130
.PHONY: deps\:lint-go
131131
deps\:lint-go:

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Read the documentation on [docs.source.network](https://docs.source.network/).
2828
* [Start](#start)
2929
* [Configuration](#configuration)
3030
* [External port binding](#external-port-binding)
31-
* [Add a schema type](#add-a-schema-type)
31+
* [Add a collection](#add-a-collection)
3232
* [Add a document](#add-a-document)
3333
* [Query documents](#query-documents)
3434
* [Obtain document commits](#obtain-document-commits)
@@ -167,26 +167,26 @@ By default the HTTP API and P2P network will use localhost. If you want to expos
167167
defradb start --p2paddr /ip4/0.0.0.0/tcp/9171 --url 0.0.0.0:9181
168168
```
169169

170-
## Add a schema type
170+
## Add a collection
171171

172-
Schemas are used to structure documents using a type system.
172+
Collections are used to structure documents using a type system.
173173

174-
In the following examples, we'll be using a simple `User` schema type.
174+
In the following examples, we'll be using a simple `User` type.
175175

176176
Add it to the database with the following command. By doing so, DefraDB generates the typed GraphQL endpoints for querying, mutation, and introspection.
177177

178178
```shell
179-
defradb client schema add '
179+
defradb client collection add '
180180
type User {
181-
name: String
182-
age: Int
183-
verified: Boolean
181+
name: String
182+
age: Int
183+
verified: Boolean
184184
points: Float
185185
}
186186
'
187187
```
188188

189-
Find more examples of schema type definitions in the [examples/schema/](examples/schema/) folder.
189+
Find more examples of type definitions in the [examples/collection/](examples/collection/) folder.
190190

191191
## Add a document
192192

@@ -216,7 +216,7 @@ Expected response:
216216
}
217217
```
218218

219-
`_docID` is the document's unique identifier determined by its schema and initial data.
219+
`_docID` is the document's unique identifier determined by its collection and initial data.
220220

221221
## Query documents
222222

@@ -418,10 +418,10 @@ Start *nodeA*:
418418
defradb start
419419
```
420420

421-
In another terminal, add this example schema to it:
421+
In another terminal, add this example collection to it:
422422

423423
```shell
424-
defradb client schema add '
424+
defradb client collection add '
425425
type Article {
426426
content: String
427427
published: Boolean
@@ -437,10 +437,10 @@ defradb start --rootdir ~/.defradb-nodeB --url localhost:9182 --p2paddr /ip4/0.0
437437

438438
Here we *do not* specify `--peers` as we will manually define a replicator after startup via the `rpc` client command.
439439

440-
In another terminal, add the same schema to *nodeB*:
440+
In another terminal, add the same collection to *nodeB*:
441441

442442
```shell
443-
defradb client schema add --url localhost:9182 '
443+
defradb client collection add --url localhost:9182 '
444444
type Article {
445445
content: String
446446
published: Boolean

acp/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ All mandatory permissions are:
103103
- Specified in the `dpi.go` file within the variable `dpiRequiredPermissions`.
104104

105105
### DPI Resource Examples:
106-
- Check out tests here: [tests/integration/acp/schema/add_dpi](/tests/integration/acp/schema/add_dpi)
106+
- Check out tests here: [tests/integration/acp/dac/link_collection](/tests/integration/acp/dac/link_collection)
107107
- The tests linked are broken into `accept_*_test.go` and `reject_*_test.go` files.
108-
- Accepted tests document the valid DPIs (as the schema is accepted).
109-
- Rejected tests document invalid DPIs (as the schema is rejected).
108+
- Accepted tests document the valid DPIs (as the collection is accepted).
109+
- Rejected tests document invalid DPIs (as the collection is rejected).
110110
- There are also some Partially-DPI tests that are both accepted and rejected depending on the resource.
111111

112112
### Required Permission's Expression:
@@ -189,9 +189,9 @@ Result:
189189
}
190190
```
191191

192-
### Add schema, linking to a resource within the policy we added:
192+
### Add collection, linking to a resource within the policy we added:
193193

194-
We have in `examples/schema/permissioned/users.graphql`:
194+
We have in `examples/collection/permissioned/users.graphql`:
195195
```graphql
196196
type Users @policy(
197197
id: "50d354a91ab1b8fce8a0ae4693de7616fb1d82cfc540f25cfbe11eb0195a5765",
@@ -204,7 +204,7 @@ type Users @policy(
204204

205205
CLI Command:
206206
```sh
207-
defradb client schema add -f examples/schema/permissioned/users.graphql
207+
defradb client collection add -f examples/collection/permissioned/users.graphql
208208
```
209209

210210
Result:
@@ -492,9 +492,9 @@ Result:
492492
}
493493
```
494494

495-
Add schema, linking to the users resource and our policyID:
495+
Add collection, linking to the users resource and our policyID:
496496
```sh
497-
defradb client schema add '
497+
defradb client collection add '
498498
type Users @policy(
499499
id: "ec11b7e29a4e195f95787e2ec9b65af134718d16a2c9cd655b5e04562d1cabf9",
500500
resource: "users"
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323
iIdentity "github.com/sourcenetwork/defradb/internal/identity"
2424
)
2525

26-
//export AddSchema
27-
func AddSchema(nodePtr C.uintptr_t, schema *C.char, identityPtr C.uintptr_t) C.Result {
26+
//export AddCollection
27+
func AddCollection(nodePtr C.uintptr_t, sdl *C.char, identityPtr C.uintptr_t) C.Result {
2828
ctx := context.Background()
2929

3030
ctx, err := contextWithIdentity(ctx, identityPtr)
@@ -36,8 +36,8 @@ func AddSchema(nodePtr C.uintptr_t, schema *C.char, identityPtr C.uintptr_t) C.R
3636
if err != nil {
3737
return returnC(returnGoC(1, err.Error(), ""))
3838
}
39-
opt := options.WithIdentity(options.AddSchema(), iIdentity.FromContext(ctx))
40-
collectionVersions, err := store.AddSchema(ctx, C.GoString(schema), opt)
39+
opt := options.WithIdentity(options.AddCollection(), iIdentity.FromContext(ctx))
40+
collectionVersions, err := store.AddCollection(ctx, C.GoString(sdl), opt)
4141
if err != nil {
4242
return returnC(returnGoC(1, err.Error(), ""))
4343
}

cbindings/document.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func Add(
6969
}
7070
ctx = encryption.SetContextConfigFromParams(ctx, isEncrypted != 0, encryptFields)
7171

72-
addOpt := options.WithIdentity(options.CollectionAdd(), acpIdentity.FromContext(ctx))
72+
addOpt := options.WithIdentity(options.AddDocument(), acpIdentity.FromContext(ctx))
7373

7474
// Determine if JSON is array or object by looking for the first character being [
7575
jsonString := strings.TrimSpace(C.GoString(json))
@@ -79,7 +79,7 @@ func Add(
7979
if err != nil {
8080
return returnC(returnGoC(1, err.Error(), ""))
8181
}
82-
err = col.AddMany(ctx, docs, addOpt)
82+
err = col.AddManyDocuments(ctx, docs, addOpt)
8383
if err != nil {
8484
return returnC(returnGoC(1, err.Error(), ""))
8585
}
@@ -89,7 +89,7 @@ func Add(
8989
if err != nil {
9090
return returnC(returnGoC(1, err.Error(), ""))
9191
}
92-
err = col.Add(ctx, doc, addOpt)
92+
err = col.AddDocument(ctx, doc, addOpt)
9393
if err != nil {
9494
return returnC(returnGoC(1, err.Error(), ""))
9595
}
@@ -135,7 +135,7 @@ func Delete(nodePtr C.uintptr_t,
135135
if err != nil {
136136
return returnC(returnGoC(1, err.Error(), ""))
137137
}
138-
_, err = col.Delete(ctx, ID, options.WithIdentity(options.CollectionDelete(), ident))
138+
_, err = col.DeleteDocument(ctx, ID, options.WithIdentity(options.DeleteDocument(), ident))
139139
if err != nil {
140140
return returnC(returnGoC(1, err.Error(), ""))
141141
}
@@ -145,8 +145,8 @@ func Delete(nodePtr C.uintptr_t,
145145
if err := json.Unmarshal([]byte(filter), &filterValue); err != nil {
146146
return returnC(returnGoC(1, err.Error(), ""))
147147
}
148-
deleteOpt := options.WithIdentity(options.CollectionDeleteWithFilter(), ident)
149-
res, err := col.DeleteWithFilter(ctx, filterValue, deleteOpt)
148+
deleteOpt := options.WithIdentity(options.DeleteDocumentsWithFilter(), ident)
149+
res, err := col.DeleteDocumentsWithFilter(ctx, filterValue, deleteOpt)
150150
if err != nil {
151151
return returnC(returnGoC(1, err.Error(), ""))
152152
}
@@ -194,8 +194,8 @@ func Get(nodePtr C.uintptr_t,
194194
if err != nil {
195195
return returnC(returnGoC(1, err.Error(), ""))
196196
}
197-
getOpt := options.WithIdentity(options.CollectionGet().SetShowDeleted(showDeleted != 0), acpIdentity.FromContext(ctx))
198-
doc, err := col.Get(ctx, docID, getOpt)
197+
getOpt := options.WithIdentity(options.GetDocument().SetShowDeleted(showDeleted != 0), acpIdentity.FromContext(ctx))
198+
doc, err := col.GetDocument(ctx, docID, getOpt)
199199
if err != nil {
200200
return returnC(returnGoC(1, err.Error(), ""))
201201
}
@@ -249,8 +249,8 @@ func Update(
249249
if err := json.Unmarshal([]byte(filter), &filterValue); err != nil {
250250
return returnC(returnGoC(1, err.Error(), ""))
251251
}
252-
res, err := col.UpdateWithFilter(ctx, filterValue, updater,
253-
options.WithIdentity(options.CollectionUpdateWithFilter(), ident))
252+
res, err := col.UpdateDocumentsWithFilter(ctx, filterValue, updater,
253+
options.WithIdentity(options.UpdateDocumentsWithFilter(), ident))
254254
if err != nil {
255255
return returnC(returnGoC(1, err.Error(), ""))
256256
}
@@ -266,15 +266,15 @@ func Update(
266266
if err != nil {
267267
return returnC(returnGoC(1, err.Error(), ""))
268268
}
269-
doc, err := col.Get(ctx, newDocID,
270-
options.WithIdentity(options.CollectionGet().SetShowDeleted(true), ident))
269+
doc, err := col.GetDocument(ctx, newDocID,
270+
options.WithIdentity(options.GetDocument().SetShowDeleted(true), ident))
271271
if err != nil {
272272
return returnC(returnGoC(1, err.Error(), ""))
273273
}
274274
if err := doc.SetWithJSON(ctx, []byte(updater)); err != nil {
275275
return returnC(returnGoC(1, err.Error(), ""))
276276
}
277-
err = col.Update(ctx, doc, options.WithIdentity(options.CollectionUpdate(), ident))
277+
err = col.UpdateDocument(ctx, doc, options.WithIdentity(options.UpdateDocument(), ident))
278278
if err != nil {
279279
return returnC(returnGoC(1, err.Error(), ""))
280280
}

cbindings/wrapper.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ extern Result PollSubscription(char* id);
6161
extern Result CloseSubscription(char* id);
6262
extern Result ExecuteQuery(uintptr_t nodePtr, char* query, uintptr_t identity,
6363
char* operationName, char* variables);
64-
extern Result AddSchema(uintptr_t nodePtr, char* schema, uintptr_t identity);
64+
extern Result AddCollection(uintptr_t nodePtr, char* schema, uintptr_t identity);
6565
extern Result SetActiveCollection(uintptr_t nodePtr, CollectionOptions options, uintptr_t identityPtr);
6666
extern NewTxnResult TransactionCreate(uintptr_t nodePtr, int isConcurrent, int isReadOnly);
6767
extern Result VersionGet(int flagFull, int flagJSON);
@@ -424,18 +424,18 @@ func (w *CWrapper) BasicExport(
424424
panic("not implemented")
425425
}
426426

427-
func (w *CWrapper) AddSchema(
427+
func (w *CWrapper) AddCollection(
428428
ctx context.Context,
429-
schema string,
430-
opts ...options.Enumerable[options.AddSchemaOptions],
429+
sdl string,
430+
opts ...options.Enumerable[options.AddCollectionOptions],
431431
) ([]client.CollectionVersion, error) {
432432
cIdentity := optionToUintptr(utils.NewOptions(opts...).GetIdentity())
433433
defer C.IdentityFree(cIdentity)
434-
cSchema := C.CString(schema)
435-
defer C.free(unsafe.Pointer(cSchema))
434+
cSDL := C.CString(sdl)
435+
defer C.free(unsafe.Pointer(cSDL))
436436

437437
callHandle := getNodeOrTxnHandle(w.handle, ctx)
438-
res := ConvertAndFreeCResult(C.AddSchema(callHandle, cSchema, cIdentity))
438+
res := ConvertAndFreeCResult(C.AddCollection(callHandle, cSDL, cIdentity))
439439

440440
if res.Status != 0 {
441441
return nil, errors.New(res.Error)

0 commit comments

Comments
 (0)