Short answer:
db:schema:dump
wrong to use, but you can add a few lines of code to your Rakefile to get the desired result.
Longer answer:
The workaround is that the db:schema:dump
task should not really dump anything more than the structure. (I know this is the wrong name.) This is an analogue of db:structure:dump
, except that it gives you the .rb file and the other gives you the .sql file.
You can create your own rake reset command by adding the following code to your Rakefile:
For SQL 2008
task :mydump do ActiveRecord::Base.connection.execute( "dbcc traceon(2544, -1) \n go \n dbcc traceon(2546, -1) \n go \n dbcc stackdump" ) end
Using the SQL server itself to dump (this is what the output code does) limits you because the dump will always go to your log directory; you cannot specify otherwise.
If you use SqlDumper or some other utility, you will have more freedom. You can call such a utility from your rake task by executing it as from a command line using the system
method. (See the MySQL example below, which uses the mysqldump utility.)
(I did not test the source code without having to install SQL 2008 myself, but the SQL source code for dumping from the SQL server is explained on this blog .)
Rake task
Then, on the command line, call rake mydump
or rake mydump RAILS_ENV=production
.
For MySQL
You can do something similar for MySQL with the following:
task :mydump do config = Rails.configuration.database_configuration[Rails.env] system "mysqldump -h #{config["host"]} -u #{config["username"]} -p#{config["password"]} #{config["database"]} > db/dump.sql" end
source share