Ben Swinburne
Ben Swinburne

Reputation: 26467

Database row snapshots/revisions

I am looking for a suitable process by which to keep revisions, or snapshots of rows (and their relations) in a database.

Take for example an eCommerce platform-

I have looked at a few concepts, one being duplicate tables, another being temporal databases, and the other being keeping a revision id and active flag.

Whilst I appreciate no one can really tell me the best/most suitable solution for my application as it's a matter open to opinion etc, I was hoping that someone might be able to demonstrate the advantages/disadvantages possibly by way of comparison. I have read lots of questions on SO, and a fair few articles on the various implementations, but none really compare each idea or indicate where they'd be best suited. Below I have outlined my understanding of each of the concepts.

Duplicate tables

Store the information in rows relevant to the data with which they need to be snapshot with. I.e. Keep an address in columns in the orders table of an online store.

Advantages

Disadvantages

Temporal Databases/Active or Current row flag

Database rows which are "time-aware", i.e. their context is the time between two datetimes. Data can be joined where it's time context lies between that of the temporal table.

Advantages

Disadvantages

Storing just the changed column, temporal.

Have a table which keeps track of changes to all tables and note the row it relates to and when it is valid in terms of time.

Advantages

Disadvantages

I have already looked at the following questions here on SO, and these other resources

Edit: The reason I haven't tagged this post with a particular DBMS as I'd like the concept to work with as many as possible ideally as the platform, at present is DBMS independent and the abstraction layer allows it to work with MySQL and MSSQL but will hopefully support others in the future.

Upvotes: 9

Views: 1575

Answers (2)

Ben Swinburne
Ben Swinburne

Reputation: 26467

I ended up using a temporal database, and the implementation of this resulted in the Temporal Model in FuelPHP.

I can now configure my models to treat rows as a time sensitive entity. Changes cause a new row to be created and the end time of the original row set accordingly.

This allows me to retrieve a row at a point in time.

Upvotes: 1

Robbie Dee
Robbie Dee

Reputation: 1977

There is another option (on Oracle at least) where you can just set the point in time and run whatever queries you like.

I believe it works using large amounts of flash recovery space but if you're only interested in tracking a few tables this might be overkill.

Upvotes: 0

Related Questions