Saturday, July 30, 2011

surrogate key question

A bit of design first.

We need to track a document through finite lifetimes. The document has a
legal validity pertaining to real world events which occurred during
such lifetimes. That "same" document gets revised/replaced every so
often or even arbitrarily if an improvement is made.

The system always needs to offer the current document but previous
versions must remain in existence. Previous versions are tagged with
review dates which signify current validity. In theory they should be
replaced with a new version of the "same" document but that might not
happen and it might stay current but be out-of-date. Not desirable but
that's life.

Documents are computed from their various attibutes and downloaded or
displayed as pdf files. These get cached for the future and also for the
past if a previous version is required.

New documents can inherit attributes of other documents. This is a
no-brainer for the next revision of the same document but similar
documents can share some of the exact same attributes.

Now the question.

For me, it sort of makes sense to give an original document a surrogate
key (maybe "ancestor_id") in addition to its primary key. Ancestor_id
would be used to link all its attributes. Then if another document is
created, say the next revision, despite having its own primary key it
gets the same ancestor_id to get the same linked attibutes. Obviously it
would also have some of its own attributes such as revision date and so on.

The ancestor_id would have to be assigned from somewhere. I did think I
could copy the primary key for a document being created from scratch
rather than one starting life as a descendant. Otherwise I would need a
separate number table in the database from which fresh numbers could be
plucked. The value of ancestor_id would have no business significance.

Is this a sane way to travel given the django ORM?

Thanks

Mike

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment