noreply at github
Oct 11, 2011, 10:13 PM
Post #1 of 1
[bricoleurs/bricolage] ddffd0: Add triggers to prevent desk asset drift.
Author: David E. Wheeler <david [at] justatheory>
Date: 2011-10-11 (Tue, 11 Oct 2011)
Add triggers to prevent desk asset drift.
There are two disconnected places in the databases where the assets on desks
are tracked. One is the `desk__id` column in the `story`, `media`, and
`template` tables. The other is "asset groups." These are kind of nasty, but
necessary in order for permissions to work properly.
Unfortunately, these two sources can drift from one another. So this commit
adds a migration that corrects any existing drift, and then adds triggers
to prevent it in the future. This required a few other changes:
* The installer now installs PL/pgSQL, which is required for the trigger
functions. If the database is created in advance, it must include PL/pgSQL
or the installation will fail.
* Bric::Biz::Workflow::Parts::Desk now has to save its corresponding asset
group before it saves the assets in that group with new IDs. This won't
usually be necessary, since the trigger executes at transaction commmit
time, but tests run under autocommit, and so generated quite a lot of
errors. By making the order of execution a little saner, the errors go away
and all tests pass.
For now, there are no corresponding triggers for MySQL. I *think* MySQL 5 can
do the same thing (or close to it), but I don't have the energy to figure out
how just now.