views:

35

answers:

2

I'm a beginner with symfony (1.4 + Doctrine), but there is a point which scares me. It seems that whenever one wants to change a model, the only way is to change the schema for the database (config/doctrine/schema.yml) and then call symphony doctrine:build, which flushes all the current data in the database.

This does not seem to me like a sane way to proceed. What if after one year my app is in production I decide that my users need to be able to add their facebook page to the profile? In other frameworks (I'm used to CakePHP) it is just a matter of adding a field in the users table and modifying a model file and the profile view. In symfony... well, I don't know, that's why I'm asking here. I'm sure I'm missing something, as the symfony designers surely have considered the idea that one may want to refactor an application after the launch. What is the correct way to do this?

+1  A: 

You need to look into the migrations framework. This is basically made up of creating classes that describe the schema change. You can see a symfony 1.2 tutorial here: http://www.symfony-project.org/doctrine/1_2/en/07-Migrations and much of this will be valid for 1.4 as well.

lonesomeday
Thank you. It seems more complex than needed, especially for simple modifications, but I think it will do.
Andrea
The other option is to change the database manually and change the schema, but run doctrine:build with different options. If you do "./symfony doctrine:build --all-classes", that will update model, form and filter classes, but won't touch the database. This isn't the best way to do it, but would work at a pinch.
lonesomeday
Thank you very much: I guess both options have their use. A quick change can be made manually, and more complex operations with the helpp of Migrations.
Andrea
A: 

I never use build-all when there is data in my db. I just use build-classes for the models and build-sql, then I change the db, adding or changing fields by hand.

dazz