Question

I've seen http://github.com/muness/migration_sql_generator, but it doesn't work properly with MySQL for certain important operations. Is there any other way we can capture the sql generated during a rails migration?

The reason I'm asking is that I cannot run the migrations on the production server since it is maintained by technical support (and never touched by developers) at my company. Developers provide a JRuby on Rails war file to tech support and they deploy it via Tomcat. But convincing tech support to install JRuby and Rails just to run the migrations on production is definitely not going to be easy. We want to keep the deployment really simple and with as few dependencies as possible.

We want to simply provide them with a war file and a sql script with db changes.

Was it helpful?

Solution 2

I actually ended up creating a rake task which monkey-patched Activerecord's sql execution method to also output all sql to a log file (log/database.log). So, the task could be run right before db:migrate like so: rake db:log db:migrate. After that, you can extract the statements which are relevant and put them into a db/sql_migrations/<migration name>.sql file and have your database admins run that when they're ready.

Thankfully I've changed jobs and don't have to deal with that mess of a process anymore though. :)

OTHER TIPS

You may be able to use some kind of tool to generate a diff of two databases. There's a question on that here.

If you diff your test database with your development database just after running the migration that would probably be the easiest way. It might even be worth adding a rake task to do it; get that rake task to depend on the migration and then you could use the new task instead of rake db:migrate to generate a diff each time you migrate.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top