John Davidson

php - Where should my migration files be if the entity is in from a shared library?


I'm working on a project with shared entities in a library.

Assuming that 3 projects use these entities, where should I put my doctrine migration files ?
In the library ? or in each project ? What's the best practice about that ?

I tried putting it them in the bundle but then I had to implement a VersionComparator to tell Doctrine which migration to run first.

My Answer:
It is generally recommended to keep migration files in the project that is using the entities, rather than in the shared library. This is because migrations are specific to the database schema of a particular project, and having them in the project allows for better organization and management.

If multiple projects are using the shared entities, each project should have its own set of migration files to manage the database schema changes specific to that project. This way, each project can independently manage its own database schema changes without affecting the others.

As for the VersionComparator issue you mentioned, this is a common problem when using shared entities across multiple projects. One way to handle this is to ensure that the migration files in each project are named in a consistent and predictable way, so that Doctrine can determine the correct order in which to run them. Additionally, you can manually specify the order of migrations in the migration configuration file if needed.

Overall, the best practice is to keep migration files in the project that is using the entities, and to ensure that each project has its own set of migration files to manage database schema changes independently.

Rate this post

4 of 5 based on 1021 votes


© 2024 - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us