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_name
andnew_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!
Is creating a view
select .., old_name as new_name
an option?@Serg that possibly could help, but I’m looking for the simplest way to rename a column, and creating a view’s not simpler than the duplicate-column approach. I think what I’m after is more likely to be a heavy-weight ORM feature, but QueryDSL is much more basic than that.