Create a custom template for Doctrine Migrations

KC Müller
Jun 28, 2018 · 1 min read

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

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store