Daniel Berger
unread,Sep 17, 2009, 11:00:10 AM9/17/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Oracle enhanced adapter for ActiveRecord
Hi,
I noticed that neither db:schema:dump nor db:structure:dump included
triggers in the dump. That got me thinking of a generic way to create
a trigger in a migration. I tried to come up with some syntax that I
thought might be reasonably cross platform. What do you think of
something like this?
# Based on example from Oracle 9i, The Complete Reference, p. 513
create_trigger(:name => 'bookshelf_bef_upd_row', :force => true) do |
t|
t.before => 'update'
t.on => 'bookshelf'
t.condition => 'new.rating < old.rating'
t.execute => %Q{
insert into bookshelf_audit
(title, publisher, categoryname, old_rating, new_rating,
audit_date)
values
(:old.title, :old.publisher, :old.category_name, :old.rating, :new.rating,
sysdate)
}
end
create_trigger could take 2 options, the 'name' and a 'force' option.
It would yield a trigger object, which would respond to the following
methods:
# These would accept 'insert', 'update' and 'delete', or any
combination of them
before
after
instead_of
# The table name
on
# The 'when' clause
condition
# The call procedure
execute
How does something like that look? And would it be of any interest to
you?
Regards,
Dan