Once our migration classes are ready, you can apply the migrations to database. To do that, you use the
migrations:migrate console command as follows:
The command above applies all available migrations in turn. It writes the IDs of the applied migration to
migrations database table. After that, the
migrations table will look as follows:
mysql> select * from migrations; +----------------+ | version | +----------------+ | 20160901114333 | | 20160901114938 | +----------------+ 2 rows in set (0.00 sec)
If you want to upgrade or downgrade to some specific version, specify the migration ID as the
command's argument as follows:
./vendor/bin/doctrine-module migrations:migrate 20160901114333
You can also use 'prev', 'next' and 'first' aliases as version IDs which respectively move database to its previous state, next state or to the state before the first migration (empty database).
So, with migrations you can easily move through migration history and change the database schema as needed. Be careful though that migrations may remove some of your data, so apply them wisely.