How to migrate data on plugin updates?September 25, 2019 09:00
You need a new feature from one of our plugins ? You started on v1 but your using our v3 seo-plugin and there are some BC on the database level ? Here is a simple guide to help you to not lose tons of important data your customer added over time.
Doctrine migrations to the rescue
If you're not familiar with doctrine migrations, check the bundle documentation.
This bundle is our lord and savior. You will never work with
bin/console doctrine:schema:update again!
From now on you will repeat those to command forever:
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
The first one will generate a new migration class was generated based on the schema differences. If you open this file, you'll find that it has the SQL code for the changes you provided to your schema since the last migration.
The second one will run the migration to add tables, insert row, update, etc. to your database.
Furthermore, those files can be edited to add your own SQL directives.