All notes
Rak

Quick Start

Rake: Ruby make.

HelpDoc



# To find where the rake commands come from:
# http://stackoverflow.com/questions/4742930/where-are-rake-tasks-defined
rake -W db:create
# rake db:create                      /Users/me/.rvm/gems/[email protected]/gems/activerecord-4.2.7.1/lib/active_record/railties/databases.rake:16:in `block in <top (required)>'
# rake db:create:all                  /Users/me/.rvm/gems/[email protected]/gems/activerecord-4.2.7.1/lib/active_record/railties/databases.rake:10:in `block (2 levels) in <top (required)>'
# rake db:create_dev_company[domain]  /Users/me/works/proj/lib/tasks/populate.rake:32:in `block in <top (required)>'
# rake db:create_scim_dev_company     /Users/me/works/proj/lib/tasks/populate.rake:15:in `block in <top (required)>'

# It can also list all the tasks
rake -W db:test

db

test


# Drop the test table:
RAILS_ENV=test rake db:drop

# Create a new test table:
RAILS_ENV=test rake db:create
# Or create all:
# rake db:create:all

# Regenerate the test db:
# http://stackoverflow.com/questions/18636800/i-get-a-database-does-not-exist-error-when-running-unit-tests
rake db:test:prepare
# Or
# rake db:test:prepare_with_migrate

# Load seed
bundle exec rake db:seed

# Load fixtures into test
RAILS_ENV=test bundle exec rake db:fixtures:load

production

michaelrigart.be: rake basics.

SO: change a rails to production.


RAILS_ENV=production rake about

# Create a secret_key that you can add to config/secrets.yml
RAILS_ENV=production rake secret

RAILS_ENV=production rake db:migrate
# Push js, css, image files into the /public folder
RAILS_ENV=production rake assets:precompile
RAILS_ENV=production rails s

# Or
rails s -e production

migrate


# Use "schema_migrations" table to decide which migration to run:
rake db:migrate

rake db:migrate:status

# Bring down/up specific migration.
# http://stackoverflow.com/questions/753919/run-a-single-migration-file
rake db:migrate:down VERSION=20090408054532
rake db:migrate:up VERSION=20090408054532

# https://rubyinrails.com/2014/01/03/rake-db-migrate-with-down-up-redo-rollback-options/
# This will first run down part and then up part of the migration having version:
rake db:migrate:redo VERSION=20130717110623

# This will rollback last run migration(i.e. Default STEP=1)
rake db:rollback
# Rollback last n migrations
rake db:rollback STEP=4