Hello! I’m evaluating headless CMS for a project, and wanted to know if cockpit supports any way of programmatic collection creation on startup — preferably via the config on startup, but CLI, HTTP API or an extension would do.
I understand that you can create / edit the collections from the UI, but I’d rather stay away from manual actions as these are tedious to replicate on QA & production, and I don’t see how you would update a running production server without falling into an inconsistent state (with missing collections / wrong schemas).
Accessing the backing database directly and adding collections bypassing cockpit, then manually registering the collection in cockpit could also be an option, but is it safe? Or maybe I’m missing something altogether?
1 Like
It’s not possible via config file, but you can just create them once and copy the schema files to your production server. The collecion schema files are stored in cockpit/storage/collections/collection_name.php
. The files return an array with the schema, so it’s easy to create one programmatically, too.
This might help, too:
Or just use cli commands
https://getcockpit.com/documentation/reference/CLI
1 Like
Thanks, this sounds neat. I’m also worried about the lack of numeric field types, but that’s a whole other topic.
The structure for a cockpit collection type is just a PHP array stored in a PHP file (/storage/collections), you can just have a custom workflow for QA & Production that deploy your files according (e.g. having the collections files versioned in git).
I use an approach of defining my data structures (singletons, collections, etc…) inside an addon with an info.yml file, and with the help of the helpers addon I can install them using the cli https://github.com/pauloamgomes/CockpitCMS-Helpers#addon-install-cli-command