Blogmark
Built-in Rails Database Rake Tasks
via jbranchaud@gmail.com
https://github.com/rails/rails/blob/1dd82aba340e8a86799bd97fe5ff2644c6972f9f/activerecord/lib/active_record/railties/databases.rake
Ruby on Rails
Database Migrations
It's cool to read through the internals of different rake tasks that are available for interacting with a Rails database and database migrations.
For instance, you can see how db:migrate
works:
desc "Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)."
task migrate: :load_config do
ActiveRecord::Tasks::DatabaseTasks.migrate_all
db_namespace["_dump"].invoke
end
First, it attempts to run all your migrations. Then it invokes _dump
which is an internal task for re-generating your schema.rb
(or structure.sql
) based on the latest DB schema changes.