Collections API
Reference for the management API's endpoints that make a database's collections and push and activate their migrations.
These endpoints are a database's collection registry: its collections, their schema versions, and the migrations between them. They are the paths and the JSON of the engine's own registry, under /v1/databases/{databaseId} instead of the engine's /v1/admin/databases/{db}. A tool that manages a self-hosted database's collections, such as mimic-kit, manages one here by changing its base URL, the prefix and its credential. See the management API overview for authentication, and migrations for how a migration is pushed, watched and activated.
| Method | Path | Does |
|---|---|---|
GET | /v1/databases/{databaseId}/collections | Lists the database's collections |
GET | /v1/databases/{databaseId}/collections/{collectionId} | Reads a collection and its active schema |
PUT | /v1/databases/{databaseId}/collections/{collectionId} | Makes a collection with its first schema |
DELETE | /v1/databases/{databaseId}/collections/{collectionId} | Removes a collection |
GET | /v1/databases/{databaseId}/collections/{collectionId}/versions | Lists the collection's schema versions |
GET | /v1/databases/{databaseId}/collections/{collectionId}/migrations | Lists the collection's migrations |
POST | /v1/databases/{databaseId}/collections/{collectionId}/migrations | Pushes a migration |
GET | /v1/databases/{databaseId}/collections/{collectionId}/migrations/{migrationId} | Reads a migration and its progress |
POST | /v1/databases/{databaseId}/collections/{collectionId}/migrations/{migrationId}/activate | Activates a verified migration |
POST | /v1/databases/{databaseId}/collections/{collectionId}/migrations/{migrationId}/abort | Aborts a migration |
collectionId is an id you draw: 32 lowercase hexadecimal characters. migrationId is the database's, answered by the push. Making a collection again the same way is done (200); making it again another way is refused 409 already_exists. Pushing again the artifact of the migration being verified answers that migration, so a push whose answer was lost can be sent again; another push while one is unfinished is refused 422 migration_in_progress.
A push is { descriptor, payload } and carries no samples: they are documents, and the database checks a push on samples it makes from the schema. A push is answered once the database has checked the migration, for at most 80 seconds here (a database you run yourself waits up to ten minutes); send it with a timeout of at least two minutes. A check that takes longer is answered 503. An activation is answered at once, and the migration becomes active when the database is ready; read the migration to follow it. Bodies are bounded before they are read: a push to 32 MiB, a collection's body to about 6 MiB (a schema of 3 MiB, sent as escaped JSON text), anything else to 64 KiB (413).
Answers
Every answer is the database's own: its status, and its body as it gave it, its refusals included ({ "code", "message" }), such as 429 resource_exhausted while it checks another push. One answer is shortened: the list of a collection's versions gives each version's number, fingerprints and time without its schema, where a database you run yourself lists each with its schema. Read a collection to read its active schema. What our cloud refuses before the database is asked comes in the same form:
| Status | code | When |
|---|---|---|
401 | unauthenticated | No management key, or one that is revoked |
404 | not_found | No such database, or not one your key reaches |
422 | failed_precondition | The database does not serve (it is being made or deleted), or it is suspended and the request changes something |
400 | invalid_argument | An id or a body of the wrong form, or a push with samples |
503 | unavailable | The database's cluster did not answer; a change may have happened, so read it back (a push: list the collection's migrations) before sending it again |
413 | invalid_argument | A body larger than its kind's bound |
A management key of either role reads and changes them. A key scoped to one database reaches only that one. Each change is recorded in the audit log when it is sent and again with the database's answer, by its kind and its ids, never with its schema.