Migration helper to rename tables without downtime
A plain rename of a table requires downtime because the running app cannot cope with the fact the table is suddenly gone. See !20809 (merged).
However, there might be an alternative approach that implements renaming of tables without requiring downtime. Here, we leverage writable views to hide the fact the table was renamed until the application gets reloaded and a post-deploy cleans up.
BEGIN; ALTER TABLE foo RENAME TO foo_renamed; CREATE VIEW foo AS SELECT * FROM foo_renamed; COMMIT;
- The running app is oblivious of the rename and continues to use
foo- this should also work for DML statements (we may want to test this extensively, a straight
insert/delete into foo...on the view works just fine.
- Application gets reloaded now to start using
- Post-deploy cleans up and drops the view.
If we have table renames, I think it'd be valuable to implement this given that normally we don't tolerate downtime migrations.