| | @@ -0,0 +1,223 @@ |
| 1 | +## -*- tcl -*-
|
| 2 | +# # ## ### ##### ######## ############# #####################
|
| 3 | +## Copyright (c) 2008 Mark Janssen.
|
| 4 | +#
|
| 5 | +# This software is licensed as described in the file LICENSE, which
|
| 6 | +# you should have received as part of this distribution.
|
| 7 | +#
|
| 8 | +# This software consists of voluntary contributions made by many
|
| 9 | +# individuals. For exact contribution history, see the revision
|
| 10 | +# history and logs, available at http://fossil-scm.hwaci.com/fossil
|
| 11 | +# # ## ### ##### ######## ############# #####################
|
| 12 | +
|
| 13 | +## Repository schema's
|
| 14 | +
|
| 15 | +# # ## ### ##### ######## ############# #####################
|
| 16 | +## Requirements
|
| 17 | +
|
| 18 | +package require Tcl 8.5 ; # Required runtime.
|
| 19 | +package require snit ; # OO system.
|
| 20 | +
|
| 21 | +package provide vc::fossil::schema 1.0
|
| 22 | +
|
| 23 | +# # ## ### ##### ######## ############# #####################
|
| 24 | +##
|
| 25 | +
|
| 26 | +
|
| 27 | +
|
| 28 | +namespace eval ::vc::fossil {
|
| 29 | +
|
| 30 | + snit::type schema {
|
| 31 | + typemethod repo1 {} {
|
| 32 | + return {
|
| 33 | + -- The BLOB and DELTA tables contain all records held in the repository.
|
| 34 | + --
|
| 35 | + -- The BLOB.CONTENT column is always compressed using libz. This
|
| 36 | + -- column might hold the full text of the record or it might hold
|
| 37 | + -- a delta that is able to reconstruct the record from some other
|
| 38 | + -- record. If BLOB.CONTENT holds a delta, then a DELTA table entry
|
| 39 | + -- will exist for the record and that entry will point to another
|
| 40 | + -- entry that holds the source of the delta. Deltas can be chained.
|
| 41 | + --
|
| 42 | + CREATE TABLE blob(
|
| 43 | + rid INTEGER PRIMARY KEY, -- Record ID
|
| 44 | + rcvid INTEGER, -- Origin of this record
|
| 45 | + size INTEGER, -- Size of content. -1 for a phantom.
|
| 46 | + uuid TEXT UNIQUE, -- SHA1 hash of the content
|
| 47 | + content BLOB -- Compressed content of this record
|
| 48 | + );
|
| 49 | + CREATE TABLE delta(
|
| 50 | + rid INTEGER PRIMARY KEY, -- Record ID
|
| 51 | + srcid INTEGER NOT NULL REFERENCES blob -- Record holding source document
|
| 52 | + );
|
| 53 | + CREATE INDEX delta_i1 ON delta(srcid);
|
| 54 | +
|
| 55 | + -- Whenever new blobs are received into the repository, an entry
|
| 56 | + -- in this table records the source of the blob.
|
| 57 | + --
|
| 58 | + CREATE TABLE rcvfrom(
|
| 59 | + rcvid INTEGER PRIMARY KEY, -- Received-From ID
|
| 60 | + uid INTEGER REFERENCES user, -- User login
|
| 61 | + mtime DATETIME, -- Time or receipt
|
| 62 | + nonce TEXT UNIQUE, -- Nonce used for login
|
| 63 | + ipaddr TEXT -- Remote IP address. NULL for direct.
|
| 64 | + );
|
| 65 | +
|
| 66 | + -- Information about users
|
| 67 | + --
|
| 68 | + CREATE TABLE user(
|
| 69 | + uid INTEGER PRIMARY KEY, -- User ID
|
| 70 | + login TEXT, -- login name of the user
|
| 71 | + pw TEXT, -- password
|
| 72 | + cap TEXT, -- Capabilities of this user
|
| 73 | + cookie TEXT, -- WWW login cookie
|
| 74 | + ipaddr TEXT, -- IP address for which cookie is valid
|
| 75 | + cexpire DATETIME, -- Time when cookie expires
|
| 76 | + info TEXT, -- contact information
|
| 77 | + photo BLOB -- JPEG image of this user
|
| 78 | + );
|
| 79 | +
|
| 80 | + -- The VAR table holds miscellanous information about the repository.
|
| 81 | + -- in the form of name-value pairs.
|
| 82 | + --
|
| 83 | + CREATE TABLE config(
|
| 84 | + name TEXT PRIMARY KEY NOT NULL, -- Primary name of the entry
|
| 85 | + value CLOB, -- Content of the named parameter
|
| 86 | + CHECK( typeof(name)='text' AND length(name)>=1 )
|
| 87 | + );
|
| 88 | +
|
| 89 | + -- Artifacts that should not be processed are identified in the
|
| 90 | + -- "shun" table. Artifacts that are control-file forgeries or
|
| 91 | + -- spam can be shunned in order to prevent them from contaminating
|
| 92 | + -- the repository.
|
| 93 | + --
|
| 94 | + CREATE TABLE shun(uuid UNIQUE);
|
| 95 | +
|
| 96 | + -- An entry in this table describes a database query that generates a
|
| 97 | + -- table of tickets.
|
| 98 | + --
|
| 99 | + CREATE TABLE reportfmt(
|
| 100 | + rn integer primary key, -- Report number
|
| 101 | + owner text, -- Owner of this report format (not used)
|
| 102 | + title text, -- Title of this report
|
| 103 | + cols text, -- A color-key specification
|
| 104 | + sqlcode text -- An SQL SELECT statement for this report
|
| 105 | + );
|
| 106 | + }
|
| 107 | + }
|
| 108 | + typemethod repo2 {} {
|
| 109 | + return {
|
| 110 | + -- Filenames
|
| 111 | + --
|
| 112 | + CREATE TABLE filename(
|
| 113 | + fnid INTEGER PRIMARY KEY, -- Filename ID
|
| 114 | + name TEXT UNIQUE -- Name of file page
|
| 115 | + );
|
| 116 | +
|
| 117 | + -- Linkages between manifests, files created by that manifest, and
|
| 118 | + -- the names of those files.
|
| 119 | + --
|
| 120 | + -- pid==0 if the file is added by check-in mid.
|
| 121 | + -- fid==0 if the file is removed by check-in mid.
|
| 122 | + --
|
| 123 | + CREATE TABLE mlink(
|
| 124 | + mid INTEGER REFERENCES blob, -- Manifest ID where change occurs
|
| 125 | + pid INTEGER REFERENCES blob, -- File ID in parent manifest
|
| 126 | + fid INTEGER REFERENCES blob, -- Changed file ID in this manifest
|
| 127 | + fnid INTEGER REFERENCES filename -- Name of the file
|
| 128 | + );
|
| 129 | + CREATE INDEX mlink_i1 ON mlink(mid);
|
| 130 | + CREATE INDEX mlink_i2 ON mlink(fnid);
|
| 131 | + CREATE INDEX mlink_i3 ON mlink(fid);
|
| 132 | + CREATE INDEX mlink_i4 ON mlink(pid);
|
| 133 | +
|
| 134 | + -- Parent/child linkages
|
| 135 | + --
|
| 136 | + CREATE TABLE plink(
|
| 137 | + pid INTEGER REFERENCES blob, -- Parent manifest
|
| 138 | + cid INTEGER REFERENCES blob, -- Child manifest
|
| 139 | + isprim BOOLEAN, -- pid is the primary parent of cid
|
| 140 | + mtime DATETIME, -- the date/time stamp on cid
|
| 141 | + UNIQUE(pid, cid)
|
| 142 | + );
|
| 143 | + CREATE INDEX plink_i2 ON plink(cid);
|
| 144 | +
|
| 145 | + -- Events used to generate a timeline
|
| 146 | + --
|
| 147 | + CREATE TABLE event(
|
| 148 | + type TEXT, -- Type of event
|
| 149 | + mtime DATETIME, -- Date and time when the event occurs
|
| 150 | + objid INTEGER PRIMARY KEY, -- Associated record ID
|
| 151 | + uid INTEGER REFERENCES user, -- User who caused the event
|
| 152 | + bgcolor TEXT, -- Color set by 'bgcolor' property
|
| 153 | + brbgcolor TEXT, -- Color set by 'br-bgcolor' property
|
| 154 | + euser TEXT, -- User set by 'user' property
|
| 155 | + user TEXT, -- Name of the user
|
| 156 | + ecomment TEXT, -- Comment set by 'comment' property
|
| 157 | + comment TEXT -- Comment describing the event
|
| 158 | + );
|
| 159 | + CREATE INDEX event_i1 ON event(mtime);
|
| 160 | +
|
| 161 | + -- A record of phantoms. A phantom is a record for which we know the
|
| 162 | + -- UUID but we do not (yet) know the file content.
|
| 163 | + --
|
| 164 | + CREATE TABLE phantom(
|
| 165 | + rid INTEGER PRIMARY KEY -- Record ID of the phantom
|
| 166 | + );
|
| 167 | +
|
| 168 | + -- Unclustered records. An unclustered record is a record (including
|
| 169 | + -- a cluster records themselves) that is not mentioned by some other
|
| 170 | + -- cluster.
|
| 171 | + --
|
| 172 | + -- Phantoms are usually included in the unclustered table. A new cluster
|
| 173 | + -- will never be created that contains a phantom. But another repository
|
| 174 | + -- might send us a cluster that contains entries that are phantoms to
|
| 175 | + -- us.
|
| 176 | + --
|
| 177 | + CREATE TABLE unclustered(
|
| 178 | + rid INTEGER PRIMARY KEY -- Record ID of the unclustered file
|
| 179 | + );
|
| 180 | +
|
| 181 | + -- Records which have never been pushed to another server. This is
|
| 182 | + -- used to reduce push operations to a single HTTP request in the
|
| 183 | + -- common case when one repository only talks to a single server.
|
| 184 | + --
|
| 185 | + CREATE TABLE unsent(
|
| 186 | + rid INTEGER PRIMARY KEY -- Record ID of the phantom
|
| 187 | + );
|
| 188 | +
|
| 189 | + -- Each baseline or manifest can have one or more tags. A tag
|
| 190 | + -- is defined by a row in the next table.
|
| 191 | + --
|
| 192 | + -- Wiki pages are tagged with "wiki-NAME" where NAME is the name of
|
| 193 | + -- the wiki page. Tickets changes are tagged with "ticket-UUID" where
|
| 194 | + -- UUID is the indentifier of the ticket.
|
| 195 | + --
|
| 196 | + CREATE TABLE tag(
|
| 197 | + tagid INTEGER PRIMARY KEY, -- Numeric tag ID
|
| 198 | + tagname TEXT UNIQUE -- Tag name.
|
| 199 | + );
|
| 200 | + INSERT INTO tag VALUES(1, 'bgcolor'); -- TAG_BGCOLOR
|
| 201 | + INSERT INTO tag VALUES(2, 'comment'); -- TAG_COMMENT
|
| 202 | + INSERT INTO tag VALUES(3, 'user'); -- TAG_USER
|
| 203 | + INSERT INTO tag VALUES(4, 'hidden'); -- TAG_HIDDEN
|
| 204 | +
|
| 205 | + -- Assignments of tags to baselines. Note that we allow tags to
|
| 206 | + -- have values assigned to them. So we are not really dealing with
|
| 207 | + -- tags here. These are really properties. But we are going to
|
| 208 | + -- keep calling them tags because in many cases the value is ignored.
|
| 209 | + --
|
| 210 | + CREATE TABLE tagxref(
|
| 211 | + tagid INTEGER REFERENCES tag, -- The tag that added or removed
|
| 212 | + tagtype INTEGER, -- 0:cancel 1:single 2:branch
|
| 213 | + srcid INTEGER REFERENCES blob, -- Origin of the tag. 0 for propagated tags
|
| 214 | + value TEXT, -- Value of the tag. Might be NULL.
|
| 215 | + mtime TIMESTAMP, -- Time of addition or removal
|
| 216 | + rid INTEGER REFERENCE blob, -- Baseline that tag added/removed from
|
| 217 | + UNIQUE(rid, tagid)
|
| 218 | + );
|
| 219 | + CREATE INDEX tagxref_i1 ON tagxref(tagid, mtime);
|
| 220 | + }
|
| 221 | + }
|
| 222 | + }
|
| 223 | +} |