Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use <code>rake -T</code> to get the description of each task:</p> <pre><code>$ rake -T | grep db rake db:create # Create the database from config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config) rake db:drop # Drops the database for the current Rails.env (use db:drop:all to drop all databases) rake db:fixtures:load # Load fixtures into the current environment's database. rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false). rake db:migrate:status # Display status of migrations rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n). rake db:schema:dump # Create a db/schema.rb file that can be portably used against any DB supported by AR rake db:schema:load # Load a schema.rb file into the database rake db:seed # Load the seed data from db/seeds.rb rake db:setup # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first) rake db:structure:dump # Dump the database structure to db/structure.sql. Specify another file with DB_STRUCTURE=db/my_structure.sql rake db:version # Retrieves the current schema version number </code></pre> <p>I this what you were asking about?</p> <p><strong>EDIT:</strong></p> <p>You can read more about what migrations are for here: <a href="http://guides.rubyonrails.org/migrations.html" rel="nofollow">http://guides.rubyonrails.org/migrations.html</a></p> <p><strong>EDIT 2:</strong></p> <p><code>rake db:migrate</code> allows 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.</p> <p>When you generate a new migration:</p> <p><code>$ rails g migration add_new_column_to_some_table</code> you will be able to run <code>rake db:migrate</code> later on to apply to changes you want (of course you have to write the body of this generated migration).</p> <p>I STRONLY advise you to read the guides though :)</p> <p><strong>EDIT 3:</strong></p> <p><code>add_column :users, :price, :float</code>, for example, will add <code>price</code> column to the <code>users</code> table, the type of the column will be <code>float</code> (<code>float</code> isn't a best idea to store money related things BTW!). This column will be <code>NULL</code> by default.</p> <p><strong>EDIT 4:</strong></p> <p>Information about which migrations were run is stored in <code>schema_migrations</code> table: running migration for the first time will add a new record in this table with <code>version</code> of 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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload