MySQL schema management in Symfony project

时间:2015-05-24 21:11:18

标签: symfony doctrine-orm

So I am trying to embark on learning Symfony, and I want to do it right. So I am now thinking about the best way to manage my schemas. Up until now I was mainly using phpMyAdmin to create my tables as I go. But recently I took different approach. I started using workbench ERD modelling and I really like it. As it forces to sort think ahead about the database structure. And I found this:

https://github.com/johmue/mysql-workbench-schema-exporter

This exports the workbench ERD to (i think) Doctrine entities.

Another way I am thinking is to use the migrations. But it would seem like migrations is just the more tedious option which kind of gives the same result (minus the actual entity classes), as you have to type out all the relationships yourself. Whereas in workbench it is drag and drop.

So I suppose, the real question is, how reliable is the first method? Anyone have any experience using it? Would you better recommend using migrations instead? If so why? Is there any other way, I may not be aware?

2 个答案:

答案 0 :(得分:1)

I was using both methods. With the first one you can catch errors with doctrine when will start to create entities related to existing DB schema. With the second one you can catch some issues with foreign keys and existing data (when you change a column type). IMHO the second one is more easier and contains a predictable behavior.

Symfony projects are built based on "Code First" principle. It means that you should create an entity earlier than table in the database. More information you can find at this article.

答案 1 :(得分:1)

如果您想要更可靠的解决方案来生成Doctrine2 ORM定义(以YML,XML或注释格式),您可以查看Skipper application

它是ORM框架(Doctrine,Doctrine2,MongoDB ODM,...)的可视化编辑器,具有模式定义导入/导出支持。