New in Symfony 5.1: Automatic schema updates
Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
Some Symfony components (e.g. Cache, Lock, Messenger, etc.) can store their contents in databases using Doctrine ORM. This requires some manual setup to work. For example, to store sessions in the database you must create the table that stores the information.
We're big fans of automation, so we decided to automate all this in Symfony 5.1.
The idea is to implement some event subscribers that listen to advanced Doctrine
Events::onSchemaCreateTable from Doctrine DBAL and
ToolEvents::postGenerateSchema from Doctrine ORM) and inject the SQL code
required to create the database tables needed by each component.
These automatic database tables are generated only when you really need them.
Consider for example the Messenger component. If you configure a Doctrine
transport and run the
make:migration command, the database is created.
Otherwise, nothing will change in your database table. The same happens when using
PdoAdapter from Cache component,
PdoStore from Lock component, etc.
Symfony Docs will be updated soon to reflect this automation and simplify the setup required in some components.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.