Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does rake db:schema:dump recreate schema.rb from migrations or the database itself?

Does

rake db:schema:dump 

recreate schema.rb from migrations or the database itself?

like image 290
pingu Avatar asked Sep 28 '10 17:09

pingu


People also ask

How is schema RB generated?

It is a Ruby representation of your database; schema. rb is created by inspecting the database and expressing its structure using Ruby.

What does Rails DB Reset do?

db:reset: Resets your database using your migrations for the current environment. It does this by running the db:drop , db:create , db:migrate tasks. db:rollback: Rolls the schema back to the previous version, undoing the migration that you just ran. If you want to undo previous n migrations, pass STEP=n to this task.


1 Answers

The answer is simple: from the database.

By the way - when you take a look into the source code of db:* tasks you can see that migration tasks calls schema:dump after the run

desc "Migrate the database (options: VERSION=x, VERBOSE=false)." task :migrate => :environment do   ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true   ActiveRecord::Migrator.migrate("db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)   Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby end 

So the migration works in the way that it change the database and then generate schema.rb file.

like image 132
Radek Paviensky Avatar answered Oct 02 '22 21:10

Radek Paviensky