views:

456

answers:

1

Is there a way to create mysql triggers using Activerecord migrations ? Has anybody worked on it share your experience . Thanks

+3  A: 

There's no magic method allowing you to create a trigger without writing any SQL.
But you can execute raw sql inside any migration.

def self.up
    execute <<-SQL
        CREATE TRIGGER my_trigger ...
    SQL
end

Then you just need to appropriately write your trigger or update it depending of the migration.

Edit : I've just found rails_on_pg, which provides some helpers to migrations.
It doesn't work with any other database server than PgSQL. But it can be a good lead if you're up to writing some MySQL triggering helper.

Damien MATHIEU
Thanks , for your resource , i wasn't knowing that it did exists :)
YetAnotherCoder