# Verbose Migrations (plugin)

**URL:** <https://www.ruby-forum.com/t/verbose-migrations-plugin/48297>\
**Category:** Rails\
**Created:** [November 18, 2005, 5:43pm UTC](https://www.ruby-forum.com/t/verbose-migrations-plugin/48297 "2005-11-18T17:43:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f17d59/32.png) [@jamis](https://www.ruby-forum.com/u/jamis)\
**Post date:** [November 18, 2005, 5:43pm UTC](https://www.ruby-forum.com/t/verbose-migrations-plugin/48297/1 "2005-11-18T17:43:36Z")

</div>

## DESCRIPTION

Verbose Migrations is a plugin that causes migrations to report what  
they are doing, verbosely, to the console. By default, each migration  
will report it’s name, and whether it is being migrated (up) or  
reverted (down). Also, each method missing call will be reported,  
with the name and arguments, so that things like create\_table and  
add\_index are printed.

Benchmarks are also displayed, showing how long each operation took.

You can use the “say” method to report your own events, such as if  
you are manipulating data directly using your own model classes:

say “migrating data”  
Finances.update\_all “amount=0”, “account\_id=7”

If you want to also show the benchmark for a custom event like this,  
you can use “say\_with\_time”:

say\_with\_time “migrating data” do  
Finances.update\_all “amount=0”, “account\_id=7”  
end

The output looks something like this:

# == NormalizeLineItems: migrating

# – create\_table(:account\_line\_items) → 0.0091s – add\_index(:account\_line\_items, :financial\_transaction\_id) → 0.0054s – add\_index(:account\_line\_items, :account\_id) → 0.0049s – create\_table(:budget\_line\_items) → 0.0064s – add\_index(:budget\_line\_items, :financial\_transaction\_id) → 0.0057s – add\_index(:budget\_line\_items, :budget\_id) → 0.0195s – migrate line items to budget and account line items → 0.0059s – drop\_table(:line\_items) → 0.0053s == NormalizeLineItems: migrated (0.0717s)

## INSTALLATION

script/plugin source [http://svn.jamisbuck.org/rails-plugins/](http://svn.jamisbuck.org/rails-plugins/)  
script/plugin install verbose\_migrations

---

<div class="post-metadata">

**Author:** ![jamis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f17d59/32.png) [@jamis](https://www.ruby-forum.com/u/jamis)\
**Post date:** [November 18, 2005, 8:02pm UTC](https://www.ruby-forum.com/t/verbose-migrations-plugin/48297/2 "2005-11-18T20:02:37Z")

</div>

On Nov 18, 2005, at 11:44 AM, Blair Z. wrote:

> Jamis,  
> ALTER TABLE post  
> -\> 0.0087s  
> That’s a good idea, though I don’t think it’s as straightforward as  
> just removing whitespace. How should, for instance, whitespace in  
> string literals be handled?

execute \<\<-SQL  
UPDATE somethings  
SET foo = ‘first second third’  
WHERE id=5  
SQL

Would it be sufficient to just do

str.sub(/^\s\*/, “”).sub(/\s\*$/, “”).gsub(/[\r\n]\s\*/, " ")

?

- Jamis

---

<div class="post-metadata">

**Author:** ![jamis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f17d59/32.png) [@jamis](https://www.ruby-forum.com/u/jamis)\
**Post date:** [November 18, 2005, 7:47pm UTC](https://www.ruby-forum.com/t/verbose-migrations-plugin/48297/3 "2005-11-18T19:47:32Z")

</div>

Jamis B. wrote:

> ## DESCRIPTION
> 
> Verbose Migrations is a plugin that causes migrations to report what  
> they are doing, verbosely, to the console. By default, each migration  
> will report it’s name, and whether it is being migrated (up) or  
> reverted (down). Also, each method missing call will be reported, with  
> the name and arguments, so that things like create\_table and add\_index  
> are printed.

Jamis,

Ahh, this is perfect! Just what I was looking for.

Could the logging of the execute task clean up the SQL to remove  
leading,  
trailing and embedded whitespace?

I have this in my migration’s up method to have it look nice (and fit in  
my  
standard 80 character wide ssh terminal):

```
 execute <<-SQL
   ALTER TABLE post
     ADD CONSTRAINT fk_post_pk_author
       FOREIGN KEY (pk_author)
       REFERENCES author(pk_author)
 SQL

```

This ends up looking like

– execute(" ALTER TABLE post\n ADD CONSTRAINT  
fk\_post\_pk\_author\n  
FOREIGN KEY (pk\_author)\n REFERENCES  
author(pk\_author)\n")  
-\> 0.0087s

Regards,  
Blair

---

<div class="post-metadata">

**Author:** ![jamis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f17d59/32.png) [@jamis](https://www.ruby-forum.com/u/jamis)\
**Post date:** [November 18, 2005, 8:17pm UTC](https://www.ruby-forum.com/t/verbose-migrations-plugin/48297/4 "2005-11-18T20:17:44Z")

</div>

Jamis B. wrote:

> That’s a good idea, though I don’t think it’s as straightforward as  
> just removing whitespace. How should, for instance, whitespace in  
> string literals be handled?

Agreed. You’d have to parse the SQL.

> execute \<\<-SQL  
> UPDATE somethings  
> SET foo = ‘first second third’  
> WHERE id=5  
> SQL
> 
> Would it be sufficient to just do
> 
> str.sub(/^\s\*/, “”).sub(/\s\*$/, “”).gsub(/[\r\n]\s\*/, " ")

Yes, that would work.

Maybe to be safe, in case people insert text in their migrations which  
have  
[\r\n], is just to trim the leading and trailing whitespace.

The other solution is to have an execute\_compress\_whitespace or  
something named  
like that function that people can use that can sub(/\s{2,}/, “”).

Regards,  
Blair
