Create a custom template for Doctrine Migrations

Doctrine Migrations are a great way to have versioning in your database that is managed by Doctrine ORM.

Migrations are generated as simple PHP files. If you want to change the layout of these files (for example to add method headers according to your coding standard) you can specify a custom template as shown below.

The first file is the doctrine configuration (in this case in YAML format for a Symfony 4 application). The “custom_template” part defines the path to your custom template file.

The second file is the template itself. Doctrine Migrations will use this template and fill the following tags:
<namespace> the namespace as declared in the configuration file
<version> the migration version number (a datetime format)
<up> will get replaced with the forward migrations
<down> will get replaced with the backward migrations