procession/procession — pull request #15 by jaypipes (2014-01-25 03:36:09+00:00)
Title: Add sharded organization model using nested sets

The world-view of Procession is divided into Organizations,
Users, and Groups. Organizations are simply containers for Users
Organizations. Groups are containers for Users within an
Organization that are used for simple categorization of Users. Groups have
a set of Roles associated with them, and Roles are used to indicate
the permissions that Users in the Group having that Role are assigned.

Organizations that have no parent Organization are known as Root
Organizations. Each Organization has attributes for both a Parent
Organization as well as the Root Organization to which the
Organization belongs. This allows us to use both an adjacency list model for
quick immediate ancestor and immediate descendant queries, as well as a nested
sets model for more complex queries involving multiple levels of the
Organization hierarchy.

We use multiple Root Organizations in order to minimize the impact of
updates to the Organization hierarchy. Since updating a nested sets
model is expensive -- since every node in the hierarchy must be updated to
change the left and right side pointer values -- dividing the whole
Organization hierarchy into multiple roots allows us to have a nested
set model per Root Organization, which limits updates to just the
Organizations within a Root Organization. If we used a single-root tree, with all
Organizations descendents from a single Organization with no parent, then
each addition or removal of an Organization would result in the need to
update every record in the organizations table.