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

Ruby on-RailsSchemaMigrationRake

Ruby on-Rails Problem Overview


Does

rake db:schema:dump

recreate schema.rb from migrations or the database itself?

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionpinguView Question on Stackoverflow
Solution 1 - Ruby on-RailsRadek PavienskyView Answer on Stackoverflow