Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to automatically have a "rake db:migrate RAILS_ENV=test" after "rake db:migrate" in development environment?

Tags:

Is there a way to automatically do a rake db:migrate RAILS_ENV=test after each rake db:migrate when in development environment?

I have guard and guard-rspec running, and I am really annoyed about the failing tests, even if it works manually in the browser.

It costs me at least 15 minutes every time I had a pause from development, to figure out that I simply forgot to call rake db:migrate:test after the change of the database.

Since I am already using guard I thought about adding guard-rake to the project also, but I dont know which file I should watch. When watching development.sqlite3, rake db:migrate RAILS_ENV=test would be fired every time I do something with my records through the browser, so this is not really what I want.

Can someone help me with my problem?

like image 797
NobbZ Avatar asked Aug 03 '11 16:08

NobbZ


People also ask

What does rake db setup do?

rake db:migrate makes changes to the existing schema. Its like creating versions of schema. db:migrate will look in db/migrate/ for any ruby files and execute the migrations that aren't run yet starting with the oldest.

Which command is true to rollback migration in Rails?

You must rollback the migration (for example with bin/rails db:rollback ), edit your migration, and then run bin/rails db:migrate to run the corrected version.

What does Rails db Migrate do?

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.


1 Answers

Possibly just make a command alias in your .bashrc file.

~/.bashrc

alias rake_db_migrate='rake db:migrate db:test:prepare' 

Terminal

$ rake_db_migrate 
like image 112
Daniel Doezema Avatar answered Jun 14 '23 15:06

Daniel Doezema