A free and open-source book on ZF3 for beginners


13.4. Executing Migrations

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:

./vendor/bin/doctrine-module migrations:migrate

The command above applies all available migrations in turn. It writes the IDs of the applied migration to the 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 migrations:migrate 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.


Top