Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 5: rename table migration

What is the best possible way to change name of table using migration and change name of all the files like controller, model and associations?

Will there be any issue when someone will try to run rails:db:migrate after cloning my repo?

like image 755
Talha Junaid Avatar asked Oct 25 '17 19:10

Talha Junaid


1 Answers

What is the best possible way to change name of table using migration

To change the name of a table, you can run:

$ rails g migration change_[old_table_name]_to_[new_table_name] 

Within the change method in the migration file generated, add this:

def change   rename_table :[old_table_name], :[new_table_name] end 

Change [old_table_name] and [new_table_name] in both cases.

(This part of the question has been answered here.)

will there be any issue when someone will try to run rails db:migrate after cloning my repo?

Nope. Keep the old migration files in place and generate a new one. That's the benefit of database migrations.

What is the best possible way to change name of all the files like controller, model and associations?

It's generally not too big of a deal to change a model name. Many text editors have the ability to search and replace within a directory.

And I would manually rename the filenames.


Here's a set of more detailed steps to make sure you've hit everything that needs to be changed.

like image 169
seancdavis Avatar answered Sep 19 '22 14:09

seancdavis