Database Design – Handling Draft Versions of Data

database-design

The database I'm currently building is pretty traditional relational database stuff, but there is one requirement that is not clear to me how model appropriately.

There are many business rules which are translated into database consistency checks (i.e. date A must be between date B and C or this field must be not null when another field is a specific value). My problem arises because a user must be able to work on a "draft" version on the data, being allowed to save their changes even if the consistency checks fail.

Eventually, a user can commit their draft, but only once all the consistency checks pass.

The main reason the client wants this functionality is so that they can query the database directly for reports, and be sure that they are using the most recent version of the data that is "consistent", but not restrict the user from entering partial data.

I've played around with storing the changeset to the data in JSON in a document store, and then applying the changeset in code when dealing with the user is dealing with draft data, but this makes it hard to manage things like relationships and the creation/deletion of records.

Is there a common way to accomplish this goal? Or does anyone have any suggestions about how I may approach this problem differently?

Best Answer

This is going to sound crazy but I'd create a separate service that stored the data in another set of tables, but this other set of tables had no integrity checking. The user would do all the partial work there, and when they were ready you could move their data into the checked schema in a single transaction.

Related Topic