2

I have a Symfony 3 application where I use deployer to deploy my application. Also I am using Doctrine Migrations to migrate my database.

I use the symfony3 recipe.

When I run dep deploy, deployer migrates my database. However, when I run dep rollback it doesn't rollback the respective doctrine migrations.

I have searched through Google and Stackoverflow to find anybody solving this, but I can't seem to find anybody.

Do you have a good idea?

loevgaard
  • 23
  • 1
  • 4

1 Answers1

2

You can use backwards compatible migrations, this way no rollback is needed ever.

As it can result in a messy database, it's often a good idea to clean up the BC layers regularly. For instance:

  1. Deploy B is deployed, it has a migration to not use a full name column, but instead split up in first name and last name. The full name column is still kept to be backwards compatible;
  2. Assume B is unstable: You rollback to A. As there is still a fully working full name column, no migration rollbacks are needed;
  3. Assume B is stable: When deploying Deploy C, a migration should be executed that first makes sure all full name values are split in first name and last name and then remove the full name column completely;
  4. Assume deploy C is unstable: You rollback to B, as they both only use full name, no migration rollbacks are needed.
Wouter J
  • 41,455
  • 15
  • 107
  • 112
  • I like this approach, however it doesn't solve more complex problems. These are questions that came to my mind: 1. How to make a BC when you're changing relations between tables. 2. When somebody have a guarantee that something stable will be after a database change? – Tomsgu May 07 '18 at 10:48
  • 1
    @Tomsgu DoctrineMigration maintains BC by allowing you to specify both `up` and `down` methods. It is up to developer however to be diligent and double-check that both methods are correct. For myself, I usually call them twice right after writing (`php bin/console doctrine:migrations:migrate` and `php bin/console doctrine:migrations:migrate prev`) to see if there are any issues. Also, my Continous Integration does the same checks just to be sure. When introducing backward-incompatible change, you should indicate it by using `$this->throwIrreversibleMigrationException()` inside `down` migration – SteveB Jun 11 '18 at 14:42
  • Yeah of course it's possible with migrations. The thing is that we are talking about backwards compatible migrations without possibility to migrate to the previous version (rollback). – Tomsgu Jun 11 '18 at 15:32