Is it possible to use Postgres's RENAME COLUMN with QueryDSL, with no app downtime?

52 Views Asked by At

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:

  1. Code change app deployment - make QueryDSL happy with both old_name and new_name (in SELECTs and INSERT/UPDATEs)
  2. DB Migration to rename column, as above.
  3. 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!

1

There are 1 best solutions below

0
stwr667 On

Looks like the answer is no, this isn't possible with QueryDSL. So the only approach will be:

  1. Create a new column
  2. Write to both columns
  3. Backfill data from the old column to the new column
  4. Move reads from the old column to the new column
  5. Stop writing to the old column
  6. Drop the old column

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.)