# migrations: getting SQL output only?

**URL:** <https://discuss.rubyonrails.org/t/migrations-getting-sql-output-only/811>\
**Category:** rubyonrails-talk\
**Created:** [August 30, 2006, 8:51pm UTC](https://discuss.rubyonrails.org/t/migrations-getting-sql-output-only/811 "2006-08-30T20:51:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Van\_Holstyn1](https://avatars.discourse-cdn.com/v4/letter/m/c6cbf5/32.png) [@Mark\_Van\_Holstyn1](https://discuss.rubyonrails.org/u/Mark_Van_Holstyn1)\
**Post date:** [August 30, 2006, 8:51pm UTC](https://discuss.rubyonrails.org/t/migrations-getting-sql-output-only/811/1 "2006-08-30T20:51:29Z")

</div>

Check out this…

[http://www.agilewebdevelopment.com/plugins/activerecord\_io\_mode\_plugin](http://www.agilewebdevelopment.com/plugins/activerecord_io_mode_plugin)

I think that should help you…

Mark

---

<div class="post-metadata">

**Author:** ![Mark\_Van\_Holstyn1](https://avatars.discourse-cdn.com/v4/letter/m/c6cbf5/32.png) [@Mark\_Van\_Holstyn1](https://discuss.rubyonrails.org/u/Mark_Van_Holstyn1)\
**Post date:** [August 30, 2006, 11:38pm UTC](https://discuss.rubyonrails.org/t/migrations-getting-sql-output-only/811/2 "2006-08-30T23:38:36Z")

</div>

> This looks like it is generally useful in certain cases, but would probably be very difficult to implement for my needs. If I understand
> 
> the little synopsis correctly, I would have to modify every call to an activerecord object that generates a database query.

Not true, all you need to do is…

output\_sql =

ActiveRecord:: Base.send\_sql\_to output\_sql #do all the migrations

Now the array output\_sql will have all the generated sql in it, and nothing will have hit the db. In fact, you can also make output\_sql a file instead of an array. You just need to put this at the begining of the the migrations. Let me know if you need a more concrete example and ill see what i can get together tonight.

mark

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://discuss.rubyonrails.org/u/Dick_Davies)\
**Post date:** [August 31, 2006, 7:18am UTC](https://discuss.rubyonrails.org/t/migrations-getting-sql-output-only/811/3 "2006-08-31T07:18:05Z")

</div>

Not entirely what you're asking for, but I'm about to write a rails backend ui to manage a database used by a mod\_perl frontend. mod\_perl relies on a load of constraints, grants, etc that are hard to capture with migrations.

I found Robbys page on using raw SQL in migrations to be a good match for what I need:

[http://www.robbyonrails.com:8680/articles/2005/11/11/rails-migrations-and-postgresql-constraints](http://www.robbyonrails.com:8680/articles/2005/11/11/rails-migrations-and-postgresql-constraints)

You'd still need ruby and activerecord, but that's not a big deal in my case.
