I am very new in ruby-on-rails. I have doubt in rake. create function is create a new db. After that, we want to run some commands like
rake db:load
rake db:data:load
rake db:schema:load
rake db:migrate
rake db:seed
But why we want to run this cmds after create the db and what function of the about cmd.
Thanks for your advice.
You can use
rake -Tto get the description of each task:I this what you were asking about?
EDIT:
You can read more about what migrations are for here: http://guides.rubyonrails.org/migrations.html
EDIT 2:
rake db:migrateallows you to update the DB schema in a “sane” way: you can create a new migration (read the guides!) and add a new column for example, add an index, rename a column, etc. – migrations allow you to “travel” back and forth in “time” – you can run the migration and rollback it later.When you generate a new migration:
$ rails g migration add_new_column_to_some_tableyou will be able to runrake db:migratelater on to apply to changes you want (of course you have to write the body of this generated migration).I STRONLY advise you to read the guides though 🙂
EDIT 3:
add_column :users, :price, :float, for example, will addpricecolumn to theuserstable, the type of the column will befloat(floatisn’t a best idea to store money related things BTW!). This column will beNULLby default.EDIT 4:
Information about which migrations were run is stored in
schema_migrationstable: running migration for the first time will add a new record in this table withversionof this migration (date + some random numbers from the name of the file). Rollbacking a migration will remove this record. Running a migration twice will not have any effect.