I've been working with Spring Boot for a while, and I've just started learning Symfony at university. In my job, we always use Liquibase or Flyway and manually write migration scripts whenever we change our entities. However, in class today, I added a field to a Symfony entity, and my professor told us to just run `make:migration`. I was surprised when Doctrine automatically generated the entire migration file for me, comparing the entity to the database and writing the SQL! I just had to run `doctrine:migrations:migrate`, and it was done without me writing any SQL.
While I understand the concept of `ddl-auto=update`, my senior developer advised against using it in real projects, which is why we manually write Liquibase changesets for every schema change. It feels like Symfony and Doctrine have really streamlined this workflow. Am I missing something, though? Is there a similar plugin in the Spring ecosystem for auto-generating migrations? Why doesn't automatic migration generation seem standard everywhere? What do others in the community actually use in their day-to-day workflows?
6 Answers
You really don’t want auto-generated migrations if you're dealing with significant data changes since they often get it wrong. Even big names like Apple have warnings against relying on automatic migrations beyond minor changes. Flyway allows you to create sequenced migrations with hashes to check for changes, which is a safer approach.
Isn't Flyway kind of the equivalent tool in Spring? From what I've seen, though, you usually end up writing migrations by hand with Flyway too.
The difference likely comes down to how Symfony and Doctrine handle migrations compared to Spring Boot. DDL changes can lead to irreversible data mutations, which can complicate auto-generating migrations. In simpler projects, this can be acceptable, but for larger projects where data integrity is crucial, you’ll want to go for manual migrations. It's often more reliable and allows for clearer control over the process.
Frameworks like Symfony and Rails include built-in features for automatic migration generation because they use an integrated ORM with dedicated CLI commands. This isn’t a standard approach in Spring Boot, possibly due to the need for compatibility with legacy systems or a more cautious approach towards database changes. While you can make it work with Spring Boot, for auto-generation, you often need to look for external tools.
Liquibase can actually generate the DDL for you, and it’s pretty versatile in migrating between databases or creating diffs. But the real issue is trust; you need to ensure these systems do the job right. Sometimes you have specific datatype mappings that need to be handled manually, and there are changes like replacing values in columns that auto-generators won't manage well.
Your senior's got a point. It can be tempting to rely on auto-generated migrations, but they tend to struggle once you're dealing with actual data migrations, beyond just adding tables or columns. If you think about version control, like with Git, it can mess things up when there are many changes, and that can lead to issues with production data. I have a system that automates migrations too, but it can't handle complex data changes, so I prefer to manage those manually after a basic setup. I'm still new to Symfony, but so far, adding simple columns or tables has been smooth for me.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically