I try to change the name of database and application name in Rails. What is the shortcut for it by changing all the depended classes and configuration values?
3 Answers
I am not sure but I think we can't change database name. You need to follow some steps in rails application:
- Take dump of your existing database
- Create a new database (
postgres=# CREATE DATABASE new_database_name;) - Restore your dump in new database
- Manually change database name in app/config/database.yml
- Run Migrations
rails db:migrate - Finally drop the older existing database (if you want)
Comments
I really don't think there are any shortcuts built into rails to change the name of the entire project as well as the database, but luckily it really isn't that hard to make the change.
Once you've edited the application.rb file and the database.yml file, you should just do a quick find and replace in project call on your project to change any other necessary references.
Comments
I don't think it's possible for the database.
You can use mysqldump to dump the data and then create a schema with your new name and then dump the data into that new database
Then after dumping the data into the database just change the new database name in your database.yml
You can find the refrence below: https://dev.mysql.com/doc/refman/5.7/en/mysqldump-sql-format.html