Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions openapi/components/schemas/diff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ properties:
type: array
items:
type: object
systemFields:
type: array
items:
type: object
properties:
collection:
type: string
field:
type: string
diff:
type: array
items:
type: object
relations:
type: array
items:
Expand Down
19 changes: 19 additions & 0 deletions openapi/components/schemas/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ type: object
properties:
version:
type: integer
description: '`1` for a full snapshot, `2` for a partial snapshot.'
enum:
- 1
- 2
example: 1
directus:
type: string
Expand All @@ -15,6 +19,21 @@ properties:
type: array
items:
$ref: fields.yaml
systemFields:
type: array
description: Indexes defined on system fields.
items:
type: object
properties:
collection:
type: string
field:
type: string
schema:
type: object
properties:
is_indexed:
type: boolean
relations:
type: array
items:
Expand Down
7 changes: 4 additions & 3 deletions openapi/paths/schema/apply/schemaApply.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
summary: Apply Schema Difference
description: Update the instance's schema by passing the diff previously retrieved
via `/schema/diff` endpoint in the JSON request body or a JSON/YAML file. This endpoint
is only available to admin users.
description: |
Update the instance's schema by passing the diff previously retrieved via `/schema/diff` endpoint in the JSON request body or a JSON/YAML file. This endpoint is only available to admin users.

Only the operations in the diff are applied, so a diff from a partial snapshot leaves everything outside its scope untouched. The `hash` is always checked against the full schema.
operationId: schemaApply
parameters:
- name: force
Expand Down
15 changes: 15 additions & 0 deletions openapi/paths/schema/diff/schemaDiff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ description: |
Alternatively, upload a JSON or YAML schema file.

Does not allow different Directus versions and database vendors by default. You can opt in to bypass these checks by passing the `force` query parameter.

Accepts partial snapshots, in which case the diff is scoped to the collections the snapshot references.
operationId: schemaDiff
parameters:
- name: force
Expand All @@ -13,6 +15,17 @@ parameters:
required: false
schema:
type: boolean
- name: mode
description: |
`mirror` (default) returns all operations. `merge` returns an additive diff that excludes deletions.
in: query
required: false
schema:
type: string
enum:
- merge
- mirror
default: mirror
requestBody:
required: true
content:
Expand Down Expand Up @@ -104,6 +117,8 @@ x-codeSamples:
},
],
relations: [],
}, {
mode: 'merge',
})
);

Expand Down
38 changes: 36 additions & 2 deletions openapi/paths/schema/snapshot/schemaSnapshot.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
summary: Retrieve Schema Snapshot
description: Retrieve the current schema. This endpoint is only available to admin
users.
description: |
Retrieve the current schema. This endpoint is only available to admin users.

Returns a full snapshot (version `1`) by default. Pass `includeCollections` or `excludeCollections` to scope it to a subset of collections, which returns a partial snapshot (version `2`).
operationId: schemaSnapshot
parameters:
- $ref: ../../../components/parameters.yaml#/Export
- name: includeCollections
description: |
Restrict the snapshot to these collections. Unknown names are ignored. Mutually exclusive with `excludeCollections`.
in: query
required: false
explode: false
schema:
type: array
items:
type: string
example:
- articles
- authors
- name: excludeCollections
description: |
Snapshot every collection except these. Mutually exclusive with `includeCollections`.
in: query
required: false
explode: false
schema:
type: array
items:
type: string
example:
- articles
responses:
'200':
description: Successful request
Expand All @@ -16,6 +43,8 @@ responses:
schema:
type: string
format: binary
'400':
$ref: ../../../components/responses.yaml#/BadRequestError
'403':
$ref: ../../../components/responses.yaml#/UnauthorizedError
security: []
Expand All @@ -30,6 +59,11 @@ x-codeSamples:
const client = createDirectus('directus_project_url').with(rest());

const result = await client.request(schemaSnapshot());

// Partial snapshot
const partial = await client.request(
schemaSnapshot({ includeCollections: ['articles', 'authors'] })
);
- label: GraphQL
lang: GraphQL
source: |
Expand Down