-
Couldn't load subscription status.
- Fork 2.2k
Description
It looks like the documentation on this function call is very sparse. https://knexjs.org/guide/schema-builder.html#renamecolumn
It just says Renames a column from one name to another. which is what I expected it to do.
When calling this function using the mysql2 driver I was expecting it to a run a very simple ALTER TABLE x RENAME COLUMN y TO z statement.
What actually happened is it dropped every foreign key pointing to the table I was renaming a column on, and then re-added the keys afterwards.
This ended up dropping a foreign key on an enormous table which took around 7 hours to re-add.
Looking at the code in lib/dialects/mysql/schema/mysql-tablecompiler.js this does appear to be the expected behaviour. I can see it calls getFKRefs() followed by a dropFKRefs() and then a final createFKRefs() once the columns have been renamed.
It would be nice if this additional behaviour was documented so users are aware that they should use knex.raw() on mysql when simply re-naming a column rather than using the renameColumn() function