What's the difference between query.changeColumn and query.renameColumn?
Issue type:
[ ] question
Database system/driver:
[ ] mysql
TypeORM version:
[ ] latest
Steps to reproduce or a small repository showing the problem:
Today, I want to change comment description of one column, so I use query.changeColumn(), it seems so right, but not as my expect. Framework drop my column and create a new for me. It's unnecessary exactly.
Then, I use query.renameColumn(), I got the right response. But, don't u think it's strange? It seems just will rename my column name.
I don't think drop and create is the best way to migrate. You will delete all data in this column, that's very very dangerous operation. May refactor this method to: dropAndCreateColumn()
I want to change comment description of one column, so I use query.changeColumn(), it
do you only change the name? Are you sure about it?
I don't want to change my column's name, I want to change my column's comment schema. I think, or somebody also think, we should use queryRunner.changeCloumn().
But now, we can only use queryRunner.renameCloumn(), because queryRunner.changeCloumn() will drop my column at first, and then create it again.
The method queryRunner.renameCloumn() seems like a method only change column name. But it can do more things now. Maybe the method name renameCloumn is not proper here.
because queryRunner.changeCloumn() will drop my column at first, and then create it again.
everything is much more complicated as it may seem. There are reasons behind this behaviour. Column is dropped if you change type or length, because its required or operation may fail. If you only change name it will simply rename it.
That may be dangerous. You can't drop column because the data in this column will gone, and the developers may don't realize that. So I suggest you refactor the method's name.
If I just change length from 20 to 30, or change type from int to float, that's ok. When migrate fail, the developers should migrate the data by themselves before they change the column schema.
Just don't drop column dangerously.
If somebody who really want to drop it's column, he can use queryRunner.dropColumn.
I agree, I had the same issue few days ago, luckily we found out this behaviour in the logs before applying migrations to production but the naming was making me think of an ALTER command.
I'm closing this issue for housekeeping purposes, if something is not clear yet, just continue the conversation or post a message in slack
The method
queryRunner.renameCloumn()seems like a method only change column name. But it can do more things now. Maybe the method namerenameCloumnis not proper here.
@fwh1990 You mentioned that renameColumn can do more things. What else can it do other than change column name? Any suggestion is appreciated.
Agree, this almost just caused a catastrophe in our application. The naming is counter-intuitive. It should be something like replaceColumn. The change column implies an update/change to a column in place. Further, the SQL CHANGE COLUMN command is an update that would not lose data. It stands that anyone familiar with SQL would expect changeColumn would be executing a CHANGE COLUMN and NOT A DROP!!
This is a huge trap, and the author seems don't want to fix it. Am I right? I turn to use sequelize these years, and have no idea what happened to typeorm.
And I will not reuse typeorm before it fixes this issue. Sorry.
+1