Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

question from:https://stackoverflow.com/questions/46940405/rails-5-rename-table-migration

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
691 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...