| description |
|---|
Create a custom step for data migrations. |
Besides the built-in migrations steps, you can also create custom ones.
To create a custom migration step, you need:
- A step class, to store any additional data that you might require.
- A step normalizer, to convert YAML definition into your step class.
- A step executor, to handle the step.
The following example shows how to create a step that replaces all ibexa_string fields that have an old company name with "New Company Name".
First, create a step class, in src/Migrations/Step/ReplaceNameStep.php:
[[= include_file('code_samples/data_migration/src/Migrations/Step/ReplaceNameStep.php') =]]Then you need a normalizer to convert data that comes from YAML into a step object,
in src/Migrations/Step/ReplaceNameStepNormalizer.php:
[[= include_file('code_samples/data_migration/src/Migrations/Step/ReplaceNameStepNormalizer.php') =]]Then, tag the step normalizer, so it's recognized by the serializer used for migrations.
[[= include_file('code_samples/data_migration/config/custom_services.yaml', 18, 23) =]]And finally, create an executor to perform the step, in src/Migrations/Step/ReplaceNameExecutor.php:
[[= include_file('code_samples/data_migration/src/Migrations/Step/ReplaceNameStepExecutor.php') =]]Tag the executor with ibexa.migrations.step_executor tag.
[[= include_file('code_samples/data_migration/config/custom_services.yaml', 23, 27) =]]Then you can create a migration file that represents this step in your application:
- type: company_name
mode: replace
replacement: 'New Company Name' # as declared in normalizer, this is optional