Skip to content

Commit 62f7ea5

Browse files
committed
feat: Batch create collections
1 parent e73d3b3 commit 62f7ea5

File tree

4 files changed

+109
-3
lines changed

4 files changed

+109
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44

55
# Misc
66
.DS_Store
7+
*.yaml.bak

scripts/fix_openapi.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ main() {
6161
yq_fix_array_object SearchRequest sort
6262
yq_fix_object SearchHit data
6363
yq_fix_object CreateOrUpdateCollectionRequest schema
64+
yq_fix_object CreateOrUpdateCollectionsRequest schemas.items
6465
yq_fix_timestamp ResponseMetadata created_at
6566
yq_fix_timestamp ResponseMetadata updated_at
6667

@@ -90,7 +91,7 @@ main() {
9091
BeginTransactionRequest CommitTransactionRequest \
9192
RollbackTransactionRequest CreateAppKeyRequest \
9293
UpdateAppKeyRequest ListAppKeysRequest \
93-
DeleteAppKeyRequest; do
94+
DeleteAppKeyRequest CreateOrUpdateCollectionsRequest; do
9495
yq_del_project_coll $i
9596
done
9697

@@ -120,7 +121,7 @@ fix_bytes() {
120121
# According to the OpenAPI spec format should be "byte",
121122
# but protoc-gen-openapi generates it as "bytes".
122123
# We fix it here
123-
sed -i'' -e 's/format: bytes/format: byte/g' "$IN_FILE"
124+
sed -i'.bak' -e 's/format: bytes/format: byte/g' "$IN_FILE"
124125
}
125126

126127
yq_cmd() {

server/v1/api.proto

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package tigrisdata.v1;
1818

1919
import "google/api/annotations.proto";
2020
import "google/protobuf/timestamp.proto";
21+
import "server/v1/observability.proto";
2122
import "openapiv3/annotations.proto";
2223

2324
option go_package = "github.com/tigrisdata/tigris/api";
@@ -661,6 +662,31 @@ message CreateOrUpdateCollectionResponse {
661662
string status = 2;
662663
}
663664

665+
message CreateOrUpdateCollectionsRequest {
666+
// Project name whose db is under target to create or update collection.
667+
string project = 1;
668+
// Optionally specify a database branch name to perform operation on
669+
string branch = 2;
670+
// collections to create.
671+
repeated bytes schemas = 3;
672+
bool only_create = 4;
673+
CollectionOptions options = 5;
674+
}
675+
676+
message CreateCollectionStatus {
677+
// An enum with value set as "created" or "updated"
678+
string status = 1;
679+
}
680+
681+
message CreateOrUpdateCollectionsResponse {
682+
// A detailed response message.
683+
repeated CreateCollectionStatus resp = 1;
684+
// In the case, when API returns an error this is an index
685+
// in the "schemas" field which failed.
686+
int32 failedAtIndex = 2;
687+
tigrisdata.observability.v1.Error error = 3;
688+
}
689+
664690
message DropCollectionRequest {
665691
// Project name whose db is under target to delete collection.
666692
string project = 1;
@@ -1144,6 +1170,17 @@ service Tigris {
11441170
tags: "Collections"
11451171
};
11461172
}
1173+
1174+
rpc CreateOrUpdateCollections(CreateOrUpdateCollectionsRequest) returns (CreateOrUpdateCollectionsResponse) {
1175+
option (google.api.http) = {
1176+
post : "/v1/projects/{project}/database/collections/createOrUpdate"
1177+
body : "*"
1178+
};
1179+
option(openapi.v3.operation) = {
1180+
summary: "Create or update a batch of collections"
1181+
tags: "Collections"
1182+
};
1183+
}
11471184
// Drops the collection inside this project. This API deletes all of the
11481185
// documents inside this collection and any metadata associated with it.
11491186
rpc DropCollection(DropCollectionRequest) returns

server/v1/openapi.yaml

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,38 @@ paths:
12981298
application/json:
12991299
schema:
13001300
$ref: '#/components/schemas/Status'
1301+
/v1/projects/{project}/database/collections/createOrUpdate:
1302+
post:
1303+
tags:
1304+
- Collections
1305+
summary: Create or update a batch of collections
1306+
operationId: Tigris_CreateOrUpdateCollections
1307+
parameters:
1308+
- name: project
1309+
in: path
1310+
description: Project name whose db is under target to create or update collection.
1311+
required: true
1312+
schema:
1313+
type: string
1314+
requestBody:
1315+
content:
1316+
application/json:
1317+
schema:
1318+
$ref: '#/components/schemas/CreateOrUpdateCollectionsRequest'
1319+
required: true
1320+
responses:
1321+
"200":
1322+
description: OK
1323+
content:
1324+
application/json:
1325+
schema:
1326+
$ref: '#/components/schemas/CreateOrUpdateCollectionsResponse'
1327+
default:
1328+
description: Default error response
1329+
content:
1330+
application/json:
1331+
schema:
1332+
$ref: '#/components/schemas/Status'
13011333
/v1/projects/{project}/database/collections/{collection}/createOrUpdate:
13021334
post:
13031335
tags:
@@ -3063,6 +3095,12 @@ components:
30633095
status:
30643096
type: string
30653097
description: An enum with value set as "created"
3098+
CreateCollectionStatus:
3099+
type: object
3100+
properties:
3101+
status:
3102+
type: string
3103+
description: An enum with value set as "created" or "updated"
30663104
CreateDocumentRequest:
30673105
type: object
30683106
properties:
@@ -3164,6 +3202,35 @@ components:
31643202
status:
31653203
type: string
31663204
description: An enum with value set as "created" or "updated"
3205+
CreateOrUpdateCollectionsRequest:
3206+
type: object
3207+
properties:
3208+
branch:
3209+
type: string
3210+
description: Optionally specify a database branch name to perform operation on
3211+
schemas:
3212+
type: array
3213+
items:
3214+
type: object
3215+
description: collections to create.
3216+
only_create:
3217+
type: boolean
3218+
options:
3219+
$ref: '#/components/schemas/CollectionOptions'
3220+
CreateOrUpdateCollectionsResponse:
3221+
type: object
3222+
properties:
3223+
resp:
3224+
type: array
3225+
items:
3226+
$ref: '#/components/schemas/CreateCollectionStatus'
3227+
description: A detailed response message.
3228+
failedAtIndex:
3229+
type: integer
3230+
description: In the case, when API returns an error this is an index in the "schemas" field which failed.
3231+
format: int32
3232+
error:
3233+
$ref: '#/components/schemas/Error'
31673234
CreateOrUpdateIndexRequest:
31683235
type: object
31693236
properties:
@@ -4856,8 +4923,8 @@ tags:
48564923
- name: Authentication
48574924
description: 'The auth section of API provides OAuth 2.0 APIs. Tigris supports pluggable OAuth provider. Pass the token in the headers for authentication, as an example `-H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6I"`(replace it with your token). All API requests must be made over HTTPS. Calls made over plain HTTP will fail. API requests without authentication will also fail.'
48584925
- name: Billing
4859-
description: The billing section provides APIs for managing invoices and payments infrastructure.
48604926
- name: Billing
4927+
description: The billing section provides APIs for managing invoices and payments infrastructure.
48614928
- name: Cache
48624929
description: The cache section provide APIs that can be used to perform cache operations.
48634930
- name: Collections

0 commit comments

Comments
 (0)