程序如下:
/schema/snapshot
: 接收实例模式的当前快照/schema/diff
:将快照与另一个实例的模式(例如,新实例或不同环境中的实例)进行比较,并检索包含所有差异的“diff”/schema/apply
: 根据之前获取的diff更新另一个实例的schema
Retrieve Schema Snapshot
检索当前架构。 此端点仅供管理员用户使用。
Query Parameters
支持 export 查询参数。
Returns
默认返回包含模式详细信息的 JSON 对象,或者在使用 export 查询参数时以替代格式下载它。
REST API
GET /schema/snapshot
Example
// returns JSON object
GET /schema/snapshot
// download as YAML file
GET /schema/snapshot?export=yaml
GraphQL
n/a
Retrieve Schema Difference
Compare the current instance's schema against the schema snapshot in JSON request body and retrieve the difference. This endpoint is only available to admin users.
Alternatively, upload a JSON or YAML schema file. Relies on a multipart/form-data
encoded request like regular file uploads. Check Upload a File for more information.
不同版本和供应商
默认情况下,此端点不允许使用不同的 Directus 版本和数据库供应商。 这是为了避免产生任何无意的差异。 您可以通过传递force
查询参数来选择绕过这些检查。
Query Parameters
force
boolean
绕过版本和数据库供应商限制。
请求体
包含 collections、fields 和 relations 应用。
或者,在multipart/form-data
请求中发送 JSON 或 YAML 架构文件。 有关详细信息,请参阅上传文件。
Returns
返回当前实例的架构与请求正文中传递的架构之间的差异。
Example
{
"hash": "2b3c71570228b864e16098147e5497f61b245a42",
"diff": {
"collections": [
{
"collection": "articles",
"diff": [
{
"kind": "N",
"rhs": {
"collection": "articles",
"meta": {
"accountability": "all",
"archive_app_filter": true,
"archive_field": null,
"archive_value": null,
"collapse": "open",
"collection": "articles",
"color": null,
"display_template": null,
"group": null,
"hidden": false,
"icon": null,
"item_duplication_fields": null,
"note": null,
"singleton": false,
"sort": null,
"sort_field": null,
"translations": null,
"unarchive_value": null
},
"schema": {
"name": "articles"
}
}
}
]
}
],
"fields": [
{
"collection": "articles",
"field": "id",
"diff": [
{
"kind": "N",
"rhs": {
"collection": "articles",
"field": "id",
"type": "integer",
"meta": {
"collection": "articles",
"conditions": null,
"display": null,
"display_options": null,
"field": "id",
"group": null,
"hidden": true,
"interface": "input",
"note": null,
"options": null,
"readonly": true,
"required": false,
"sort": null,
"special": null,
"translations": null,
"validation": null,
"validation_message": null,
"width": "full"
},
"schema": {
"name": "id",
"table": "articles",
"data_type": "integer",
"default_value": null,
"max_length": null,
"numeric_precision": null,
"numeric_scale": null,
"is_nullable": false,
"is_unique": false,
"is_primary_key": true,
"is_generated": false,
"generation_expression": null,
"has_auto_increment": true,
"foreign_key_table": null,
"foreign_key_column": null
}
}
}
]
},
{
"collection": "articles",
"field": "title",
"diff": [
{
"kind": "N",
"rhs": {
"collection": "articles",
"field": "title",
"type": "string",
"meta": {
"collection": "articles",
"conditions": null,
"display": null,
"display_options": null,
"field": "title",
"group": null,
"hidden": false,
"interface": "input",
"note": null,
"options": null,
"readonly": false,
"required": false,
"sort": null,
"special": null,
"translations": null,
"validation": null,
"validation_message": null,
"width": "full"
},
"schema": {
"name": "title",
"table": "articles",
"data_type": "varchar",
"default_value": null,
"max_length": 255,
"numeric_precision": null,
"numeric_scale": null,
"is_nullable": true,
"is_unique": false,
"is_primary_key": false,
"is_generated": false,
"generation_expression": null,
"has_auto_increment": false,
"foreign_key_table": null,
"foreign_key_column": null
}
}
}
]
}
],
"relations": []
}
}
REST API
POST /schema/diff
Example
POST /schema/diff
Content-Type: multipart/form-data; charset=utf-8; boundary=__X_BOUNDARY__
Content-Length: 3442422
--__X_BOUNDARY__
Content-Disposition: form-data; name="file"; filename="schema.yaml"
Content-Type: text/yaml
version: 1
directus: 9.22.4
vendor: sqlite
collections:
- collection: articles
meta:
accountability: all
archive_app_filter: true
archive_field: null
archive_value: null
collapse: open
collection: articles
color: null
display_template: null
group: null
hidden: false
icon: null
item_duplication_fields: null
note: null
singleton: false
sort: null
sort_field: null
translations: null
unarchive_value: null
schema:
name: articles
fields:
- collection: articles
field: id
type: integer
meta:
collection: articles
conditions: null
display: null
display_options: null
field: id
group: null
hidden: true
interface: input
note: null
options: null
readonly: true
required: false
sort: null
special: null
translations: null
validation: null
validation_message: null
width: full
schema:
name: id
table: articles
data_type: integer
default_value: null
max_length: null
numeric_precision: null
numeric_scale: null
is_nullable: false
is_unique: false
is_primary_key: true
is_generated: false
generation_expression: null
has_auto_increment: true
foreign_key_table: null
foreign_key_column: null
- collection: articles
field: title
type: string
meta:
collection: articles
conditions: null
display: null
display_options: null
field: title
group: null
hidden: false
interface: input
note: null
options: null
readonly: false
required: false
sort: null
special: null
translations: null
validation: null
validation_message: null
width: full
schema:
name: title
table: articles
data_type: varchar
default_value: null
max_length: 255
numeric_precision: null
numeric_scale: null
is_nullable: true
is_unique: false
is_primary_key: false
is_generated: false
generation_expression: null
has_auto_increment: false
foreign_key_table: null
foreign_key_column: null
relations: []
GraphQL
n/a
Apply Schema Difference
通过在请求正文中传递先前通过/schema/diff
端点检索到的差异来更新实例的架构。 此端点仅供管理员用户使用。
Query Parameters
此端点当前不支持任何查询参数。
请求体
包含 collections、fields 和 relations 应用。
哈希
哈希基于目标实例的架构和版本。 它用于防止在生成当前差异后可能发生的更改,在没有此保护的情况下应用差异时可能会产生意想不到的副作用。 如果架构在此期间发生更改,则必须重新生成差异。
Returns
Empty body.
REST API
POST /schema/apply
Example
POST /schema/apply
{
"hash": "2b3c71570228b864e16098147e5497f61b245a42",
"diff": {
"collections": [
{
"collection": "articles",
"diff": [
{
"kind": "N",
"rhs": {
"collection": "articles",
"meta": {
"accountability": "all",
"archive_app_filter": true,
"archive_field": null,
"archive_value": null,
"collapse": "open",
"collection": "articles",
"color": null,
"display_template": null,
"group": null,
"hidden": false,
"icon": null,
"item_duplication_fields": null,
"note": null,
"singleton": false,
"sort": null,
"sort_field": null,
"translations": null,
"unarchive_value": null
},
"schema": {
"name": "articles"
}
}
}
]
}
],
"fields": [
{
"collection": "articles",
"field": "id",
"diff": [
{
"kind": "N",
"rhs": {
"collection": "articles",
"field": "id",
"type": "integer",
"meta": {
"collection": "articles",
"conditions": null,
"display": null,
"display_options": null,
"field": "id",
"group": null,
"hidden": true,
"interface": "input",
"note": null,
"options": null,
"readonly": true,
"required": false,
"sort": null,
"special": null,
"translations": null,
"validation": null,
"validation_message": null,
"width": "full"
},
"schema": {
"name": "id",
"table": "articles",
"data_type": "integer",
"default_value": null,
"max_length": null,
"numeric_precision": null,
"numeric_scale": null,
"is_nullable": false,
"is_unique": false,
"is_primary_key": true,
"is_generated": false,
"generation_expression": null,
"has_auto_increment": true,
"foreign_key_table": null,
"foreign_key_column": null
}
}
}
]
},
{
"collection": "articles",
"field": "title",
"diff": [
{
"kind": "N",
"rhs": {
"collection": "articles",
"field": "title",
"type": "string",
"meta": {
"collection": "articles",
"conditions": null,
"display": null,
"display_options": null,
"field": "title",
"group": null,
"hidden": false,
"interface": "input",
"note": null,
"options": null,
"readonly": false,
"required": false,
"sort": null,
"special": null,
"translations": null,
"validation": null,
"validation_message": null,
"width": "full"
},
"schema": {
"name": "title",
"table": "articles",
"data_type": "varchar",
"default_value": null,
"max_length": 255,
"numeric_precision": null,
"numeric_scale": null,
"is_nullable": true,
"is_unique": false,
"is_primary_key": false,
"is_generated": false,
"generation_expression": null,
"has_auto_increment": false,
"foreign_key_table": null,
"foreign_key_column": null
}
}
}
]
}
],
"relations": []
}
}
GraphQL
n/a