Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine 2 Migrations Workflow

I am developing a web application using Zend Framework 2 and Doctrine 2. I'm new to Doctrine 2 in general and Migrations in particular. I was wondering if there are any recommended best practices in using this. Some specific things I'm looking for:

  • A recommended workflow from development to deployment?
  • Do you include pre-populating data in migrations?
  • How to handle reverting to a previous version if migration fails.

Many thanks!

like image 292
stase Avatar asked Apr 25 '15 20:04

stase


People also ask

What is a doctrine migration?

The Doctrine Migrations offer additional functionality on top of the database abstraction layer (DBAL) for versioning your database schema and easily deploying changes to it. It is a very easy to use and powerful tool. In order to use migrations you need to do some setup first.

What is migration in symfony?

Database migrations are a way to safely update your database schema both locally and on production. Instead of running the doctrine:schema:update command or applying the database changes manually with SQL statements, migrations allow to replicate the changes in your database schema in a safe manner.

What is Symfony doctrine?

Symfony provides all the tools you need to use databases in your applications thanks to Doctrine, the best set of PHP libraries to work with databases. These tools support relational databases like MySQL and PostgreSQL and also NoSQL databases like MongoDB.

How should be the process to add a new entity to the app in Symfony?

With the doctrine:database:create command we create a new database from the provided URL. With the make entity command, we create a new entity called City . The command creates two files: src/Entity/City. php and src/Repository/CityRepository.


2 Answers

Doctrine has own library for migrations, that includes also Symfony bundle.

For Zend there probably is some bundle as well (maybe seek on Github a bit more)

As for your specific questions:

  1. Nothing special. Basic workflow is nicely described in Symfony bundle documentation. We use it in pretty same way even in a different framework.

  2. Yes, so every developer has fully operational system. For tests we use data-fixtures with minimal required data only.

  3. It's managed by this package itself.

like image 141
Tomas Votruba Avatar answered Oct 17 '22 03:10

Tomas Votruba


The Doctrine ORM module for ZF2 (DoctrineORMModule) has built-in support for Doctrine ORM migrations. There's a very brief blurb in the documentation about how to configure it. You can then access the migration commands (generate, migrate, etc) through the CLI interface that module provides (vendor/bin/doctrine-module)

As for my personal workflow I generally put initialization or pre-population data - the stuff you initially seed a new installation with - into database fixtures (which Doctrine ORM also supports and there is a ZF2 module for).

like image 30
Adam Lundrigan Avatar answered Oct 17 '22 03:10

Adam Lundrigan