Menu

Renaming columns and tables without losing data
📰

Renaming columns and tables without losing data

DEV Community: java·Feroz Shah·1 day ago
#OXu3n4IX
#devtojava#devto#dev#rename#table
Reading 0:00
15s threshold

Renames are where generated migrations usually go wrong. When a field changes from name to fullName , the database only sees one column disappear and another appear. A tool that just compares the two schemas drops the old column, and every value in it, then adds an empty new one.

Migrax notices when a change looks like a rename. In a terminal it asks you. In CI, where no one can answer, it refuses to write a migration that would lose the data. This article shows both cases for a column and for a table, and how to undo a rename.

Tested with: Migrax 0.17.1, Hibernate 6.6.13, PostgreSQL 17.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.