We have had a problem with using the CLI for transferring schema, and for upgrading Squidex, because we have managed to get our content in to an invalid state. This invalid state is easy to reproduce and is likely to happen to multiple people. It could be resolved by applying defaults to mandatory fields when they are undefined. The steps to reproduce the issue:
Create a schema
Create content based on that schema
Update the schema to have a new field that is both mandatory and has a default value.
Note all existing content is now invalid as far as they system is concerned as the defaults are not applied and it is mandatory. So, now you move the site content via CLI, you cannot upgrade Squidex, etc. until it is resolved.
You can resolve this manually but when there is a large amount of historical content this can be difficult to find elements that contain the now broken schema, and then change all of them.
I know the idea of applying defaults to old content was rejected ( Fields Default Values do not work - #6 by Vitali_Nikolenko) and I understand that but I think in the case of mandatory fields it would make sense to change this as there is no reason a mandatory field with a default value should ever legitimately have a value of undefined. Also, it is only in the mandatory case that Squidex features like the upgrade migration break.
I don’t know. I see this in documentation for scripting:
You can create scripts that run whenever a content item is created, updated, deleted, queried or when the status changes (e.g. from Draft to Published).
In the case we are discussing we have only changed the schema. We haven’t necessarily queried for the content item at all. The operations that are breaking for us are sq sync and the rebuilding of content and schemas during upgrade. Would those actions trigger a content query that would trigger the script?
With the migration script is that something built into Squidex that I haven’t seen yet that we could plug in to? Or, do you mean write something separate outside of Squidex to query and update the content directly in the database?
I would just use the SDK for that (depending on your programming language), it can probably be done in a few lines of code. Don’t touch the database please
I have added new endpoints to the API to enforce the defaults. There is also CLI support for that.
sq contents enrich-defaults <my-schema>
But you need to update Squidex for that. I have considered to implement it without that, but I did not want to duplicate the default value logic.
We already have a basic task system in the API for backups. I think I will generalize this next year to allow other tasks as well. Then we can integrate some tasks into the UI.