We have a Java app using QueryDSL for managing SQL queries with Postgres. We want to simply rename a column in the most efficient way. In Postgres this is simple:
ALTER TABLE my_table RENAME COLUMN old_name TO new_name;
In order to have that work without application downtime, I was hoping to be able to do something like:
- Code change app deployment - make QueryDSL happy with both
old_nameandnew_name(in SELECTs and INSERT/UPDATEs) - DB Migration to rename column, as above.
- Code change app deployment - remove all references to
old_name.
However I don't know if there's any way to make step 1 possible with QueryDSL. E.g. some kind of annotation or behaviour to only use old_name and new_name if they exist, otherwise use the other.
Is this possible somehow?
If not, it looks like the only away to achieve a simple DB column rename is to completely duplicate the column, migrate data across, make the app write to both, and then eventually remove the old one. Surely there's an easier way!
Looks like the answer is no, this isn't possible with QueryDSL. So the only approach will be:
Source: https://github.com/ankane/strong_migrations?tab=readme-ov-file#renaming-a-column (a Ruby on Rails gem, but the principles are generally applicable.)