How to create mysql triggers using migrations in Rails?

activerecord, ruby-on-rails, triggers

Solution

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.

Problem

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

Original source