Green Acorn

Blog

Useful Ruby on Rails Commands

1. Create a new Ruby On Rails application using the MySQL database adapter.

rails new ProjectName -d mysql

2. Dump current database schema into db/schema.rb. Migration tasks calls the below command after each run.

rake db:schema:dump

3. Generate a model

rails generate model ModelName

4. Create a migration

rails generate migration migrationName

5. Run migrations

rake db:migrate

6. Migrate to a given version. i.e. 0

rake db:migrate VERSION=0

7. Migrate status of what is up or down. Handy for getting migration id’s!

rake db:migrate:status

8. Run the migrate up method for a given version. i.e. 9999999.

rake db:migrate:up VERSION=9999999

9. Run the migrate down method for a given version. i.e. 9999999.

rake db:migrate:down VERSION=9999999

10. Run the migrate down method followed immediately by the up method for a given version. i.e. 9999999.

rake db:migrate:redo VERSION=9999999

Leave a Reply

Your email address will not be published. Required fields are marked *

     

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>