We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Refresh database

Looked at great example https://github.com/phalcon/tutorial-models-init I've got a question: Is there any way to refresh database (create, alter tables, etc) by models definitions, like $connection->updateDatabase()? Or only way is using createTable, alterTable functions (https://docs.phalcon.io/en/latest/reference/db.html#creating-tables) with manual check for diff?



98.9k

There is no an automatic way to do that, but I think the migrations code on devtools could be reused to implement something similar to the idea you have.

https://github.com/phalcon/phalcon-devtools/tree/master/scripts/Phalcon/Mvc/Model