Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails migration management - best practices?

What are best practices for migration management?

For instance, when debugging a migration, do you edit the original migration or add an edit migration before committing to the repository? Thanks!

like image 910
happythenewsad Avatar asked Jun 17 '09 19:06

happythenewsad


People also ask

How do I migrate a specific migration in rails?

To run a specific migration up or down, use db:migrate:up or db:migrate:down . The version number in the above commands is the numeric prefix in the migration's filename. For example, to migrate to the migration 20160515085959_add_name_to_users. rb , you would use 20160515085959 as the version number.

How does migration work in rails?

A Rails migration is a tool for changing an application's database schema. Instead of managing SQL scripts, you define database changes in a domain-specific language (DSL). The code is database-independent, so you can easily move your app to a new platform.

How can I check my rails migration status?

To check for status, run rails db:migrate:status . Then you'll have a good view of the migrations you want to remove. Then, run rails db:rollback to revert the changes one by one.

What does Add_index do in rails?

It adds a multi-column index on columns one and two in resources table. The advantage of multi-column index is that it helps when you have a query with conditions on those multiple columns.


2 Answers

I tend to edit the original migration as long as it is a) the last migration and b) not in source control. This presents a clean migration path for all other consumers of the code. The important thing is that your migrations should be able to run without error from whatever database state is the earliest that you can expect to encounter.

like image 51
Ben Hughes Avatar answered Oct 10 '22 18:10

Ben Hughes


Start testing your migrations.

http://blog.carbonfive.com/2011/01/27/start-testing-your-migrations-right-now/

like image 31
Christian Bradley Avatar answered Oct 10 '22 18:10

Christian Bradley