Mailing List Archive

[bricoleurs/bricolage] ddffd0: Add triggers to prevent desk asset drift.
Branch: refs/heads/master

Commit: ddffd06403d76695ee728529c8b5799887845a8b
Author: David E. Wheeler <>
Date: 2011-10-11 (Tue, 11 Oct 2011)

Changed paths:
M inst/
A inst/upgrade/2.1.0/
M lib/Bric/Admin.pod
M lib/Bric/Biz/Workflow/Parts/
M lib/Bric/Changes.pod
M sql/Pg/Bric/Biz/Asset/Business/Media.con
M sql/Pg/Bric/Biz/Asset/Business/Story.con
M sql/Pg/Bric/Biz/Asset/Template.con

Log Message:
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.

[#272 state:resolved]