Details
-
Story
-
Resolution: Unresolved
-
Medium
-
None
-
None
Description
Introduces the concept of RepeatableStep.
To allow it to work, expression syntax is allowed almost everywhere. There are two variants:
Whole string starts with ### and ends with ###. Everything inside is treated as an expression and it's resulting value is returned as-is.
String contains ###FOO <expression> FOO###, where FOO can be any string (no whitespace). Since it is "inside" the string, it's result is always implicitly cast to string.
Expression language contains an extension point that allow adding functions to it, for example:
fields:
- value: '### faker().name() ###'
We might add a configuration for, so it's (not?) enabled by default.
Samples
type: repeatable
mode: create
iteration_counter_name: i # default, optional
iterations: 2
steps:
-
type: sql
mode: execute
query:
-
driver: mysql
sql: 'CREATE TABLE `test_migration1_mysql_###XXX i XXX###` (`name` varchar(255) NOT NULL);'
-
type: sql
mode: execute
query:
-
driver: mysql
sql: 'CREATE TABLE `test_migration2_mysql_###XXX i XXX###` (`name` varchar(255) NOT NULL);'
Such migration would result in 4 steps being executed, as if they were defined as:
-
type: sql
mode: execute
query:
-
driver: mysql
sql: 'CREATE TABLE `test_migration1_mysql_0` (`name` varchar(255) NOT NULL);'
-
type: sql
mode: execute
query:
-
driver: mysql
sql: 'CREATE TABLE `test_migration2_mysql_0` (`name` varchar(255) NOT NULL);'
-
type: sql
mode: execute
query:
-
driver: mysql
sql: 'CREATE TABLE `test_migration1_mysql_1` (`name` varchar(255) NOT NULL);'
-
type: sql
mode: execute
query:
-
driver: mysql
sql: 'CREATE TABLE `test_migration2_mysql_1` (`name` varchar(255) NOT NULL);'
This will allow creation of multitude of Content Objects and similar using Ibexa Migrations, without needless repetition.
Extensions and Faker integration
Additionally, as proof of the ability to extend this functionality, Faker integration is included (conditionally, depending on whether fakerphp/faker is installed).
Any other functionality can be added into expression language. To do so, it needs to be declared as a service tagged with ibexa.migrations.template.expression_language.function.
For example:
ibexa.migrations.template.to_bool:
class: Closure
factory: [ Closure, fromCallable ]
arguments:
- 'boolval'
tags:
- name: 'ibexa.migrations.template.expression_language.function'
function: to_boolibexa.migrations.template.faker:
class: Closure
factory: [ Closure, fromCallable ]
arguments:
- 'Faker\Factory::create'
tags:
- name: 'ibexa.migrations.template.expression_language.function'
function: faker
Service-based functions can be also added, but they have to be callable - so they probably will need __invoke function, or a wrapping service with one.