Skip to content

Bakery Planner

The Bakery Planner makes it possible to define Brezel configurations that can be applied to the respective system database in a declarative fashion. Instead of having to write migrations for your modules or having to manually use the API or write PHP code, you declare the resources you want in .bake.json files. The Bakery Planner takes care of the rest, analyzing the difference between your desired state and the system’s state, and then applying the changes.

You can define modules, entities, translations, styles and more as “Bakery resources”. These resources have a type, a name, and the resource definition. The planner keeps track of your configuration using its name and connects it to a Brezel identifier, like a module or entity ID, in the system database.

For a non-exhaustive list of available resource types, see the reference.

Bakery resources

A “Bakery resource” is a definition written in JSON or YAML that describes a desired Brezel module, entity, workflow, style or any other configurable Brezel resource.

The Bakery Planner scans the systems directory for Bakery resources and computes a difference between the state in the Brezel database and the desired configuration in the resources. When differences are found, the Planner applies the desired changes and updates the state.

Bakery resources are used to seed the module structure and keep it up to date (i.e. module tables and their columns), to define module entities (i.e. data rows in the module tables), and even workflows.

Bakery resources are defined in .bake.json or .bake.yml files. One such file can contain multiple resources:

[
{
"resource_module": "clients",
"resource": {
"identifier": "client",
"type": "clients",
"title": "title",
"icon": "setting",
"fields": [
{
"identifier": "title",
"type": "text"
}
]
}
},
{
"resource_user": "main_client",
"resource": {
"module": "clients",
"fields": {
"title": "Default client"
}
}
}
{
"resource_module": "users",
"resource": {
"identifier": "users",
"type": "users",
"title": "number",
"icon": "user",
"fields": [
{
"identifier": "email",
"type": "email"
},
{
"identifier": "password",
"type": "password"
},
{
"identifier": "name",
"type": "text"
}
]
}
},
{
"resource_user": "admin_user",
"depends_on": "resource_client.main_client",
"resource": {
"module": "users",
"fields": {
"email": "admin@brezel.io",
"password": "secret"
}
}
}
]

Using template strings

You can use template strings in your configuration to reference system environment variables or other resources. Template strings are enclosed in ${} and can contain any valid Recipe expression:

{
"resource_user": "admin_user",
"depends_on": "resource_client.main_client",
"resource": {
"module": "users",
"fields": {
"email": "admin@brezel.io",
"password": "${env('ADMIN_PASSWORD')}"
}
}
}

Referencing another resource:

{
"resource_entity": "supplier",
"resource": {
"module": "clients",
"fields": {
"title": "${resource_user.admin_user.fields.email}"
}
}
}

You can also compose your files using jsonFile():

{
"resource_module": "customers",
"resource": {
"identifier": "customers",
"title": "name",
"icon": "user",
"layouts": {
"detail": "${jsonFile('path/to/layouts/detail.json')}"
}
}
}

Or insert text values using file():

{
"resource_module": "customers",
"resource": {
"identifier": "customers",
"title": "name",
"icon": "user",
"fields": [
{
"identifier": "content",
"type": "textarea",
"options": {
"default": "${file('path/to/content.txt')}"
}
}
]
}
}

Recipe functions specific to the Bakery Planner

  • env('VARIABLE_NAME'): Get the value of an environment variable.
  • jsonFile('path/to/file.json'): Load a JSON file.
  • glob('path/to/files/*'): Return an array of files matching the glob pattern.
  • appEnv(): Get the current application environment (e.g. local, production).

Applying planned changes

Full documentation: CLI reference

To apply the changes defined in the Bakery resources, run the following command:

Terminal window
php bakery apply