Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Custom migration template into the documentation #1128

Merged
merged 1 commit into from
Feb 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions docs/en/reference/custom-configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,47 @@ With this configuration you can use the ``--conn`` parameter to specify a connec
migrations. If the parameter is not passed, it will fallback to the one passed in the configuration,
and if that is also not provided it will fallback to the default connection name specified when creating
the connection registry.

Custom migration template
-------------------------

When the default generated migrations do not suit your needs, you may provide a custom migration template that will
be used to generate future migrations.

For example, if you don't need a ``down`` migration your template could look like this:

.. code-block:: php

<?php

declare(strict_types=1);

namespace <namespace>;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class <className> extends AbstractMigration
{
public function up(Schema $schema): void
{
<up>
}
}

Placeholders (words inside ``< >``) are replaced with correct code upon generation. All possible wildcards are:

=============== ===============================================
Placeholder Description
--------------- -----------------------------------------------
``<namespace>`` Namespace of the class, e.g. ``App\Migrations``
``<className>`` Classname, e.g. ``Version20210212092730``
``<up>`` SQL for migrating up
``<down>`` SQL for migrating down
=============== ===============================================

The custom template needs to be configured.

.. code-block:: php

$configuration->setCustomTemplate(__DIR__ . '/custom_template.tpl');