[CDBI] Re: Record versioning

Edward J. Sabol sabol at alderaan.gsfc.nasa.gov
Tue Mar 14 19:26:33 GMT 2006


> Hello, I'm wondering, does some record versioning scheme exist in
> the Class::DBI world? I mean, say I augment my key with a version
> tag and override update() with some timestamping+insert()... How
> would its API be like? { firstversion(), lastversion(),
> nextversion(), firstversionafter(date), lastversionbefore(date)...}?
> Isn't this sort of thing likely to be useful to wiki-like
> applications? If there isn't such a thing, which would be a sane
> approach to implementing it?

Versioning was just discussed on the mailing list last week. Check the
mailing list archives for the "Transactions between HTTP requests?" thread.
Ryan Tate's posting probably had the most information on how to implement
such a system. Additional discussion to flesh out some of the details would
still be useful, however. The topic would make a great node for the CDBI wiki
cookbook at http://wiki.class-dbi.com/wiki/Cdbi_cookbook (hint, hint!).

I've implemented a versioning system of sorts, but I don't think it's not
quite the same system as what Ryan Tate posted in abovementioned thread. Mine
is probably just a slight variation. My versioning implementation involves a
fair amount of application logic (which, unfortunately is not generic enough
that it would be helpful to share with you) and requires a database with
support for transactions. However, the table schema involves the following
columns:

(a) a record_id column, a sequential key,
(b) a record_date column, which I initialize using a 'before_create'
    trigger to the timestamp of when the object/version was created,
(c) a record_discarded column, which is either null (if the record has not
    been discarded/trashed or superseded by a new version) or a date (the
    timestamp of when the record was discarded),
(d) a record_parent_id column, which is either null or the record_id of the
    previous version of that object.

The advantages of this system are that the simple 'WHERE' clause
"record_discarded is null" gives you the current version of any object (or
all objects). I also have a "parent" method (which you might want to call the
"previous_version" method) in this class which retrieves the record object of
the previous version if record_parent_id is not null. I didn't have a
requirement for such a capability, but, if you wanted to implement a
"next_version" method efficiently, you might want to add a record_child_id
column to the above table schema, for example.

Hope this helps,
Ed




More information about the ClassDBI mailing list