If you don't mind changing your database schema and access logic, the easiest way is to extend your database schema:
create table sometext ( id INTEGER PRIMARY KEY, content VARCHAR(4096), previous_version INTEGER )
Then, selecting the current version of something becomes easy (modulo indices on the previous_version column), updating a version becomes easy and building the diff between two versions is a matter of Algorithm::Diff.
Of course, with MySQL, which has problems with accessing reverse indices, this might not be a good solution, and if you're driving a system like Perlmonks from the database, (read) access to the current version is far more often than access to previous versions. Then you might want to consider either partitioning your table so that the current versions all live in the same partition or splitting your table into two tables, sometext and old_sometext, where the current version always lives in sometext. With that approach you lose the ability to have multiple branches though, as you will only have one active version.
If you want version/patch integrity across tables, you will first need atomic commits across tables and you will also need a global version number/commit number that will allow you to cross-reference a selection of "patches" against the database. Svk does that (for text files), and I think it would be good to steal the ideas from it.
If you want magic rollback/versioning without changing your software, I believe there is nothing like that except cranking up your DBI logging, copying the database during the night, and then replaying the logs as you need to move forward. Moving backwards is most likely not possible unless you write an SQL parser that knows how to undo stuff or write your DB emulator, which saves the steps with undo information and thus allows you to "move backwards" in your DBI log.
If you only want the differences between two versions of the database, your best bet is to dump both versions as text and then to run diff over the text files :-).
In reply to Re: Revision control in relational databases
by Corion
in thread Revision control in relational databases
by Your Mother
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |