-
-
Notifications
You must be signed in to change notification settings - Fork 388
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
Implement all or nothing transaction strategy for migrations. #683
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,7 @@ commands to our `Doctrine Command Line Interface <http://doctrine-orm.readthedoc | |
new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand() | ||
)); | ||
|
||
Additionally you have to make sure the 'db' and 'dialog' Helpers are added to your Symfony | ||
Additionally you have to make sure the ``db`` and ``dialog`` Helpers are added to your Symfony | ||
Console HelperSet. | ||
|
||
.. code-block:: php | ||
|
@@ -185,18 +185,87 @@ the migrations are executed in the correct order. | |
While you *can* use custom filenames, it's probably a good idea to let Doctrine | ||
:doc:`generate migration files </reference/generating_migrations>` for you. | ||
|
||
|
||
And if you want to specify each migration manually in YAML you can: | ||
|
||
.. code-block:: yaml | ||
|
||
table_name: doctrine_migration_versions | ||
migrations_directory: /path/to/migrations/classes/DoctrineMigrations | ||
migrations: | ||
migration1: | ||
version: 20100704000000 | ||
class: DoctrineMigrations\NewMigration | ||
migration1: | ||
version: 20100704000000 | ||
class: DoctrineMigrations\NewMigration | ||
|
||
If you specify your own migration classes (like `DoctrineMigrations\NewMigration` in the previous | ||
example) you will need an autoloader unless all those classes begin with the prefix Version*, | ||
for example path/to/migrations/classes/VersionNewMigration.php. | ||
|
||
All or Nothing Migrations | ||
~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
If you want your migrations to be all or nothing then you can configure your migrations behave that way. | ||
This means when you executed multiple migrations in a row, the whole migration will be wrapped | ||
in a single migration and if one of the migrations fails, the transaction will be rolled back. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
looks like a typo? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like it. Can you check if it still exists in master and record an issue to fix it if so? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jwage oh, didn't realize that the PR is so old 😅 The whole paragraph is gone in 2.0 and I couldn't find it in 1.8 either (that's where this PR landed). So probably already fixed then. 👍 |
||
|
||
.. note:: | ||
|
||
This only works if the database connection you are using supports transactional DDL statements. | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: php | ||
|
||
$configuration = new Configuration($connection); | ||
$configuration->setAllOrNothing(true); | ||
|
||
.. code-block:: xml | ||
|
||
<?xml version="1.0" encoding="UTF-8"?> | ||
<doctrine-migrations xmlns="http://doctrine-project.org/schemas/migrations/configuration" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://doctrine-project.org/schemas/migrations/configuration | ||
http://doctrine-project.org/schemas/migrations/configuration.xsd"> | ||
|
||
<name>Doctrine Sandbox Migrations</name> | ||
|
||
<migrations-namespace>DoctrineMigrations</migrations-namespace> | ||
|
||
<table name="doctrine_migration_versions" /> | ||
|
||
<migrations-directory>/path/to/migrations/classes/DoctrineMigrations</migrations-directory> | ||
|
||
<all-or-nothing>true</all-or-nothing> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... here it is true. Should be consistent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The docs were updated and fixed at some point in the future. FYI, we take the string from the XML and pass it through this class https://github.com/doctrine/migrations/blob/master/lib/Doctrine/Migrations/Tools/BooleanStringFormatter.php here https://github.com/doctrine/migrations/blob/master/lib/Doctrine/Migrations/Configuration/XmlConfiguration.php#L89 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the feedback |
||
|
||
</doctrine-migrations> | ||
|
||
.. code-block:: yaml | ||
|
||
name: Doctrine Sandbox Migrations | ||
migrations_namespace: DoctrineMigrations | ||
table_name: doctrine_migration_versions | ||
migrations_directory: /path/to/migrations/classes/DoctrineMigrations | ||
all_or_nothing: true | ||
|
||
|
||
.. code-block:: json | ||
|
||
{ | ||
"name" : "Doctrine Sandbox Migrations", | ||
"migrations_namespace" : "DoctrineMigrations", | ||
"table_name" : "doctrine_migration_versions", | ||
"migrations_directory" : "/path/to/migrations/classes/DoctrineMigrations", | ||
"all_or_nothing" : true | ||
} | ||
|
||
You can also optionally use the ``--all-or-nothing`` option from the command line to enable or disable | ||
the feature for a specific migration run: | ||
|
||
.. code-block:: bash | ||
|
||
$ ./doctrine migrations:migrate --all-or-nothing | ||
|
||
Or if you have it enabled in your configuration setup and you want to disable it for a migration: | ||
|
||
.. code-block:: bash | ||
|
||
$ ./doctrine migrations:migrate --all-or-nothing=0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it is 1...