Setting Environment For Rails Migration
TAGS:
ruby rails migration database environment
Related:
- Adding fields to table via migration.
- Creating migration file using generate migration
- Creation migration file using generate model.
- Creating migration file using scaffold.
- Drop tables using migration.
- Seeding data into tables via migration.
- Joining two tables via migration.
- Migration specific VERSION or STEP.
- Removing fields from tables via migration.
- Setting rails environment via migration command.
- Setup, reset and drop database
Setting Environment For Rails Migration.
You can set the environment for rails migration RAILS_ENV using one of two ways:
First, Using rake command line as:
rake db:migrate RAILS_ENV=test
#or
rake db:migrate RAILS_ENV=development
#or
rake db:migrate RAILS_ENV=productionSecond, Using system variables in command line
export RAILS_ENV=test
#or
export RAILS_ENV=development
#or
export RAILS_ENV=productionOr editing ~/.bashrc file to add RAILS_ENV as:
echo 'RAILS_ENV=test' >> ~/.bashrc
#or
echo 'RAILS_ENV=test' >> ~/.bashrc
#or
echo 'RAILS_ENV=test' >> ~/.bashrcAnd then, refresh your system variables using:
source ~/.bashrcYou can assure that you have system variable RAILS_ENV and its value using :
echo $RAILS_ENVNote, The database for that environment must be created before its migration.
Now, Take a look to this tutorial video: