(API)Route not found > schema/diff
-
Hi there,
I'm trying to connect to server.tld/schema/diff & ./schema/apply via method POST but my instance always replies with a 404 "route not found".
- Version is 11.12.0
- (API)User has Admin-Permissions
- for example ./schema/snapshot is just working fine
Could it be that these two endpoints are "blocked" in cloudron directus apps? Can we "activate" them? Or should they work and the problem sits in front of the screen
Kind regards
Mario -
Hello @Mario-0
Setting a user token to make the API calls less difficult but
auth/login
can also be used.
Create a collection and added atest_input
field.Getting the current schema and storing it into
schema.json
curl --request GET --header 'Authorization: Bearer 3F410Ia783fuxm3OanzRIVyMzXS3Y77f' https://io.directus9.cloudronapp.cloudron.dev/schema/snapshot > schema.json
Adding another test Input field and store it to
schema2.json
.
Getting a snapshot again:curl --request GET --header 'Authorization: Bearer 3F410Ia783fuxm3OanzRIVyMzXS3Y77f' https://io.directus9.cloudronapp.cloudron.dev/schema/snapshot > schema2.json
Getting the diff and storing it into
diff.json
:curl --request POST -H "Content-Type: application/json" --data "$(yq .data schema.json)" --header 'Authorization: Bearer 3F410Ia783fuxm3OanzRIVyMzXS3Y77f' https://io.directus9.cloudronapp.cloudron.dev/schema/diff > diff.json
Applying the
diff.json
.curl --request POST -H "Content-Type: application/json" --data "$(yq .data diff.json)" --header 'Authorization: Bearer 3F410Ia783fuxm3OanzRIVyMzXS3Y77f' https://io.directus9.cloudronapp.cloudron.dev/schema/apply
I can see in the WebUI that the Schema was reverted with the diff.
-
Thanks a lot for your support 🤩
The "problem" was that I tried to send "pure" JSON to the diff-endpoint and this ended up in route not found (IMO not the best hint).
With parsing json to yaml--data "$(yq .data schema.json)"
the endpoint worked like expected.But why ist JSON not working!?
[...]Compare the current instance's schema against the schema snapshot in JSON request body and retrieve the difference. [...] Alternatively, upload a JSON or YAML schema file. (ref: https://directus.io/docs/api/schema#retrieve-schema-snapshot)
Also I'm wondering if my approach is the "best" solution:
- schema/snapshot > prod.json
- work on the snapshot schema locally and track/commit changes to git-repo (prod.json > local.json)
- schema/diff (edited) local.json against server > diff.json
- schema/apply diff.json on server
Thanks for your support
Mario -
Hello @Mario-0
@Mario-0 said in (API)Route not found > schema/diff:
With parsing json to yaml
"$(yq .data schema.json)"
does not parse JSON to YAML.
The command above returns the value inside the"data":{}
object andyq
does garbage in garbage out JSON<=>JSON.
Usingyq
here might have been a little misleading.I use the tool yq because, in my opinion, it offers a better feature set then jq which is just for JSON.
The data you get from
/schema/snapshot
is nested inside the object"data":{}
so in order to use the data you have to "step into" the.data
object.
That is what I am doing with$(yq .data schema.json)
.
Same with the response from/schema/diff
.
To POST the JSON inside"data":{}
you have to "step into" the.data
object.Example:
curl --request GET --header 'Authorization: Bearer kJ7B6RXawG7C6Hc14AWpturoM3R_5t-r' https://directus.cloudron.dev/schema/snapshot {"data":{"version":1,"directus":"11.12.0","vendor":"postgres","collections":[{"collection":"Cloudron_Forum_Example","meta":{"accountability":"all","archive_app_filter":true,"archive_field":null,"archive_value":null,"collapse":"open","collection":"Cloudron_Forum_Example","color":null,"display_template":null,"group":null,"hidden":false,"icon":null,"item_duplication_fields":null,"note":null,"preview_url":null,"singleton":false,"sort":null,"sort_field":null,"translations":null,"unarchive_value":null,"versioning":false},"schema":{"name":"Cloudron_Forum_Example"}}],"fields":[{"collection":"Cloudron_Forum_Example","field":"id","type":"integer","meta":{"collection":"Cloudron_Forum_Example","conditions":null,"display":null,"display_options":null,"field":"id","group":null,"hidden":true,"interface":"input","note":null,"options":null,"readonly":true,"required":false,"sort":1,"special":null,"translations":null,"validation":null,"validation_message":null,"width":"full"},"schema":{"name":"id","table":"Cloudron_Forum_Example","data_type":"integer","default_value":"nextval('\"Cloudron_Forum_Example_id_seq\"'::regclass)","max_length":null,"numeric_precision":32,"numeric_scale":0,"is_nullable":false,"is_unique":true,"is_indexed":false,"is_primary_key":true,"is_generated":false,"generation_expression":null,"has_auto_increment":true,"foreign_key_table":null,"foreign_key_column":null}},{"collection":"Cloudron_Forum_Example","field":"Data_Input_Text","type":"string","meta":{"collection":"Cloudron_Forum_Example","conditions":null,"display":null,"display_options":null,"field":"Data_Input_Text","group":null,"hidden":false,"interface":"input","note":null,"options":null,"readonly":false,"required":false,"sort":2,"special":null,"translations":null,"validation":null,"validation_message":null,"width":"full"},"schema":{"name":"Data_Input_Text","table":"Cloudron_Forum_Example","data_type":"character varying","default_value":null,"max_length":255,"numeric_precision":null,"numeric_scale":null,"is_nullable":true,"is_unique":false,"is_indexed":false,"is_primary_key":false,"is_generated":false,"generation_expression":null,"has_auto_increment":false,"foreign_key_table":null,"foreign_key_column":null}}],"relations":[]}}
for better understanding:
{"data":{INSIDE_HERE_IS_THE_DATA_YOU_WANT}}
If you put the whole JSON Object inside a visualizer like e.g. https://jsoncrack.com/editor the visual might help.
You can also append
yq
to the CURL request so you get the data directly.
I also added--prettyPrint
and--output-format=json
for bedder readability here in the forum.
Note:yq
can work withyaml
andjson
and with certain parameters, like--prettyPrint
the default output isyaml
, so you need to define--output-format=json
.curl -s --request GET --header 'Authorization: Bearer kJ7B6RXawG7C6Hc14AWpturoM3R_5t-r' https://directus.cloudron.dev/schema/snapshot | yq .data --prettyPrint --output-format=json { "version": 1, "directus": "11.12.0", "vendor": "postgres", "collections": [ { "collection": "Cloudron_Forum_Example", "meta": { "accountability": "all", "archive_app_filter": true, "archive_field": null, "archive_value": null, "collapse": "open", "collection": "Cloudron_Forum_Example", "color": null, "display_template": null, "group": null, "hidden": false, "icon": null, "item_duplication_fields": null, "note": null, "preview_url": null, "singleton": false, "sort": null, "sort_field": null, "translations": null, "unarchive_value": null, "versioning": false }, "schema": { "name": "Cloudron_Forum_Example" } } ], "fields": [ { "collection": "Cloudron_Forum_Example", "field": "id", "type": "integer", "meta": { "collection": "Cloudron_Forum_Example", "conditions": null, "display": null, "display_options": null, "field": "id", "group": null, "hidden": true, "interface": "input", "note": null, "options": null, "readonly": true, "required": false, "sort": 1, "special": null, "translations": null, "validation": null, "validation_message": null, "width": "full" }, "schema": { "name": "id", "table": "Cloudron_Forum_Example", "data_type": "integer", "default_value": "nextval('\"Cloudron_Forum_Example_id_seq\"'::regclass)", "max_length": null, "numeric_precision": 32, "numeric_scale": 0, "is_nullable": false, "is_unique": true, "is_indexed": false, "is_primary_key": true, "is_generated": false, "generation_expression": null, "has_auto_increment": true, "foreign_key_table": null, "foreign_key_column": null } }, { "collection": "Cloudron_Forum_Example", "field": "Data_Input_Text", "type": "string", "meta": { "collection": "Cloudron_Forum_Example", "conditions": null, "display": null, "display_options": null, "field": "Data_Input_Text", "group": null, "hidden": false, "interface": "input", "note": null, "options": null, "readonly": false, "required": false, "sort": 2, "special": null, "translations": null, "validation": null, "validation_message": null, "width": "full" }, "schema": { "name": "Data_Input_Text", "table": "Cloudron_Forum_Example", "data_type": "character varying", "default_value": null, "max_length": 255, "numeric_precision": null, "numeric_scale": null, "is_nullable": true, "is_unique": false, "is_indexed": false, "is_primary_key": false, "is_generated": false, "generation_expression": null, "has_auto_increment": false, "foreign_key_table": null, "foreign_key_column": null } } ], "relations": [] }
I hope my explanation made it a little more understandable.