Skip to main content

A versioned domain model framework.

Project description

About

A versioned domain model framework.

The vdm package allows you to ‘version’ your domain model in the same way that source code version control systems such as subversion allow you version your code. In particular, versioned domain model versions a complete model and not just individual domain objects (for more on this distinction see below).

At present the package is provided as an extension to SQLAlchemy and SQLObject (with an extension to Elixir in progress).

Authors

Rufus Pollock <rufus [at] rufuspollock [dot] org>

Conceptual Documentation

A great starting point is Fowler’s Patterns for things that change with time:

<http://www.martinfowler.com/ap2/timeNarrative.html>

In particular Temporal Object:

<http://www.martinfowler.com/ap2/temporalObject.html>

Two possible approaches:

  1. (simpler) Versioned domain objects are versioned independently (like a wiki). This is less of a versioned ‘domain model’ and more of plain versioned domain objects.

  2. (more complex) Have explicit ‘Revision’ object and multiple objects can be changed simultaneously in each revision (atomicity). This is a proper versioned domain model.

Remark: using the first approach it is:

  • Impossible to support versioning of many-to-many links between versioned domain objects.

  • It is impossible to change multiple objects ‘at once’ – that is as part of one atomic change

  • More discussions of limitations can be found in this thread [1] as well as in vdm/elixir/README.txt.

[1]:<http://groups.google.com/group/sqlelixir/browse_thread/thread/50aee902ce3555fb/>

The versioned domain model (vdm) package focuses on supporting the second case (this obviously includes the first one as a subcase) – hence the name.

Full Versioned Domain Model

To encapsulate changing multiple objects at once as well as to facilitate domain object traversal it is necessary to introduce an explicit ‘Revision’ object to represent a single changeset to the domain model.

One also needs to introduce the concept of ‘State’. This allows us to make (some) domain objects stateful, in particular those which are to be versioned (State is necessary to support delete/undelete functionality as well as to implement versioned many-to-many relationships).

For each original domain object that comes versioned we end up with 2 domain objects:

  • The ‘continuity’: the original domain object.

  • The ‘version/revision’ of that domain object.

Often a user will never need to be concerned (explicitly) with the version/revision object as they will just interact with the original domain object, which will, where necessary, ‘proxy’ requests down to the ‘version/revision’.

To give a flavour of all of this here is a pseudo-code example:

# we need a session of some kind to track which objects have been changed
# each session then has a single revision
rev1 = Revision(author='me')
session.revision = rev1
# Book and Author are domain objects which has been made versioned using this library
# typo!
b1 = Book(name='warandpeace', title='War and Peacee')
b2 = Book(name='annakarenina', title='Anna')
b3 = Book(name='warandpeace')
a1 = Author(name='tolstoy')
# this is just shorthand for ending this revision and saving all changes
# this may vary depending on the implementation
rev1.commit()
timestamp1 = rev1.timestamp

# some time later

rev2 = Revision(author='me')
session.revision = rev2
b1 = Book.get(name='warandpeace')
# correct typo
b1.title = 'War and Peace'
# add the author
a1 = Author.get(name='tolstoy')
b1.authors.append(a1)
# duplicate item so delete
b3.delete()
rev2.commit()

# some time even later
rev1 = Revision.get(timestamp=timestamp1)
b1 = Book.get(name='warandpeace')
b1 = b1.get_as_of(rev1)
assert b1.title == 'War and Peacee'
assert b1.authors == []
# etc

Code in Action

To see some real code in action take a look at:

vdm/sqlalchemy/demo.py
vdm/sqlalchemy/demo_test.py

vdm/sqlobject/demo.py
vdm/sqlobject/demo_test.py

The code for elixir, which is not yet fully functional, can be found in:

vdm/elixir/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vdm-0.2.tar.gz (37.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vdm-0.2-py2.5.egg (114.8 kB view details)

Uploaded Egg

File details

Details for the file vdm-0.2.tar.gz.

File metadata

  • Download URL: vdm-0.2.tar.gz
  • Upload date:
  • Size: 37.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for vdm-0.2.tar.gz
Algorithm Hash digest
SHA256 39255c55849f806ba06cccf2d937b16bd7f3b01fd96ca5fb56a43a2cb55d64cf
MD5 147829ba706733973fd607c579247617
BLAKE2b-256 9ae9bc68be8022480319a313cecee9046e6caf6536ce1b4a7de8b9462a148c8e

See more details on using hashes here.

File details

Details for the file vdm-0.2-py2.5.egg.

File metadata

  • Download URL: vdm-0.2-py2.5.egg
  • Upload date:
  • Size: 114.8 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for vdm-0.2-py2.5.egg
Algorithm Hash digest
SHA256 9d231f8e50ff2ebbdfb26a2dbd1b4c23f92d12eae3695f929f4f3b8fead5bde7
MD5 c9f59e00dc26c18fdd217ea3e74817ff
BLAKE2b-256 37da367c973fd1d2b2d5acf22cfb679adf7b2e31f342e9b9b47f234a8d7615f5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page