skip to Main Content

What I want to do : For every migrations executed with php bin/console doctrine:migrations:migrate to be wrapped in a proper transaction (START TRANSACTION / BEGIN / ROLLBACK / …).

My config/doctrine_migrations.yml file contains the following options :

doctrine_migrations:
    migrations_paths:
        # namespace is arbitrary but should be different from AppMigrations
        # as migrations classes should NOT be autoloaded
        'DoctrineMigrations': '%kernel.project_dir%/migrations'
    enable_profiler: false
    # Run all migrations in a transaction.
    all_or_nothing: true
    # Adds an extra check in the generated migrations to ensure that is executed on the same database type.
    check_database_platform: true
    # Whether to wrap migrations in a single transaction.
    transactional: true

And in any case the isTransactional method from AbstractMigration returns true by default.

Am I missing something here ? Does "transactions" here have another meaning than what’s I’m expecting ?

I’m running symfony 6.3.7 with doctine-migrations-bundle 3.2.4 on a 5.7.29 MySQL database

2

Answers


  1. Chosen as BEST ANSWER

    Well it turns out the transactions are being set as expected but MySQL autocommits when executing a DDL statement (CREATE / ALTER TABLE / ...), so as soon as a DDL statement is run in a migration file, the transaction is commited and the transactionnal mode is turned off and there is no rollback to the previous state.


  2. The transactional configuration value is apparently only used when generating a new migration, as can be seen in the generator, when transactional is set to false, AbstractMigration::isTransactional will be overridden to return false instead.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search