1

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.

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

the diff should be done on table structure for every table, and data for schema_migrations since you want to have the migrations in this table.
1

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. :)

2 Comments

I'm in the same situation as you were. Did you ever open source this solution?
I did not. And I don't have the computer housing that code with me. However, with a small bit of research, you can easily do the same. I don't remember too well, but I may have looked at this answer to another SO question: stackoverflow.com/a/1629474/241367. And I may have looked at the link he provided: misuse.org/science/2006/12/12/sql-logging-in-rails. I did not implement everything the misuse.org article had in its code snippet. YMMV, hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.