Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Altering a database in symfony (doctrine)

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?

like image 768
Andrea Avatar asked Dec 19 '25 17:12

Andrea


1 Answers

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.

like image 88
lonesomeday Avatar answered Dec 22 '25 10:12

lonesomeday



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!