To generate/update db/schema.rb
even if using the :sql
option, you can put this in your Rakefile
:
Rake::Task["db:migrate"].enhance do
if ActiveRecord::Base.schema_format == :sql
Rake::Task["db:schema:dump"].invoke
end
end
That should be fine for IDea and RubyMine.
For others that just want the file for reference, you might want to rename it to something else like db/schema.rb.backup
so it won't be confusing. To do that:
Rake::Task["db:migrate"].enhance do
if ActiveRecord::Base.schema_format == :sql
Rake::Task["db:schema:dump"].invoke
File.rename(File.expand_path('../db/schema.rb', __FILE__), File.expand_path('../db/schema.rb.backup', __FILE__))
end
end
(Note: Using ../
in paths in Rakefile
because __FILE__
evaluates to a path that ends in /Rakefile
.)