This spec describes a database schema that has been introduced with the Lyons release. This model allows storage and optimized retrieval of resources with support for hierarchies, change tracking, metadata (with revisioning), and content independence.
The pre-Lyons storage model for pages and attachments have significant drawbacks that limit the introduction of new features while hampering existing functionality of attachments and change tracking. Although MediaWiki's data model has since evolved and improved, Deki inherited many of the problems by forking from an older release. This model removes the workarounds that stemmed from limitations imposed by MySql 4.x as well as introducing concepts better suited for Deki's use cases.
The design of the new model is driven by the need to address known issues in the pre-Lyons model, as well as meeting requirements for the architectural vision.
Know Issues
Design Desiderata
The resources table contains aggregate information such as the type of resource, whether or not it's currently deleted, when it was created, and the current head revision. It also contains a mirror of the head revision for the resource in the resourcerevs table. Note that unlike Deki's and MediaWiki's 'old' table, the resourcerevs table contains the head revision as well. This data duplication exists to simplify and optimize for the majority of queries where only the current version of the resource is relevant. Other than representing the current state of the resource, this table describes aspects of the resource that are revision-independent such as the type of resource.
| Column | Type | Default | Description |
| res_id | int(4) unsigned NOT NULL | auto_increment | primary key |
| res_headrev | int(4) NOT NULL | current revision number of head | |
| res_type | tinyint(1) unsigned NOT NULL | 0 | type of resource 0: undefined 2: file 4: property |
| res_deleted | tinyint(1) unsigned NOT NULL | 0 | whether or not the resource is currently marked as removed |
| res_create_timestamp | datetime NOT NULL | 0001-01-01 00:00:00 | timestamp when the first revision was created |
| res_update_timestamp | datetime NOT NULL | 0001-01-01 00:00:00 | timestamp of the current head revision (same as resrev_timestamp) |
| res_create_user_id | int(4) unsigned NOT NULL | 0 | user id of who created the first revision |
| res_update_user_id | int(4) unsigned NOT NULL | 0 | user id of who created the head revision (same as resrev_user_id) |
| resrev_rev | int(4) NOT NULL | (copy of head revision row, see description below) | |
| resrev_user_id | int(4) unsigned NOT NULL | (copy of head revision row, see description below) | |
| resrev_parent_id | int(4) unsigned NOT NULL | (copy of head revision row, see description below) | |
| resrev_parent_page_id | int(4) unsigned | NULL | (copy of head revision row, see description below) |
| resrev_parent_user_id | int(4) unsigned | NULL | (copy of head revision row, see description below) |
| resrev_change_mask | tinyint(1) unsigned NOT NULL | 0 | (copy of head revision row, see description below) |
| resrev_name | varchar(255) NOT NULL | '' (empty string) | (copy of head revision row, see description below) |
| resrev_change_description | varchar(255) | NULL | (copy of head revision row, see description below) |
| resrev_timestamp | datetime NOT NULL | 0001-01-01 00:00:00 | (copy of head revision row, see description below) |
| resrev_content_id | int(4) unsigned NOT NULL | 0 | (copy of head revision row, see description below) |
| resrev_deleted | tinyint(1) unsigned NOT NULL | 0 | (copy of head revision row, see description below) |
| resrev_changeset_id | int(4) unsigned NOT NULL | 0 | (copy of head revision row, see description below) |
| resrev_size | int(4) unsigned NOT NULL | 0 | content size in bytes |
| resrev_mimetype | varchar(255) NOT NULL | '' (empty string) | (copy of head revision row, see description below) |
| resrev_language | varchar(255) | NULL | (copy of head revision row, see description below) |
| resrev_meta | text | NULL | (copy of head revision row, see description below) |
Primary: res_id
Secondary:
The resourcerevs (resource revisions) table contains information about all revisions of all resources. Revisions of a given resource are related by the resource id.
| Column | Type | Default | Description |
| resrev_id | int(4) unsigned NOT NULL | auto_increment | primary key |
| resrev_res_id | int(4) unsigned NOT NULL | 0 | resource id that revision applies to; foreign key into resources table |
| resrev_rev | int(4) NOT NULL | 0 | revision number; starts at 1 and increments by 1; unique per resrev_res_id |
| resrev_user_id | int(4) unsigned NOT NULL | 0 | user who performed the change that caused the revision creation |
| resrev_parent_id | int(4) unsigned NOT NULL | 0 | parent resource id |
| resrev_parent_page_id | int(4) unsigned | NULL | parent page id; used by resources associated with a page (this column will be dropped as pages are migrated) |
| resrev_parent_user_id | int(4) unsigned | NULL | parent user id; used by resources associated with a user such as properties |
| resrev_change_mask | tinyint(1) unsigned NOT NULL | 0 | bitfield describing which columns were changed: 0: none 1: content 2: name 4: language 8: meta 16: deleteflag 32: parent |
| resrev_name | varchar(255) NOT NULL | '' (empty string) | the name of the resource, such as filename or property key |
| resrev_change_description | varchar(255) | NULL | human readable description of operation that created this revision |
| resrev_timestamp | datetime NOT NULL | 0001-01-01 00:00:00 | timestamp when revision was created |
| resrev_content_id | int(4) unsigned NOT NULL | 0 | foreign key to resourcecontents table |
| resrev_deleted | tinyint(1) unsigned NOT NULL | 0 | whether or not this resource is marked as deleted |
| resrev_changeset_id | int(4) unsigned NOT NULL | 0 | foreign key to change-set which groups up multiple specific changes for an operation |
| resrev_size | int(4) unsigned NOT NULL | 0 | content size in bytes |
| resrev_mimetype | varchar(255) NOT NULL | '' (empty string) | content MIME type |
| resrev_language | varchar(255) | NULL | language code following standard language-culture convention |
| resrev_meta | text | NULL | xml describing custom generated attributes for the revision such as attachment image width/height |
Primary: resrev_id
Unique: resid_rev, (resrev_res_id, resrev_rev)
The resource contents table stores either the content for a resources revision or a description for how to get to it outside of the db.
| Column | Type | Default | Description |
| rescontent_id | int(4) unsigned NOT NULL | auto_increment | primary key |
| rescontent_res_id | int(4) unsigned | NULL | resource id that content applies to; foreign key into resources table |
| rescontent_res_rev | smallint(2) unsigned | NULL | revision number when content was added |
| rescontent_value | mediumblob | binary resource contents; empty when rescontent_location is used | |
| rescontent_mimetype | varchar(255) NOT NULL | '' (empty string) | content MIME type |
| rescontent_location | varchar(255) | NULL | content location; NULL when rescontent_value is used |
| rescontent_size | int(4) unsigned NOT NULL | 0 | content size in bytes when known, otherwise NULL |
Primary: rescontent_id
Unique: rescontent_res_id, (rescontent_res_id, rescontent_res_rev)
A resource is marked as deleted with the res_deleted flag being set to 1. If a resource is deleted the only valid next revision would be to restore the resource. This allows the assumption that if the resource is marked as deleted, it's always the current head revision that performed the deletion and the user id and timestamp of the deletion are stored within that head revision.
Currently permissions are coupled with pages in two ways. Grants (user and group) reference pageids and restrictions are stored in the page table as a restrictionid. As part of the page migration, restrictions shouldn't be migrated into resources schema but should instead become auxiliary. Keeping permissions outside of resources would have a number of benefits
Statistics tracking of pages is currently done in the pages table. This also needs to be decoupled into its own tables for most of the same reasons as permissions.
Deficiencies of current design:
Benefits of current design:
Desiderata:
Proposed title table columns: (very work in progress)
Resources has a title_id foreign key.
Redirect point to resources with the title_redirect_to_resource_id column.
Title table is only updated for redirects otherwise no entries are ever removed or updated.
TODO: Look at other name resolution mechanisms such as XRDS for inspiration.
| Images 0 | ||
|---|---|---|
| No images to display in the gallery. |
Copyright © 2011 MindTouch, Inc. Powered by