alex3t / rails_on_pg

PostgreSQL views, functions, triggers, foreign keys for rails migration
146 stars 15 forks source link

create language plpgsql statement error causes migration fail #1

Open gonzoyumo opened 14 years ago

gonzoyumo commented 14 years ago

Hi, first, thanks for giving us this nice plugin ! I'm using rails_on_pg in my project and I run into this issue when I try a migration :

When I want to add a funcion, rails_on_pg automatically add a "CREATE LANGUAGE plpgsql" statement before. But if this language has already been created (e.g : by another create_function call before this one), I get an ActiveRecord::StatementInvalid wich cause the transaction to rollback when running rake db:migrate. Though the plugin uses rescue ActiveRecord::StatementInvalid when executing this create language statement.

Note that while using rake db:setup (which is 'db:create', 'db:schema:load', 'db:seed') we don't have the problem since the StatementInvalid is catched in the rescue in this case.

I'm not so familiar with rails migration mechanism so I'm stuck after reaching this point in debugging :/

I put a sample project to test this behavior here : http://github.com/gonzoyumo/rails_on_pg_test Complete workflow explained in the readme.

I will appreciate your help to solve this issue.

gonzoyumo.

gonzoyumo commented 14 years ago

here is a temporary patch (method taken from http://wiki.postgresql.org/wiki/CREATE_OR_REPLACE_LANGUAGE)

http://gist.github.com/335115

but still need to understand why it breaks with rake db:migrate and not with rake db:setup :/