Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update table columns with updateDBSchema if required #74

Open
hyOzd opened this issue Mar 9, 2022 · 1 comment
Open

update table columns with updateDBSchema if required #74

hyOzd opened this issue Mar 9, 2022 · 1 comment

Comments

@hyOzd
Copy link

hyOzd commented Mar 9, 2022

It would be nice if updateDBSchema also added/removed table columns when fields are added and removed from the respective class. I suspect this is one of those features that sounds easy but has a lot of edge cases to be handled?

@vnayar
Copy link
Contributor

vnayar commented Jan 8, 2024

This is one of those intractable problems that even the original Hibernate is unable to solve. The root of the issue is that some changes simply aren't able to be migrated automatically. Consider the following examples:

  • A new non-null column is added, but existing records are there and have no value for this column.
  • A column is changed from a double to an integer, but data already exists with fractional values.
  • A column is renamed. For a human this is trivial, but for a computer, it's unclear whether the old column was simply deleted and a new column was inserted, or if it is supposed to migrate data.

There are just a few simple examples, you can imagine a lot more I'm sure. For this reason, the typical workflow is to use automatic schema generation during local development, or in early stages of the project's development.

As systems enter production or have data that must be delicately preserved, automatic schema generation is disabled, and migration systems are used to make incremental changes to the DB. Systems like Flyway or Liquibase are common, but have their own trade-offs.

Alternatively, one can use a home-grown shellscript like the following: https://gist.github.com/vnayar/692d9c0d18dda4057f9a58add3449ebd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants