Tuesday, April 04, 2006

Rails schema cloning

While recently working through an Oracle schema cloning issue we were using rake db:test:clone to clone the database. We noticed that the cloning was not working correctly; therefore, we needed to go back to dumping the schema to development_structure.sql. This is easily done by changing config.active_record.schema_format = :sql in environment.rb.

However, even after making the above change in environment.rb, rake db:test:clone kept creating a schema.rb file and not a development_structure.sql. This surprised us, because running rake did create a development_structure.sql and did not create a schema.rb.

After a brief look at the list generated by rake -T, we noticed the rake test:db:clone_structure task. rake test:db:clone_structure does generate development_structure.sql.

This is easy enough to remember once you learn, but I'm not sure that it's the most intuitive option. To me, rake db:test:clone is very generic and should behave similar to rake by reading the environment.rb file and creating the expected file.

If it's truly necessary to have a task that generates specifically schema.rb or development_structure.sql they could be name more explicitly as test:db:clone_using_ruby and test:db:clone_using_sql, or something along those lines. Though, I have to wonder if anyone is actually setting their environment.rb to one option and running rake with the other option.
Post a Comment