Hex Artifact Content
Not logged in

Artifact db3fd09f7a989b26be82b24af9e9e93927a0bcc9:

File src/schema.c part of check-in [ac03d43348] - Add the ability to edit check-in dates using control artifacts. Useful if a user does a check-in when their system clock is set incorrectly thus causing an incorrect timestamp to appear on the check-in artifact. You must run "fossil all rebuild" after upgrading to this or any later version of fossil from a prior version. by drh on 2009-08-21 16:25:30.

0000: 2f 2a 0a 2a 2a 20 43 6f 70 79 72 69 67 68 74 20  /*.** Copyright 
0010: 28 63 29 20 32 30 30 37 20 44 2e 20 52 69 63 68  (c) 2007 D. Rich
0020: 61 72 64 20 48 69 70 70 0a 2a 2a 0a 2a 2a 20 54  ard Hipp.**.** T
0030: 68 69 73 20 70 72 6f 67 72 61 6d 20 69 73 20 66  his program is f
0040: 72 65 65 20 73 6f 66 74 77 61 72 65 3b 20 79 6f  ree software; yo
0050: 75 20 63 61 6e 20 72 65 64 69 73 74 72 69 62 75  u can redistribu
0060: 74 65 20 69 74 20 61 6e 64 2f 6f 72 0a 2a 2a 20  te it and/or.** 
0070: 6d 6f 64 69 66 79 20 69 74 20 75 6e 64 65 72 20  modify it under 
0080: 74 68 65 20 74 65 72 6d 73 20 6f 66 20 74 68 65  the terms of the
0090: 20 47 4e 55 20 47 65 6e 65 72 61 6c 20 50 75 62   GNU General Pub
00a0: 6c 69 63 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 76  lic.** License v
00b0: 65 72 73 69 6f 6e 20 32 20 61 73 20 70 75 62 6c  ersion 2 as publ
00c0: 69 73 68 65 64 20 62 79 20 74 68 65 20 46 72 65  ished by the Fre
00d0: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64  e Software Found
00e0: 61 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 68 69  ation..**.** Thi
00f0: 73 20 70 72 6f 67 72 61 6d 20 69 73 20 64 69 73  s program is dis
0100: 74 72 69 62 75 74 65 64 20 69 6e 20 74 68 65 20  tributed in the 
0110: 68 6f 70 65 20 74 68 61 74 20 69 74 20 77 69 6c  hope that it wil
0120: 6c 20 62 65 20 75 73 65 66 75 6c 2c 0a 2a 2a 20  l be useful,.** 
0130: 62 75 74 20 57 49 54 48 4f 55 54 20 41 4e 59 20  but WITHOUT ANY 
0140: 57 41 52 52 41 4e 54 59 3b 20 77 69 74 68 6f 75  WARRANTY; withou
0150: 74 20 65 76 65 6e 20 74 68 65 20 69 6d 70 6c 69  t even the impli
0160: 65 64 20 77 61 72 72 61 6e 74 79 20 6f 66 0a 2a  ed warranty of.*
0170: 2a 20 4d 45 52 43 48 41 4e 54 41 42 49 4c 49 54  * MERCHANTABILIT
0180: 59 20 6f 72 20 46 49 54 4e 45 53 53 20 46 4f 52  Y or FITNESS FOR
0190: 20 41 20 50 41 52 54 49 43 55 4c 41 52 20 50 55   A PARTICULAR PU
01a0: 52 50 4f 53 45 2e 20 20 53 65 65 20 74 68 65 20  RPOSE.  See the 
01b0: 47 4e 55 0a 2a 2a 20 47 65 6e 65 72 61 6c 20 50  GNU.** General P
01c0: 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 20 66 6f  ublic License fo
01d0: 72 20 6d 6f 72 65 20 64 65 74 61 69 6c 73 2e 0a  r more details..
01e0: 2a 2a 20 0a 2a 2a 20 59 6f 75 20 73 68 6f 75 6c  ** .** You shoul
01f0: 64 20 68 61 76 65 20 72 65 63 65 69 76 65 64 20  d have received 
0200: 61 20 63 6f 70 79 20 6f 66 20 74 68 65 20 47 4e  a copy of the GN
0210: 55 20 47 65 6e 65 72 61 6c 20 50 75 62 6c 69 63  U General Public
0220: 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 61 6c 6f 6e  .** License alon
0230: 67 20 77 69 74 68 20 74 68 69 73 20 6c 69 62 72  g with this libr
0240: 61 72 79 3b 20 69 66 20 6e 6f 74 2c 20 77 72 69  ary; if not, wri
0250: 74 65 20 74 6f 20 74 68 65 0a 2a 2a 20 46 72 65  te to the.** Fre
0260: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64  e Software Found
0270: 61 74 69 6f 6e 2c 20 49 6e 63 2e 2c 20 35 39 20  ation, Inc., 59 
0280: 54 65 6d 70 6c 65 20 50 6c 61 63 65 20 2d 20 53  Temple Place - S
0290: 75 69 74 65 20 33 33 30 2c 0a 2a 2a 20 42 6f 73  uite 330,.** Bos
02a0: 74 6f 6e 2c 20 4d 41 20 20 30 32 31 31 31 2d 31  ton, MA  02111-1
02b0: 33 30 37 2c 20 55 53 41 2e 0a 2a 2a 0a 2a 2a 20  307, USA..**.** 
02c0: 41 75 74 68 6f 72 20 63 6f 6e 74 61 63 74 20 69  Author contact i
02d0: 6e 66 6f 72 6d 61 74 69 6f 6e 3a 0a 2a 2a 20 20  nformation:.**  
02e0: 20 64 72 68 40 68 77 61 63 69 2e 63 6f 6d 0a 2a   drh@hwaci.com.*
02f0: 2a 20 20 20 68 74 74 70 3a 2f 2f 77 77 77 2e 68  *   http://www.h
0300: 77 61 63 69 2e 63 6f 6d 2f 64 72 68 2f 0a 2a 2a  waci.com/drh/.**
0310: 0a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  .***************
0320: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0330: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0340: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0350: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0360: 0a 2a 2a 20 0a 2a 2a 20 54 68 69 73 20 66 69 6c  .** .** This fil
0370: 65 20 63 6f 6e 74 61 69 6e 73 20 73 74 72 69 6e  e contains strin
0380: 67 20 63 6f 6e 73 74 61 6e 74 73 20 74 68 61 74  g constants that
0390: 20 69 6d 70 6c 65 6d 65 6e 74 20 74 68 65 20 64   implement the d
03a0: 61 74 61 62 61 73 65 20 73 63 68 65 6d 61 2e 0a  atabase schema..
03b0: 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 22 63 6f 6e  */.#include "con
03c0: 66 69 67 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20  fig.h".#include 
03d0: 22 73 63 68 65 6d 61 2e 68 22 0a 0a 2f 2a 0a 2a  "schema.h"../*.*
03e0: 2a 20 54 68 65 20 64 61 74 61 62 61 73 65 20 73  * The database s
03f0: 63 68 65 6d 61 20 66 6f 72 20 74 68 65 20 7e 2f  chema for the ~/
0400: 2e 66 6f 73 73 69 6c 20 63 6f 6e 66 69 67 75 72  .fossil configur
0410: 61 74 69 6f 6e 20 64 61 74 61 62 61 73 65 2e 0a  ation database..
0420: 2a 2f 0a 63 6f 6e 73 74 20 63 68 61 72 20 7a 43  */.const char zC
0430: 6f 6e 66 69 67 53 63 68 65 6d 61 5b 5d 20 3d 20  onfigSchema[] = 
0440: 0a 40 20 2d 2d 20 54 68 69 73 20 66 69 6c 65 20  .@ -- This file 
0450: 63 6f 6e 74 61 69 6e 73 20 74 68 65 20 73 63 68  contains the sch
0460: 65 6d 61 20 66 6f 72 20 74 68 65 20 64 61 74 61  ema for the data
0470: 62 61 73 65 20 74 68 61 74 20 69 73 20 6b 65 70  base that is kep
0480: 74 20 69 6e 20 74 68 65 0a 40 20 2d 2d 20 7e 2f  t in the.@ -- ~/
0490: 2e 66 6f 73 73 69 6c 20 66 69 6c 65 20 61 6e 64  .fossil file and
04a0: 20 74 68 61 74 20 73 74 6f 72 65 73 20 69 6e 66   that stores inf
04b0: 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20 74  ormation about t
04c0: 68 65 20 75 73 65 72 73 20 73 65 74 75 70 2e 0a  he users setup..
04d0: 40 20 2d 2d 0a 40 20 43 52 45 41 54 45 20 54 41  @ --.@ CREATE TA
04e0: 42 4c 45 20 67 6c 6f 62 61 6c 5f 63 6f 6e 66 69  BLE global_confi
04f0: 67 28 0a 40 20 20 20 6e 61 6d 65 20 54 45 58 54  g(.@   name TEXT
0500: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 0a 40 20   PRIMARY KEY,.@ 
0510: 20 20 76 61 6c 75 65 20 54 45 58 54 0a 40 20 29    value TEXT.@ )
0520: 3b 0a 3b 0a 0a 23 69 66 20 49 4e 54 45 52 46 41  ;.;..#if INTERFA
0530: 43 45 0a 2f 2a 0a 2a 2a 20 54 68 65 20 63 6f 6e  CE./*.** The con
0540: 74 65 6e 74 20 74 61 62 6c 65 73 20 68 61 76 65  tent tables have
0550: 20 61 20 63 6f 6e 74 65 6e 74 20 76 65 72 73 69   a content versi
0560: 6f 6e 20 6e 75 6d 62 65 72 20 77 68 69 63 68 20  on number which 
0570: 72 61 72 65 6c 79 0a 2a 2a 20 63 68 61 6e 67 65  rarely.** change
0580: 73 2e 20 20 54 68 65 20 61 75 78 20 74 61 62 6c  s.  The aux tabl
0590: 65 73 20 68 61 76 65 20 61 6e 20 61 72 62 69 74  es have an arbit
05a0: 72 61 72 79 20 76 65 72 73 69 6f 6e 20 6e 75 6d  rary version num
05b0: 62 65 72 20 28 74 79 70 69 63 61 6c 6c 79 0a 2a  ber (typically.*
05c0: 2a 20 61 20 64 61 74 65 29 20 77 68 69 63 68 20  * a date) which 
05d0: 63 61 6e 20 63 68 61 6e 67 65 20 66 72 65 71 75  can change frequ
05e0: 65 6e 74 6c 79 2e 20 20 57 68 65 6e 20 74 68 65  ently.  When the
05f0: 20 63 6f 6e 74 65 6e 74 20 73 63 68 65 6d 61 20   content schema 
0600: 63 68 61 6e 67 65 73 2c 0a 2a 2a 20 77 65 20 68  changes,.** we h
0610: 61 76 65 20 74 6f 20 65 78 65 63 75 74 65 20 73  ave to execute s
0620: 70 65 63 69 61 6c 20 70 72 6f 63 65 64 75 72 65  pecial procedure
0630: 73 20 74 6f 20 75 70 64 61 74 65 20 74 68 65 20  s to update the 
0640: 73 63 68 65 6d 61 2e 20 20 57 68 65 6e 0a 2a 2a  schema.  When.**
0650: 20 74 68 65 20 61 75 78 20 73 63 68 65 6d 61 20   the aux schema 
0660: 63 68 61 6e 67 65 73 2c 20 61 6c 6c 20 77 65 20  changes, all we 
0670: 6e 65 65 64 20 74 6f 20 64 6f 20 69 73 20 72 65  need to do is re
0680: 62 75 69 6c 64 20 74 68 65 20 64 61 74 61 62 61  build the databa
0690: 73 65 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 43  se..*/.#define C
06a0: 4f 4e 54 45 4e 54 5f 53 43 48 45 4d 41 20 20 22  ONTENT_SCHEMA  "
06b0: 31 22 0a 23 64 65 66 69 6e 65 20 41 55 58 5f 53  1".#define AUX_S
06c0: 43 48 45 4d 41 20 20 20 20 20 20 22 32 30 30 36  CHEMA      "2006
06d0: 2d 31 32 2d 32 33 22 0a 0a 23 65 6e 64 69 66 20  -12-23"..#endif 
06e0: 2f 2a 20 49 4e 54 45 52 46 41 43 45 20 2a 2f 0a  /* INTERFACE */.
06f0: 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 73 63 68 65  ../*.** The sche
0700: 6d 61 20 66 6f 72 20 61 20 72 65 70 6f 73 69 74  ma for a reposit
0710: 6f 72 79 20 64 61 74 61 62 61 73 65 2e 20 20 0a  ory database.  .
0720: 2a 2a 0a 2a 2a 20 53 63 68 65 6d 61 31 5b 5d 20  **.** Schema1[] 
0730: 63 6f 6e 74 61 69 6e 73 20 70 61 72 74 73 20 6f  contains parts o
0740: 66 20 74 68 65 20 73 63 68 65 6d 61 20 74 68 61  f the schema tha
0750: 74 20 61 72 65 20 66 69 78 65 64 20 61 6e 64 20  t are fixed and 
0760: 75 6e 63 68 61 6e 67 69 6e 67 0a 2a 2a 20 61 63  unchanging.** ac
0770: 72 6f 73 73 20 76 65 72 73 69 6f 6e 73 2e 20 20  ross versions.  
0780: 53 63 68 65 6d 61 32 5b 5d 20 63 6f 6e 74 61 69  Schema2[] contai
0790: 6e 73 20 70 61 72 74 73 20 6f 66 20 74 68 65 20  ns parts of the 
07a0: 73 63 68 65 6d 61 20 74 68 61 74 20 63 61 6e 0a  schema that can.
07b0: 2a 2a 20 63 68 61 6e 67 65 20 66 72 6f 6d 20 6f  ** change from o
07c0: 6e 65 20 76 65 72 73 69 6f 6e 20 74 6f 20 74 68  ne version to th
07d0: 65 20 6e 65 78 74 2e 20 20 54 68 65 20 69 6e 66  e next.  The inf
07e0: 6f 72 6d 61 74 69 6f 6e 20 69 6e 20 53 63 68 65  ormation in Sche
07f0: 6d 61 32 5b 5d 0a 2a 2a 20 63 61 6e 20 62 65 20  ma2[].** can be 
0800: 72 65 63 6f 6e 73 74 72 75 63 74 65 64 20 66 72  reconstructed fr
0810: 6f 6d 20 74 68 65 20 69 6e 66 6f 72 6d 61 74 69  om the informati
0820: 6f 6e 20 69 6e 20 53 63 68 65 6d 61 31 5b 5d 2e  on in Schema1[].
0830: 0a 2a 2f 0a 63 6f 6e 73 74 20 63 68 61 72 20 7a  .*/.const char z
0840: 52 65 70 6f 73 69 74 6f 72 79 53 63 68 65 6d 61  RepositorySchema
0850: 31 5b 5d 20 3d 20 0a 40 20 2d 2d 20 54 68 65 20  1[] = .@ -- The 
0860: 42 4c 4f 42 20 61 6e 64 20 44 45 4c 54 41 20 74  BLOB and DELTA t
0870: 61 62 6c 65 73 20 63 6f 6e 74 61 69 6e 20 61 6c  ables contain al
0880: 6c 20 72 65 63 6f 72 64 73 20 68 65 6c 64 20 69  l records held i
0890: 6e 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79  n the repository
08a0: 2e 0a 40 20 2d 2d 0a 40 20 2d 2d 20 54 68 65 20  ..@ --.@ -- The 
08b0: 42 4c 4f 42 2e 43 4f 4e 54 45 4e 54 20 63 6f 6c  BLOB.CONTENT col
08c0: 75 6d 6e 20 69 73 20 61 6c 77 61 79 73 20 63 6f  umn is always co
08d0: 6d 70 72 65 73 73 65 64 20 75 73 69 6e 67 20 6c  mpressed using l
08e0: 69 62 7a 2e 20 20 54 68 69 73 0a 40 20 2d 2d 20  ibz.  This.@ -- 
08f0: 63 6f 6c 75 6d 6e 20 6d 69 67 68 74 20 68 6f 6c  column might hol
0900: 64 20 74 68 65 20 66 75 6c 6c 20 74 65 78 74 20  d the full text 
0910: 6f 66 20 74 68 65 20 72 65 63 6f 72 64 20 6f 72  of the record or
0920: 20 69 74 20 6d 69 67 68 74 20 68 6f 6c 64 0a 40   it might hold.@
0930: 20 2d 2d 20 61 20 64 65 6c 74 61 20 74 68 61 74   -- a delta that
0940: 20 69 73 20 61 62 6c 65 20 74 6f 20 72 65 63 6f   is able to reco
0950: 6e 73 74 72 75 63 74 20 74 68 65 20 72 65 63 6f  nstruct the reco
0960: 72 64 20 66 72 6f 6d 20 73 6f 6d 65 20 6f 74 68  rd from some oth
0970: 65 72 0a 40 20 2d 2d 20 72 65 63 6f 72 64 2e 20  er.@ -- record. 
0980: 20 49 66 20 42 4c 4f 42 2e 43 4f 4e 54 45 4e 54   If BLOB.CONTENT
0990: 20 68 6f 6c 64 73 20 61 20 64 65 6c 74 61 2c 20   holds a delta, 
09a0: 74 68 65 6e 20 61 20 44 45 4c 54 41 20 74 61 62  then a DELTA tab
09b0: 6c 65 20 65 6e 74 72 79 0a 40 20 2d 2d 20 77 69  le entry.@ -- wi
09c0: 6c 6c 20 65 78 69 73 74 20 66 6f 72 20 74 68 65  ll exist for the
09d0: 20 72 65 63 6f 72 64 20 61 6e 64 20 74 68 61 74   record and that
09e0: 20 65 6e 74 72 79 20 77 69 6c 6c 20 70 6f 69 6e   entry will poin
09f0: 74 20 74 6f 20 61 6e 6f 74 68 65 72 0a 40 20 2d  t to another.@ -
0a00: 2d 20 65 6e 74 72 79 20 74 68 61 74 20 68 6f 6c  - entry that hol
0a10: 64 73 20 74 68 65 20 73 6f 75 72 63 65 20 6f 66  ds the source of
0a20: 20 74 68 65 20 64 65 6c 74 61 2e 20 20 44 65 6c   the delta.  Del
0a30: 74 61 73 20 63 61 6e 20 62 65 20 63 68 61 69 6e  tas can be chain
0a40: 65 64 2e 0a 40 20 2d 2d 0a 40 20 43 52 45 41 54  ed..@ --.@ CREAT
0a50: 45 20 54 41 42 4c 45 20 62 6c 6f 62 28 0a 40 20  E TABLE blob(.@ 
0a60: 20 20 72 69 64 20 49 4e 54 45 47 45 52 20 50 52    rid INTEGER PR
0a70: 49 4d 41 52 59 20 4b 45 59 2c 20 20 20 20 20 20  IMARY KEY,      
0a80: 20 20 2d 2d 20 52 65 63 6f 72 64 20 49 44 0a 40    -- Record ID.@
0a90: 20 20 20 72 63 76 69 64 20 49 4e 54 45 47 45 52     rcvid INTEGER
0aa0: 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  ,               
0ab0: 20 20 20 2d 2d 20 4f 72 69 67 69 6e 20 6f 66 20     -- Origin of 
0ac0: 74 68 69 73 20 72 65 63 6f 72 64 0a 40 20 20 20  this record.@   
0ad0: 73 69 7a 65 20 49 4e 54 45 47 45 52 2c 20 20 20  size INTEGER,   
0ae0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0af0: 2d 2d 20 53 69 7a 65 20 6f 66 20 63 6f 6e 74 65  -- Size of conte
0b00: 6e 74 2e 20 2d 31 20 66 6f 72 20 61 20 70 68 61  nt. -1 for a pha
0b10: 6e 74 6f 6d 2e 0a 40 20 20 20 75 75 69 64 20 54  ntom..@   uuid T
0b20: 45 58 54 20 55 4e 49 51 55 45 20 4e 4f 54 20 4e  EXT UNIQUE NOT N
0b30: 55 4c 4c 2c 20 20 20 20 20 20 2d 2d 20 53 48 41  ULL,      -- SHA
0b40: 31 20 68 61 73 68 20 6f 66 20 74 68 65 20 63 6f  1 hash of the co
0b50: 6e 74 65 6e 74 0a 40 20 20 20 63 6f 6e 74 65 6e  ntent.@   conten
0b60: 74 20 42 4c 4f 42 2c 20 20 20 20 20 20 20 20 20  t BLOB,         
0b70: 20 20 20 20 20 20 20 20 20 20 2d 2d 20 43 6f 6d            -- Com
0b80: 70 72 65 73 73 65 64 20 63 6f 6e 74 65 6e 74 20  pressed content 
0b90: 6f 66 20 74 68 69 73 20 72 65 63 6f 72 64 0a 40  of this record.@
0ba0: 20 20 20 43 48 45 43 4b 28 20 6c 65 6e 67 74 68     CHECK( length
0bb0: 28 75 75 69 64 29 3d 3d 34 30 20 41 4e 44 20 72  (uuid)==40 AND r
0bc0: 69 64 3e 30 20 29 0a 40 20 29 3b 0a 40 20 43 52  id>0 ).@ );.@ CR
0bd0: 45 41 54 45 20 54 41 42 4c 45 20 64 65 6c 74 61  EATE TABLE delta
0be0: 28 0a 40 20 20 20 72 69 64 20 49 4e 54 45 47 45  (.@   rid INTEGE
0bf0: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 20  R PRIMARY KEY,  
0c00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2d                 -
0c10: 2d 20 52 65 63 6f 72 64 20 49 44 0a 40 20 20 20  - Record ID.@   
0c20: 73 72 63 69 64 20 49 4e 54 45 47 45 52 20 4e 4f  srcid INTEGER NO
0c30: 54 20 4e 55 4c 4c 20 52 45 46 45 52 45 4e 43 45  T NULL REFERENCE
0c40: 53 20 62 6c 6f 62 20 20 20 2d 2d 20 52 65 63 6f  S blob   -- Reco
0c50: 72 64 20 68 6f 6c 64 69 6e 67 20 73 6f 75 72 63  rd holding sourc
0c60: 65 20 64 6f 63 75 6d 65 6e 74 0a 40 20 29 3b 0a  e document.@ );.
0c70: 40 20 43 52 45 41 54 45 20 49 4e 44 45 58 20 64  @ CREATE INDEX d
0c80: 65 6c 74 61 5f 69 31 20 4f 4e 20 64 65 6c 74 61  elta_i1 ON delta
0c90: 28 73 72 63 69 64 29 3b 0a 40 0a 40 20 2d 2d 20  (srcid);.@.@ -- 
0ca0: 57 68 65 6e 65 76 65 72 20 6e 65 77 20 62 6c 6f  Whenever new blo
0cb0: 62 73 20 61 72 65 20 72 65 63 65 69 76 65 64 20  bs are received 
0cc0: 69 6e 74 6f 20 74 68 65 20 72 65 70 6f 73 69 74  into the reposit
0cd0: 6f 72 79 2c 20 61 6e 20 65 6e 74 72 79 0a 40 20  ory, an entry.@ 
0ce0: 2d 2d 20 69 6e 20 74 68 69 73 20 74 61 62 6c 65  -- in this table
0cf0: 20 72 65 63 6f 72 64 73 20 74 68 65 20 73 6f 75   records the sou
0d00: 72 63 65 20 6f 66 20 74 68 65 20 62 6c 6f 62 2e  rce of the blob.
0d10: 0a 40 20 2d 2d 0a 40 20 43 52 45 41 54 45 20 54  .@ --.@ CREATE T
0d20: 41 42 4c 45 20 72 63 76 66 72 6f 6d 28 0a 40 20  ABLE rcvfrom(.@ 
0d30: 20 20 72 63 76 69 64 20 49 4e 54 45 47 45 52 20    rcvid INTEGER 
0d40: 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 20 20 20  PRIMARY KEY,    
0d50: 20 20 2d 2d 20 52 65 63 65 69 76 65 64 2d 46 72    -- Received-Fr
0d60: 6f 6d 20 49 44 0a 40 20 20 20 75 69 64 20 49 4e  om ID.@   uid IN
0d70: 54 45 47 45 52 20 52 45 46 45 52 45 4e 43 45 53  TEGER REFERENCES
0d80: 20 75 73 65 72 2c 20 20 20 20 2d 2d 20 55 73 65   user,    -- Use
0d90: 72 20 6c 6f 67 69 6e 0a 40 20 20 20 6d 74 69 6d  r login.@   mtim
0da0: 65 20 44 41 54 45 54 49 4d 45 2c 20 20 20 20 20  e DATETIME,     
0db0: 20 20 20 20 20 20 20 20 20 20 20 20 2d 2d 20 54              -- T
0dc0: 69 6d 65 20 6f 72 20 72 65 63 65 69 70 74 0a 40  ime or receipt.@
0dd0: 20 20 20 6e 6f 6e 63 65 20 54 45 58 54 20 55 4e     nonce TEXT UN
0de0: 49 51 55 45 2c 20 20 20 20 20 20 20 20 20 20 20  IQUE,           
0df0: 20 20 20 2d 2d 20 4e 6f 6e 63 65 20 75 73 65 64     -- Nonce used
0e00: 20 66 6f 72 20 6c 6f 67 69 6e 0a 40 20 20 20 69   for login.@   i
0e10: 70 61 64 64 72 20 54 45 58 54 20 20 20 20 20 20  paddr TEXT      
0e20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2d                 -
0e30: 2d 20 52 65 6d 6f 74 65 20 49 50 20 61 64 64 72  - Remote IP addr
0e40: 65 73 73 2e 20 20 4e 55 4c 4c 20 66 6f 72 20 64  ess.  NULL for d
0e50: 69 72 65 63 74 2e 0a 40 20 29 3b 0a 40 0a 40 20  irect..@ );.@.@ 
0e60: 2d 2d 20 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 61  -- Information a
0e70: 62 6f 75 74 20 75 73 65 72 73 0a 40 20 2d 2d 0a  bout users.@ --.
0e80: 40 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 75  @ CREATE TABLE u
0e90: 73 65 72 28 0a 40 20 20 20 75 69 64 20 49 4e 54  ser(.@   uid INT
0ea0: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59  EGER PRIMARY KEY
0eb0: 2c 20 20 20 20 20 20 20 20 2d 2d 20 55 73 65 72  ,        -- User
0ec0: 20 49 44 0a 40 20 20 20 6c 6f 67 69 6e 20 54 45   ID.@   login TE
0ed0: 58 54 2c 20 20 20 20 20 20 20 20 20 20 20 20 20  XT,             
0ee0: 20 20 20 20 20 20 20 20 2d 2d 20 6c 6f 67 69 6e          -- login
0ef0: 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 75 73 65   name of the use
0f00: 72 0a 40 20 20 20 70 77 20 54 45 58 54 2c 20 20  r.@   pw TEXT,  
0f10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0f20: 20 20 20 20 20 20 2d 2d 20 70 61 73 73 77 6f 72        -- passwor
0f30: 64 0a 40 20 20 20 63 61 70 20 54 45 58 54 2c 20  d.@   cap TEXT, 
0f40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0f50: 20 20 20 20 20 20 2d 2d 20 43 61 70 61 62 69 6c        -- Capabil
0f60: 69 74 69 65 73 20 6f 66 20 74 68 69 73 20 75 73  ities of this us
0f70: 65 72 0a 40 20 20 20 63 6f 6f 6b 69 65 20 54 45  er.@   cookie TE
0f80: 58 54 2c 20 20 20 20 20 20 20 20 20 20 20 20 20  XT,             
0f90: 20 20 20 20 20 20 20 2d 2d 20 57 57 57 20 6c 6f         -- WWW lo
0fa0: 67 69 6e 20 63 6f 6f 6b 69 65 0a 40 20 20 20 69  gin cookie.@   i
0fb0: 70 61 64 64 72 20 54 45 58 54 2c 20 20 20 20 20  paddr TEXT,     
0fc0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2d                 -
0fd0: 2d 20 49 50 20 61 64 64 72 65 73 73 20 66 6f 72  - IP address for
0fe0: 20 77 68 69 63 68 20 63 6f 6f 6b 69 65 20 69 73   which cookie is
0ff0: 20 76 61 6c 69 64 0a 40 20 20 20 63 65 78 70 69   valid.@   cexpi
1000: 72 65 20 44 41 54 45 54 49 4d 45 2c 20 20 20 20  re DATETIME,    
1010: 20 20 20 20 20 20 20 20 20 20 20 2d 2d 20 54 69             -- Ti
1020: 6d 65 20 77 68 65 6e 20 63 6f 6f 6b 69 65 20 65  me when cookie e
1030: 78 70 69 72 65 73 0a 40 20 20 20 69 6e 66 6f 20  xpires.@   info 
1040: 54 45 58 54 2c 20 20 20 20 20 20 20 20 20 20 20  TEXT,           
1050: 20 20 20 20 20 20 20 20 20 20 20 2d 2d 20 63 6f             -- co
1060: 6e 74 61 63 74 20 69 6e 66 6f 72 6d 61 74 69 6f  ntact informatio
1070: 6e 0a 40 20 20 20 70 68 6f 74 6f 20 42 4c 4f 42  n.@   photo BLOB
1080: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1090: 20 20 20 20 20 20 2d 2d 20 4a 50 45 47 20 69 6d        -- JPEG im
10a0: 61 67 65 20 6f 66 20 74 68 69 73 20 75 73 65 72  age of this user
10b0: 0a 40 20 29 3b 0a 40 0a 40 20 2d 2d 20 54 68 65  .@ );.@.@ -- The
10c0: 20 56 41 52 20 74 61 62 6c 65 20 68 6f 6c 64 73   VAR table holds
10d0: 20 6d 69 73 63 65 6c 6c 61 6e 6f 75 73 20 69 6e   miscellanous in
10e0: 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20  formation about 
10f0: 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 2e 0a  the repository..
1100: 40 20 2d 2d 20 69 6e 20 74 68 65 20 66 6f 72 6d  @ -- in the form
1110: 20 6f 66 20 6e 61 6d 65 2d 76 61 6c 75 65 20 70   of name-value p
1120: 61 69 72 73 2e 0a 40 20 2d 2d 0a 40 20 43 52 45  airs..@ --.@ CRE
1130: 41 54 45 20 54 41 42 4c 45 20 63 6f 6e 66 69 67  ATE TABLE config
1140: 28 0a 40 20 20 20 6e 61 6d 65 20 54 45 58 54 20  (.@   name TEXT 
1150: 50 52 49 4d 41 52 59 20 4b 45 59 20 4e 4f 54 20  PRIMARY KEY NOT 
1160: 4e 55 4c 4c 2c 20 20 2d 2d 20 50 72 69 6d 61 72  NULL,  -- Primar
1170: 79 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 65 6e  y name of the en
1180: 74 72 79 0a 40 20 20 20 76 61 6c 75 65 20 43 4c  try.@   value CL
1190: 4f 42 2c 20 20 20 20 20 20 20 20 20 20 20 20 20  OB,             
11a0: 20 20 20 20 20 20 20 20 20 2d 2d 20 43 6f 6e 74           -- Cont
11b0: 65 6e 74 20 6f 66 20 74 68 65 20 6e 61 6d 65 64  ent of the named
11c0: 20 70 61 72 61 6d 65 74 65 72 0a 40 20 20 20 43   parameter.@   C
11d0: 48 45 43 4b 28 20 74 79 70 65 6f 66 28 6e 61 6d  HECK( typeof(nam
11e0: 65 29 3d 27 74 65 78 74 27 20 41 4e 44 20 6c 65  e)='text' AND le
11f0: 6e 67 74 68 28 6e 61 6d 65 29 3e 3d 31 20 29 0a  ngth(name)>=1 ).
1200: 40 20 29 3b 0a 40 0a 40 20 2d 2d 20 41 72 74 69  @ );.@.@ -- Arti
1210: 66 61 63 74 73 20 74 68 61 74 20 73 68 6f 75 6c  facts that shoul
1220: 64 20 6e 6f 74 20 62 65 20 70 72 6f 63 65 73 73  d not be process
1230: 65 64 20 61 72 65 20 69 64 65 6e 74 69 66 69 65  ed are identifie
1240: 64 20 69 6e 20 74 68 65 0a 40 20 2d 2d 20 22 73  d in the.@ -- "s
1250: 68 75 6e 22 20 74 61 62 6c 65 2e 20 20 41 72 74  hun" table.  Art
1260: 69 66 61 63 74 73 20 74 68 61 74 20 61 72 65 20  ifacts that are 
1270: 63 6f 6e 74 72 6f 6c 2d 66 69 6c 65 20 66 6f 72  control-file for
1280: 67 65 72 69 65 73 20 6f 72 0a 40 20 2d 2d 20 73  geries or.@ -- s
1290: 70 61 6d 20 6f 72 20 61 72 74 69 66 61 63 74 73  pam or artifacts
12a0: 20 77 68 6f 73 65 20 63 6f 6e 74 65 6e 74 73 20   whose contents 
12b0: 76 69 6f 6c 61 74 65 20 61 64 6d 69 6e 69 73 74  violate administ
12c0: 72 61 74 69 76 65 20 70 6f 6c 69 63 79 0a 40 20  rative policy.@ 
12d0: 2d 2d 20 63 61 6e 20 62 65 20 73 68 75 6e 6e 65  -- can be shunne
12e0: 64 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 70 72  d in order to pr
12f0: 65 76 65 6e 74 20 74 68 65 6d 20 66 72 6f 6d 20  event them from 
1300: 63 6f 6e 74 61 6d 69 6e 61 74 69 6e 67 0a 40 20  contaminating.@ 
1310: 2d 2d 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72  -- the repositor
1320: 79 2e 0a 40 20 2d 2d 0a 40 20 2d 2d 20 53 68 75  y..@ --.@ -- Shu
1330: 6e 6e 65 64 20 61 72 74 69 66 61 63 74 73 20 64  nned artifacts d
1340: 6f 20 6e 6f 74 20 65 78 69 73 74 20 69 6e 20 74  o not exist in t
1350: 68 65 20 62 6c 6f 62 20 74 61 62 6c 65 2e 20 20  he blob table.  
1360: 48 65 6e 63 65 20 74 68 65 79 0a 40 20 2d 2d 20  Hence they.@ -- 
1370: 68 61 76 65 20 6e 6f 74 20 61 72 74 69 66 61 63  have not artifac
1380: 74 20 49 44 20 28 72 69 64 29 20 61 6e 64 20 77  t ID (rid) and w
1390: 65 20 74 68 75 73 20 6d 75 73 74 20 73 74 6f 72  e thus must stor
13a0: 65 20 74 68 65 69 72 20 66 75 6c 6c 0a 40 20 2d  e their full.@ -
13b0: 2d 20 55 55 49 44 2e 0a 40 20 2d 2d 0a 40 20 43  - UUID..@ --.@ C
13c0: 52 45 41 54 45 20 54 41 42 4c 45 20 73 68 75 6e  REATE TABLE shun
13d0: 28 75 75 69 64 20 55 4e 49 51 55 45 29 3b 0a 40  (uuid UNIQUE);.@
13e0: 0a 40 20 2d 2d 20 41 72 74 69 66 61 63 74 73 20  .@ -- Artifacts 
13f0: 74 68 61 74 20 73 68 6f 75 6c 64 20 6e 6f 74 20  that should not 
1400: 62 65 20 70 75 73 68 65 64 20 61 72 65 20 73 74  be pushed are st
1410: 6f 72 65 64 20 69 6e 20 74 68 65 20 22 70 72 69  ored in the "pri
1420: 76 61 74 65 22 0a 40 20 2d 2d 20 74 61 62 6c 65  vate".@ -- table
1430: 2e 20 20 50 72 69 76 61 74 65 20 61 72 74 69 66  .  Private artif
1440: 61 63 74 73 20 61 72 65 20 6f 6d 69 74 74 65 64  acts are omitted
1450: 20 66 72 6f 6d 20 74 68 65 20 22 75 6e 63 6c 75   from the "unclu
1460: 73 74 65 72 65 64 22 20 61 6e 64 0a 40 20 2d 2d  stered" and.@ --
1470: 20 22 75 6e 73 65 6e 74 22 20 74 61 62 6c 65 73   "unsent" tables
1480: 2e 0a 40 20 2d 2d 0a 40 20 43 52 45 41 54 45 20  ..@ --.@ CREATE 
1490: 54 41 42 4c 45 20 70 72 69 76 61 74 65 28 72 69  TABLE private(ri
14a0: 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52  d INTEGER PRIMAR
14b0: 59 20 4b 45 59 29 3b 0a 40 0a 40 20 2d 2d 20 41  Y KEY);.@.@ -- A
14c0: 6e 20 65 6e 74 72 79 20 69 6e 20 74 68 69 73 20  n entry in this 
14d0: 74 61 62 6c 65 20 64 65 73 63 72 69 62 65 73 20  table describes 
14e0: 61 20 64 61 74 61 62 61 73 65 20 71 75 65 72 79  a database query
14f0: 20 74 68 61 74 20 67 65 6e 65 72 61 74 65 73 20   that generates 
1500: 61 0a 40 20 2d 2d 20 74 61 62 6c 65 20 6f 66 20  a.@ -- table of 
1510: 74 69 63 6b 65 74 73 2e 0a 40 20 2d 2d 0a 40 20  tickets..@ --.@ 
1520: 43 52 45 41 54 45 20 54 41 42 4c 45 20 72 65 70  CREATE TABLE rep
1530: 6f 72 74 66 6d 74 28 0a 40 20 20 20 20 72 6e 20  ortfmt(.@    rn 
1540: 69 6e 74 65 67 65 72 20 70 72 69 6d 61 72 79 20  integer primary 
1550: 6b 65 79 2c 20 20 2d 2d 20 52 65 70 6f 72 74 20  key,  -- Report 
1560: 6e 75 6d 62 65 72 0a 40 20 20 20 20 6f 77 6e 65  number.@    owne
1570: 72 20 74 65 78 74 2c 20 20 20 20 20 20 20 20 20  r text,         
1580: 20 20 20 20 20 2d 2d 20 4f 77 6e 65 72 20 6f 66       -- Owner of
1590: 20 74 68 69 73 20 72 65 70 6f 72 74 20 66 6f 72   this report for
15a0: 6d 61 74 20 28 6e 6f 74 20 75 73 65 64 29 0a 40  mat (not used).@
15b0: 20 20 20 20 74 69 74 6c 65 20 74 65 78 74 2c 20      title text, 
15c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2d 2d 20               -- 
15d0: 54 69 74 6c 65 20 6f 66 20 74 68 69 73 20 72 65  Title of this re
15e0: 70 6f 72 74 0a 40 20 20 20 20 63 6f 6c 73 20 74  port.@    cols t
15f0: 65 78 74 2c 20 20 20 20 20 20 20 20 20 20 20 20  ext,            
1600: 20 20 20 2d 2d 20 41 20 63 6f 6c 6f 72 2d 6b 65     -- A color-ke
1610: 79 20 73 70 65 63 69 66 69 63 61 74 69 6f 6e 0a  y specification.
1620: 40 20 20 20 20 73 71 6c 63 6f 64 65 20 74 65 78  @    sqlcode tex
1630: 74 20 20 20 20 20 20 20 20 20 20 20 20 20 2d 2d  t             --
1640: 20 41 6e 20 53 51 4c 20 53 45 4c 45 43 54 20 73   An SQL SELECT s
1650: 74 61 74 65 6d 65 6e 74 20 66 6f 72 20 74 68 69  tatement for thi
1660: 73 20 72 65 70 6f 72 74 0a 40 20 29 3b 0a 40 20  s report.@ );.@ 
1670: 49 4e 53 45 52 54 20 49 4e 54 4f 20 72 65 70 6f  INSERT INTO repo
1680: 72 74 66 6d 74 28 74 69 74 6c 65 2c 63 6f 6c 73  rtfmt(title,cols
1690: 2c 73 71 6c 63 6f 64 65 29 20 56 41 4c 55 45 53  ,sqlcode) VALUES
16a0: 28 27 41 6c 6c 20 54 69 63 6b 65 74 73 27 2c 27  ('All Tickets','
16b0: 23 66 66 66 66 66 66 20 4b 65 79 3a 0a 40 20 23  #ffffff Key:.@ #
16c0: 66 32 64 63 64 63 20 41 63 74 69 76 65 0a 40 20  f2dcdc Active.@ 
16d0: 23 65 38 65 38 65 38 20 52 65 76 69 65 77 0a 40  #e8e8e8 Review.@
16e0: 20 23 63 66 65 38 62 64 20 46 69 78 65 64 0a 40   #cfe8bd Fixed.@
16f0: 20 23 62 64 65 35 64 36 20 54 65 73 74 65 64 0a   #bde5d6 Tested.
1700: 40 20 23 63 61 63 61 65 35 20 44 65 66 65 72 72  @ #cacae5 Deferr
1710: 65 64 0a 40 20 23 63 38 63 38 63 38 20 43 6c 6f  ed.@ #c8c8c8 Clo
1720: 73 65 64 27 2c 27 53 45 4c 45 43 54 0a 40 20 20  sed','SELECT.@  
1730: 20 43 41 53 45 20 57 48 45 4e 20 73 74 61 74 75   CASE WHEN statu
1740: 73 20 49 4e 20 28 27 27 4f 70 65 6e 27 27 2c 27  s IN (''Open'','
1750: 27 56 65 72 69 66 69 65 64 27 27 29 20 54 48 45  'Verified'') THE
1760: 4e 20 27 27 23 66 32 64 63 64 63 27 27 0a 40 20  N ''#f2dcdc''.@ 
1770: 20 20 20 20 20 20 20 57 48 45 4e 20 73 74 61 74         WHEN stat
1780: 75 73 3d 27 27 52 65 76 69 65 77 27 27 20 54 48  us=''Review'' TH
1790: 45 4e 20 27 27 23 65 38 65 38 65 38 27 27 0a 40  EN ''#e8e8e8''.@
17a0: 20 20 20 20 20 20 20 20 57 48 45 4e 20 73 74 61          WHEN sta
17b0: 74 75 73 3d 27 27 46 69 78 65 64 27 27 20 54 48  tus=''Fixed'' TH
17c0: 45 4e 20 27 27 23 63 66 65 38 62 64 27 27 0a 40  EN ''#cfe8bd''.@
17d0: 20 20 20 20 20 20 20 20 57 48 45 4e 20 73 74 61          WHEN sta
17e0: 74 75 73 3d 27 27 54 65 73 74 65 64 27 27 20 54  tus=''Tested'' T
17f0: 48 45 4e 20 27 27 23 62 64 65 35 64 36 27 27 0a  HEN ''#bde5d6''.
1800: 40 20 20 20 20 20 20 20 20 57 48 45 4e 20 73 74  @        WHEN st
1810: 61 74 75 73 3d 27 27 44 65 66 65 72 72 65 64 27  atus=''Deferred'
1820: 27 20 54 48 45 4e 20 27 27 23 63 61 63 61 65 35  ' THEN ''#cacae5
1830: 27 27 0a 40 20 20 20 20 20 20 20 20 45 4c 53 45  ''.@        ELSE
1840: 20 27 27 23 63 38 63 38 63 38 27 27 20 45 4e 44   ''#c8c8c8'' END
1850: 20 41 53 20 27 27 62 67 63 6f 6c 6f 72 27 27 2c   AS ''bgcolor'',
1860: 0a 40 20 20 20 73 75 62 73 74 72 28 74 6b 74 5f  .@   substr(tkt_
1870: 75 75 69 64 2c 31 2c 31 30 29 20 41 53 20 27 27  uuid,1,10) AS ''
1880: 23 27 27 2c 0a 40 20 20 20 64 61 74 65 74 69 6d  #'',.@   datetim
1890: 65 28 74 6b 74 5f 6d 74 69 6d 65 29 20 41 53 20  e(tkt_mtime) AS 
18a0: 27 27 6d 74 69 6d 65 27 27 2c 0a 40 20 20 20 74  ''mtime'',.@   t
18b0: 79 70 65 2c 0a 40 20 20 20 73 74 61 74 75 73 2c  ype,.@   status,
18c0: 0a 40 20 20 20 73 75 62 73 79 73 74 65 6d 2c 0a  .@   subsystem,.
18d0: 40 20 20 20 74 69 74 6c 65 0a 40 20 46 52 4f 4d  @   title.@ FROM
18e0: 20 74 69 63 6b 65 74 27 29 3b 0a 40 0a 40 20 2d   ticket');.@.@ -
18f0: 2d 20 53 6f 6d 65 20 74 69 63 6b 65 74 20 63 6f  - Some ticket co
1900: 6e 74 65 6e 74 20 28 73 75 63 68 20 61 73 20 74  ntent (such as t
1910: 68 65 20 6f 72 69 67 69 6e 61 74 6f 72 73 20 65  he originators e
1920: 6d 61 69 6c 20 61 64 64 72 65 73 73 20 6f 72 20  mail address or 
1930: 63 6f 6e 74 61 63 74 0a 40 20 2d 2d 20 69 6e 66  contact.@ -- inf
1940: 6f 72 6d 61 74 69 6f 6e 29 20 6e 65 65 64 73 20  ormation) needs 
1950: 74 6f 20 62 65 20 6f 62 73 63 75 72 65 64 20 74  to be obscured t
1960: 6f 20 70 72 6f 74 65 63 74 20 70 72 69 76 61 63  o protect privac
1970: 79 2e 20 20 54 68 69 73 20 69 73 20 61 63 68 69  y.  This is achi
1980: 65 76 65 64 0a 40 20 2d 2d 20 62 79 20 73 74 6f  eved.@ -- by sto
1990: 72 69 6e 67 20 61 6e 20 53 48 41 31 20 68 61 73  ring an SHA1 has
19a0: 68 20 6f 66 20 74 68 65 20 63 6f 6e 74 65 6e 74  h of the content
19b0: 2e 20 20 46 6f 72 20 64 69 73 70 6c 61 79 2c 20  .  For display, 
19c0: 74 68 65 20 68 61 73 68 20 69 73 0a 40 20 2d 2d  the hash is.@ --
19d0: 20 6d 61 70 70 65 64 20 62 61 63 6b 20 69 6e 74   mapped back int
19e0: 6f 20 74 68 65 20 6f 72 69 67 69 6e 61 6c 20 74  o the original t
19f0: 65 78 74 20 75 73 69 6e 67 20 74 68 69 73 20 74  ext using this t
1a00: 61 62 6c 65 2e 20 20 0a 40 20 2d 2d 0a 40 20 2d  able.  .@ --.@ -
1a10: 2d 20 54 68 69 73 20 74 61 62 6c 65 20 63 6f 6e  - This table con
1a20: 74 61 69 6e 73 20 73 65 6e 73 69 74 69 76 65 20  tains sensitive 
1a30: 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 6e 64 20  information and 
1a40: 73 68 6f 75 6c 64 20 6e 6f 74 20 62 65 20 73 68  should not be sh
1a50: 61 72 65 64 0a 40 20 2d 2d 20 77 69 74 68 20 75  ared.@ -- with u
1a60: 6e 61 75 74 68 6f 72 69 7a 65 64 20 75 73 65 72  nauthorized user
1a70: 73 2e 0a 40 20 2d 2d 0a 40 20 43 52 45 41 54 45  s..@ --.@ CREATE
1a80: 20 54 41 42 4c 45 20 63 6f 6e 63 65 61 6c 65 64   TABLE concealed
1a90: 28 0a 40 20 20 20 68 61 73 68 20 54 45 58 54 20  (.@   hash TEXT 
1aa0: 50 52 49 4d 41 52 59 20 4b 45 59 2c 0a 40 20 20  PRIMARY KEY,.@  
1ab0: 20 63 6f 6e 74 65 6e 74 20 54 45 58 54 0a 40 20   content TEXT.@ 
1ac0: 29 3b 0a 3b 0a 0a 63 6f 6e 73 74 20 63 68 61 72  );.;..const char
1ad0: 20 7a 52 65 70 6f 73 69 74 6f 72 79 53 63 68 65   zRepositorySche
1ae0: 6d 61 32 5b 5d 20 3d 0a 40 20 2d 2d 20 46 69 6c  ma2[] =.@ -- Fil
1af0: 65 6e 61 6d 65 73 0a 40 20 2d 2d 0a 40 20 43 52  enames.@ --.@ CR
1b00: 45 41 54 45 20 54 41 42 4c 45 20 66 69 6c 65 6e  EATE TABLE filen
1b10: 61 6d 65 28 0a 40 20 20 20 66 6e 69 64 20 49 4e  ame(.@   fnid IN
1b20: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45  TEGER PRIMARY KE
1b30: 59 2c 20 20 20 20 2d 2d 20 46 69 6c 65 6e 61 6d  Y,    -- Filenam
1b40: 65 20 49 44 0a 40 20 20 20 6e 61 6d 65 20 54 45  e ID.@   name TE
1b50: 58 54 20 55 4e 49 51 55 45 20 20 20 20 20 20 20  XT UNIQUE       
1b60: 20 20 20 20 20 20 2d 2d 20 4e 61 6d 65 20 6f 66        -- Name of
1b70: 20 66 69 6c 65 20 70 61 67 65 0a 40 20 29 3b 0a   file page.@ );.
1b80: 40 0a 40 20 2d 2d 20 4c 69 6e 6b 61 67 65 73 20  @.@ -- Linkages 
1b90: 62 65 74 77 65 65 6e 20 6d 61 6e 69 66 65 73 74  between manifest
1ba0: 73 2c 20 66 69 6c 65 73 20 63 72 65 61 74 65 64  s, files created
1bb0: 20 62 79 20 74 68 61 74 20 6d 61 6e 69 66 65 73   by that manifes
1bc0: 74 2c 20 61 6e 64 0a 40 20 2d 2d 20 74 68 65 20  t, and.@ -- the 
1bd0: 6e 61 6d 65 73 20 6f 66 20 74 68 6f 73 65 20 66  names of those f
1be0: 69 6c 65 73 2e 0a 40 20 2d 2d 0a 40 20 2d 2d 20  iles..@ --.@ -- 
1bf0: 70 69 64 3d 3d 30 20 69 66 20 74 68 65 20 66 69  pid==0 if the fi
1c00: 6c 65 20 69 73 20 61 64 64 65 64 20 62 79 20 63  le is added by c
1c10: 68 65 63 6b 2d 69 6e 20 6d 69 64 2e 0a 40 20 2d  heck-in mid..@ -
1c20: 2d 20 66 69 64 3d 3d 30 20 69 66 20 74 68 65 20  - fid==0 if the 
1c30: 66 69 6c 65 20 69 73 20 72 65 6d 6f 76 65 64 20  file is removed 
1c40: 62 79 20 63 68 65 63 6b 2d 69 6e 20 6d 69 64 2e  by check-in mid.
1c50: 0a 40 20 2d 2d 0a 40 20 43 52 45 41 54 45 20 54  .@ --.@ CREATE T
1c60: 41 42 4c 45 20 6d 6c 69 6e 6b 28 0a 40 20 20 20  ABLE mlink(.@   
1c70: 6d 69 64 20 49 4e 54 45 47 45 52 20 52 45 46 45  mid INTEGER REFE
1c80: 52 45 4e 43 45 53 20 62 6c 6f 62 2c 20 20 20 20  RENCES blob,    
1c90: 20 20 20 20 2d 2d 20 4d 61 6e 69 66 65 73 74 20      -- Manifest 
1ca0: 49 44 20 77 68 65 72 65 20 63 68 61 6e 67 65 20  ID where change 
1cb0: 6f 63 63 75 72 73 0a 40 20 20 20 70 69 64 20 49  occurs.@   pid I
1cc0: 4e 54 45 47 45 52 20 52 45 46 45 52 45 4e 43 45  NTEGER REFERENCE
1cd0: 53 20 62 6c 6f 62 2c 20 20 20 20 20 20 20 20 2d  S blob,        -
1ce0: 2d 20 46 69 6c 65 20 49 44 20 69 6e 20 70 61 72  - File ID in par
1cf0: 65 6e 74 20 6d 61 6e 69 66 65 73 74 0a 40 20 20  ent manifest.@  
1d00: 20 66 69 64 20 49 4e 54 45 47 45 52 20 52 45 46   fid INTEGER REF
1d10: 45 52 45 4e 43 45 53 20 62 6c 6f 62 2c 20 20 20  ERENCES blob,   
1d20: 20 20 20 20 20 2d 2d 20 43 68 61 6e 67 65 64 20       -- Changed 
1d30: 66 69 6c 65 20 49 44 20 69 6e 20 74 68 69 73 20  file ID in this 
1d40: 6d 61 6e 69 66 65 73 74 0a 40 20 20 20 66 6e 69  manifest.@   fni
1d50: 64 20 49 4e 54 45 47 45 52 20 52 45 46 45 52 45  d INTEGER REFERE
1d60: 4e 43 45 53 20 66 69 6c 65 6e 61 6d 65 2c 20 20  NCES filename,  
1d70: 20 2d 2d 20 4e 61 6d 65 20 6f 66 20 74 68 65 20   -- Name of the 
1d80: 66 69 6c 65 0a 40 20 20 20 70 66 6e 69 64 20 49  file.@   pfnid I
1d90: 4e 54 45 47 45 52 20 52 45 46 45 52 45 4e 43 45  NTEGER REFERENCE
1da0: 53 20 66 69 6c 65 6e 61 6d 65 20 20 20 2d 2d 20  S filename   -- 
1db0: 50 72 65 76 69 6f 75 73 20 6e 61 6d 65 2e 20 30  Previous name. 0
1dc0: 20 69 66 20 75 6e 63 68 61 6e 67 65 64 0a 40 20   if unchanged.@ 
1dd0: 29 3b 0a 40 20 43 52 45 41 54 45 20 49 4e 44 45  );.@ CREATE INDE
1de0: 58 20 6d 6c 69 6e 6b 5f 69 31 20 4f 4e 20 6d 6c  X mlink_i1 ON ml
1df0: 69 6e 6b 28 6d 69 64 29 3b 0a 40 20 43 52 45 41  ink(mid);.@ CREA
1e00: 54 45 20 49 4e 44 45 58 20 6d 6c 69 6e 6b 5f 69  TE INDEX mlink_i
1e10: 32 20 4f 4e 20 6d 6c 69 6e 6b 28 66 6e 69 64 29  2 ON mlink(fnid)
1e20: 3b 0a 40 20 43 52 45 41 54 45 20 49 4e 44 45 58  ;.@ CREATE INDEX
1e30: 20 6d 6c 69 6e 6b 5f 69 33 20 4f 4e 20 6d 6c 69   mlink_i3 ON mli
1e40: 6e 6b 28 66 69 64 29 3b 0a 40 20 43 52 45 41 54  nk(fid);.@ CREAT
1e50: 45 20 49 4e 44 45 58 20 6d 6c 69 6e 6b 5f 69 34  E INDEX mlink_i4
1e60: 20 4f 4e 20 6d 6c 69 6e 6b 28 70 69 64 29 3b 0a   ON mlink(pid);.
1e70: 40 0a 40 20 2d 2d 20 50 61 72 65 6e 74 2f 63 68  @.@ -- Parent/ch
1e80: 69 6c 64 20 6c 69 6e 6b 61 67 65 73 0a 40 20 2d  ild linkages.@ -
1e90: 2d 0a 40 20 43 52 45 41 54 45 20 54 41 42 4c 45  -.@ CREATE TABLE
1ea0: 20 70 6c 69 6e 6b 28 0a 40 20 20 20 70 69 64 20   plink(.@   pid 
1eb0: 49 4e 54 45 47 45 52 20 52 45 46 45 52 45 4e 43  INTEGER REFERENC
1ec0: 45 53 20 62 6c 6f 62 2c 20 20 20 20 2d 2d 20 50  ES blob,    -- P
1ed0: 61 72 65 6e 74 20 6d 61 6e 69 66 65 73 74 0a 40  arent manifest.@
1ee0: 20 20 20 63 69 64 20 49 4e 54 45 47 45 52 20 52     cid INTEGER R
1ef0: 45 46 45 52 45 4e 43 45 53 20 62 6c 6f 62 2c 20  EFERENCES blob, 
1f00: 20 20 20 2d 2d 20 43 68 69 6c 64 20 6d 61 6e 69     -- Child mani
1f10: 66 65 73 74 0a 40 20 20 20 69 73 70 72 69 6d 20  fest.@   isprim 
1f20: 42 4f 4f 4c 45 41 4e 2c 20 20 20 20 20 20 20 20  BOOLEAN,        
1f30: 20 20 20 20 20 20 20 20 20 2d 2d 20 70 69 64 20           -- pid 
1f40: 69 73 20 74 68 65 20 70 72 69 6d 61 72 79 20 70  is the primary p
1f50: 61 72 65 6e 74 20 6f 66 20 63 69 64 0a 40 20 20  arent of cid.@  
1f60: 20 6d 74 69 6d 65 20 44 41 54 45 54 49 4d 45 2c   mtime DATETIME,
1f70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1f80: 20 2d 2d 20 74 68 65 20 64 61 74 65 2f 74 69 6d   -- the date/tim
1f90: 65 20 73 74 61 6d 70 20 6f 6e 20 63 69 64 0a 40  e stamp on cid.@
1fa0: 20 20 20 55 4e 49 51 55 45 28 70 69 64 2c 20 63     UNIQUE(pid, c
1fb0: 69 64 29 0a 40 20 29 3b 0a 40 20 43 52 45 41 54  id).@ );.@ CREAT
1fc0: 45 20 49 4e 44 45 58 20 70 6c 69 6e 6b 5f 69 32  E INDEX plink_i2
1fd0: 20 4f 4e 20 70 6c 69 6e 6b 28 63 69 64 29 3b 0a   ON plink(cid);.
1fe0: 40 0a 40 20 2d 2d 20 45 76 65 6e 74 73 20 75 73  @.@ -- Events us
1ff0: 65 64 20 74 6f 20 67 65 6e 65 72 61 74 65 20 61  ed to generate a
2000: 20 74 69 6d 65 6c 69 6e 65 0a 40 20 2d 2d 0a 40   timeline.@ --.@
2010: 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 65 76   CREATE TABLE ev
2020: 65 6e 74 28 0a 40 20 20 20 74 79 70 65 20 54 45  ent(.@   type TE
2030: 58 54 2c 20 20 20 20 20 20 20 20 20 20 20 20 20  XT,             
2040: 20 20 20 20 20 20 20 20 20 2d 2d 20 54 79 70 65           -- Type
2050: 20 6f 66 20 65 76 65 6e 74 0a 40 20 20 20 6d 74   of event.@   mt
2060: 69 6d 65 20 44 41 54 45 54 49 4d 45 2c 20 20 20  ime DATETIME,   
2070: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2d 2d                --
2080: 20 44 61 74 65 20 61 6e 64 20 74 69 6d 65 20 77   Date and time w
2090: 68 65 6e 20 74 68 65 20 65 76 65 6e 74 20 6f 63  hen the event oc
20a0: 63 75 72 73 0a 40 20 20 20 6f 62 6a 69 64 20 49  curs.@   objid I
20b0: 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b  NTEGER PRIMARY K
20c0: 45 59 2c 20 20 20 20 20 20 2d 2d 20 41 73 73 6f  EY,      -- Asso
20d0: 63 69 61 74 65 64 20 72 65 63 6f 72 64 20 49 44  ciated record ID
20e0: 0a 40 20 20 20 75 69 64 20 49 4e 54 45 47 45 52  .@   uid INTEGER
20f0: 20 52 45 46 45 52 45 4e 43 45 53 20 75 73 65 72   REFERENCES user
2100: 2c 20 20 20 20 2d 2d 20 55 73 65 72 20 77 68 6f  ,    -- User who
2110: 20 63 61 75 73 65 64 20 74 68 65 20 65 76 65 6e   caused the even
2120: 74 0a 40 20 20 20 62 67 63 6f 6c 6f 72 20 54 45  t.@   bgcolor TE
2130: 58 54 2c 20 20 20 20 20 20 20 20 20 20 20 20 20  XT,             
2140: 20 20 20 20 20 20 2d 2d 20 43 6f 6c 6f 72 20 73        -- Color s
2150: 65 74 20 62 79 20 27 62 67 63 6f 6c 6f 72 27 20  et by 'bgcolor' 
2160: 70 72 6f 70 65 72 74 79 0a 40 20 20 20 65 75 73  property.@   eus
2170: 65 72 20 54 45 58 54 2c 20 20 20 20 20 20 20 20  er TEXT,        
2180: 20 20 20 20 20 20 20 20 20 20 20 20 20 2d 2d 20               -- 
2190: 55 73 65 72 20 73 65 74 20 62 79 20 27 75 73 65  User set by 'use
21a0: 72 27 20 70 72 6f 70 65 72 74 79 0a 40 20 20 20  r' property.@   
21b0: 75 73 65 72 20 54 45 58 54 2c 20 20 20 20 20 20  user TEXT,      
21c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
21d0: 2d 2d 20 4e 61 6d 65 20 6f 66 20 74 68 65 20 75  -- Name of the u
21e0: 73 65 72 0a 40 20 20 20 65 63 6f 6d 6d 65 6e 74  ser.@   ecomment
21f0: 20 54 45 58 54 2c 20 20 20 20 20 20 20 20 20 20   TEXT,          
2200: 20 20 20 20 20 20 20 20 2d 2d 20 43 6f 6d 6d 65          -- Comme
2210: 6e 74 20 73 65 74 20 62 79 20 27 63 6f 6d 6d 65  nt set by 'comme
2220: 6e 74 27 20 70 72 6f 70 65 72 74 79 0a 40 20 20  nt' property.@  
2230: 20 63 6f 6d 6d 65 6e 74 20 54 45 58 54 20 20 20   comment TEXT   
2240: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2250: 20 2d 2d 20 43 6f 6d 6d 65 6e 74 20 64 65 73 63   -- Comment desc
2260: 72 69 62 69 6e 67 20 74 68 65 20 65 76 65 6e 74  ribing the event
2270: 0a 40 20 29 3b 0a 40 20 43 52 45 41 54 45 20 49  .@ );.@ CREATE I
2280: 4e 44 45 58 20 65 76 65 6e 74 5f 69 31 20 4f 4e  NDEX event_i1 ON
2290: 20 65 76 65 6e 74 28 6d 74 69 6d 65 29 3b 0a 40   event(mtime);.@
22a0: 0a 40 20 2d 2d 20 41 20 72 65 63 6f 72 64 20 6f  .@ -- A record o
22b0: 66 20 70 68 61 6e 74 6f 6d 73 2e 20 20 41 20 70  f phantoms.  A p
22c0: 68 61 6e 74 6f 6d 20 69 73 20 61 20 72 65 63 6f  hantom is a reco
22d0: 72 64 20 66 6f 72 20 77 68 69 63 68 20 77 65 20  rd for which we 
22e0: 6b 6e 6f 77 20 74 68 65 0a 40 20 2d 2d 20 55 55  know the.@ -- UU
22f0: 49 44 20 62 75 74 20 77 65 20 64 6f 20 6e 6f 74  ID but we do not
2300: 20 28 79 65 74 29 20 6b 6e 6f 77 20 74 68 65 20   (yet) know the 
2310: 66 69 6c 65 20 63 6f 6e 74 65 6e 74 2e 0a 40 20  file content..@ 
2320: 2d 2d 0a 40 20 43 52 45 41 54 45 20 54 41 42 4c  --.@ CREATE TABL
2330: 45 20 70 68 61 6e 74 6f 6d 28 0a 40 20 20 20 72  E phantom(.@   r
2340: 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41  id INTEGER PRIMA
2350: 52 59 20 4b 45 59 20 20 20 20 20 20 20 20 20 2d  RY KEY         -
2360: 2d 20 52 65 63 6f 72 64 20 49 44 20 6f 66 20 74  - Record ID of t
2370: 68 65 20 70 68 61 6e 74 6f 6d 0a 40 20 29 3b 0a  he phantom.@ );.
2380: 40 0a 40 20 2d 2d 20 55 6e 63 6c 75 73 74 65 72  @.@ -- Uncluster
2390: 65 64 20 72 65 63 6f 72 64 73 2e 20 20 41 6e 20  ed records.  An 
23a0: 75 6e 63 6c 75 73 74 65 72 65 64 20 72 65 63 6f  unclustered reco
23b0: 72 64 20 69 73 20 61 20 72 65 63 6f 72 64 20 28  rd is a record (
23c0: 69 6e 63 6c 75 64 69 6e 67 0a 40 20 2d 2d 20 61  including.@ -- a
23d0: 20 63 6c 75 73 74 65 72 20 72 65 63 6f 72 64 73   cluster records
23e0: 20 74 68 65 6d 73 65 6c 76 65 73 29 20 74 68 61   themselves) tha
23f0: 74 20 69 73 20 6e 6f 74 20 6d 65 6e 74 69 6f 6e  t is not mention
2400: 65 64 20 62 79 20 73 6f 6d 65 20 6f 74 68 65 72  ed by some other
2410: 0a 40 20 2d 2d 20 63 6c 75 73 74 65 72 2e 0a 40  .@ -- cluster..@
2420: 20 2d 2d 0a 40 20 2d 2d 20 50 68 61 6e 74 6f 6d   --.@ -- Phantom
2430: 73 20 61 72 65 20 75 73 75 61 6c 6c 79 20 69 6e  s are usually in
2440: 63 6c 75 64 65 64 20 69 6e 20 74 68 65 20 75 6e  cluded in the un
2450: 63 6c 75 73 74 65 72 65 64 20 74 61 62 6c 65 2e  clustered table.
2460: 20 20 41 20 6e 65 77 20 63 6c 75 73 74 65 72 0a    A new cluster.
2470: 40 20 2d 2d 20 77 69 6c 6c 20 6e 65 76 65 72 20  @ -- will never 
2480: 62 65 20 63 72 65 61 74 65 64 20 74 68 61 74 20  be created that 
2490: 63 6f 6e 74 61 69 6e 73 20 61 20 70 68 61 6e 74  contains a phant
24a0: 6f 6d 2e 20 20 42 75 74 20 61 6e 6f 74 68 65 72  om.  But another
24b0: 20 72 65 70 6f 73 69 74 6f 72 79 0a 40 20 2d 2d   repository.@ --
24c0: 20 6d 69 67 68 74 20 73 65 6e 64 20 75 73 20 61   might send us a
24d0: 20 63 6c 75 73 74 65 72 20 74 68 61 74 20 63 6f   cluster that co
24e0: 6e 74 61 69 6e 73 20 65 6e 74 72 69 65 73 20 74  ntains entries t
24f0: 68 61 74 20 61 72 65 20 70 68 61 6e 74 6f 6d 73  hat are phantoms
2500: 20 74 6f 0a 40 20 2d 2d 20 75 73 2e 0a 40 20 2d   to.@ -- us..@ -
2510: 2d 0a 40 20 43 52 45 41 54 45 20 54 41 42 4c 45  -.@ CREATE TABLE
2520: 20 75 6e 63 6c 75 73 74 65 72 65 64 28 0a 40 20   unclustered(.@ 
2530: 20 20 72 69 64 20 49 4e 54 45 47 45 52 20 50 52    rid INTEGER PR
2540: 49 4d 41 52 59 20 4b 45 59 20 20 20 20 20 20 20  IMARY KEY       
2550: 20 20 2d 2d 20 52 65 63 6f 72 64 20 49 44 20 6f    -- Record ID o
2560: 66 20 74 68 65 20 75 6e 63 6c 75 73 74 65 72 65  f the unclustere
2570: 64 20 66 69 6c 65 0a 40 20 29 3b 0a 40 0a 40 20  d file.@ );.@.@ 
2580: 2d 2d 20 52 65 63 6f 72 64 73 20 77 68 69 63 68  -- Records which
2590: 20 68 61 76 65 20 6e 65 76 65 72 20 62 65 65 6e   have never been
25a0: 20 70 75 73 68 65 64 20 74 6f 20 61 6e 6f 74 68   pushed to anoth
25b0: 65 72 20 73 65 72 76 65 72 2e 20 20 54 68 69 73  er server.  This
25c0: 20 69 73 0a 40 20 2d 2d 20 75 73 65 64 20 74 6f   is.@ -- used to
25d0: 20 72 65 64 75 63 65 20 70 75 73 68 20 6f 70 65   reduce push ope
25e0: 72 61 74 69 6f 6e 73 20 74 6f 20 61 20 73 69 6e  rations to a sin
25f0: 67 6c 65 20 48 54 54 50 20 72 65 71 75 65 73 74  gle HTTP request
2600: 20 69 6e 20 74 68 65 0a 40 20 2d 2d 20 63 6f 6d   in the.@ -- com
2610: 6d 6f 6e 20 63 61 73 65 20 77 68 65 6e 20 6f 6e  mon case when on
2620: 65 20 72 65 70 6f 73 69 74 6f 72 79 20 6f 6e 6c  e repository onl
2630: 79 20 74 61 6c 6b 73 20 74 6f 20 61 20 73 69 6e  y talks to a sin
2640: 67 6c 65 20 73 65 72 76 65 72 2e 0a 40 20 2d 2d  gle server..@ --
2650: 0a 40 20 43 52 45 41 54 45 20 54 41 42 4c 45 20  .@ CREATE TABLE 
2660: 75 6e 73 65 6e 74 28 0a 40 20 20 20 72 69 64 20  unsent(.@   rid 
2670: 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20  INTEGER PRIMARY 
2680: 4b 45 59 20 20 20 20 20 20 20 20 20 2d 2d 20 52  KEY         -- R
2690: 65 63 6f 72 64 20 49 44 20 6f 66 20 74 68 65 20  ecord ID of the 
26a0: 70 68 61 6e 74 6f 6d 0a 40 20 29 3b 0a 40 0a 40  phantom.@ );.@.@
26b0: 20 2d 2d 20 45 61 63 68 20 62 61 73 65 6c 69 6e   -- Each baselin
26c0: 65 20 6f 72 20 6d 61 6e 69 66 65 73 74 20 63 61  e or manifest ca
26d0: 6e 20 68 61 76 65 20 6f 6e 65 20 6f 72 20 6d 6f  n have one or mo
26e0: 72 65 20 74 61 67 73 2e 20 20 41 20 74 61 67 0a  re tags.  A tag.
26f0: 40 20 2d 2d 20 69 73 20 64 65 66 69 6e 65 64 20  @ -- is defined 
2700: 62 79 20 61 20 72 6f 77 20 69 6e 20 74 68 65 20  by a row in the 
2710: 6e 65 78 74 20 74 61 62 6c 65 2e 0a 40 20 2d 2d  next table..@ --
2720: 20 0a 40 20 2d 2d 20 57 69 6b 69 20 70 61 67 65   .@ -- Wiki page
2730: 73 20 61 72 65 20 74 61 67 67 65 64 20 77 69 74  s are tagged wit
2740: 68 20 22 77 69 6b 69 2d 4e 41 4d 45 22 20 77 68  h "wiki-NAME" wh
2750: 65 72 65 20 4e 41 4d 45 20 69 73 20 74 68 65 20  ere NAME is the 
2760: 6e 61 6d 65 20 6f 66 0a 40 20 2d 2d 20 74 68 65  name of.@ -- the
2770: 20 77 69 6b 69 20 70 61 67 65 2e 20 20 54 69 63   wiki page.  Tic
2780: 6b 65 74 73 20 63 68 61 6e 67 65 73 20 61 72 65  kets changes are
2790: 20 74 61 67 67 65 64 20 77 69 74 68 20 22 74 69   tagged with "ti
27a0: 63 6b 65 74 2d 55 55 49 44 22 20 77 68 65 72 65  cket-UUID" where
27b0: 20 0a 40 20 2d 2d 20 55 55 49 44 20 69 73 20 74   .@ -- UUID is t
27c0: 68 65 20 69 6e 64 65 6e 74 69 66 69 65 72 20 6f  he indentifier o
27d0: 66 20 74 68 65 20 74 69 63 6b 65 74 2e 20 20 54  f the ticket.  T
27e0: 61 67 73 20 75 73 65 64 20 74 6f 20 61 73 73 69  ags used to assi
27f0: 67 6e 20 73 79 6d 62 6f 6c 69 63 0a 40 20 2d 2d  gn symbolic.@ --
2800: 20 6e 61 6d 65 73 20 74 6f 20 62 61 73 65 6c 69   names to baseli
2810: 6e 65 73 20 61 72 65 20 62 72 61 6e 63 68 65 73  nes are branches
2820: 20 61 72 65 20 6f 66 20 74 68 65 20 66 6f 72 6d   are of the form
2830: 20 22 73 79 6d 2d 4e 41 4d 45 22 20 77 68 65 72   "sym-NAME" wher
2840: 65 0a 40 20 2d 2d 20 4e 41 4d 45 20 69 73 20 74  e.@ -- NAME is t
2850: 68 65 20 73 79 6d 62 6f 6c 69 63 20 6e 61 6d 65  he symbolic name
2860: 2e 0a 40 20 2d 2d 0a 40 20 43 52 45 41 54 45 20  ..@ --.@ CREATE 
2870: 54 41 42 4c 45 20 74 61 67 28 0a 40 20 20 20 74  TABLE tag(.@   t
2880: 61 67 69 64 20 49 4e 54 45 47 45 52 20 50 52 49  agid INTEGER PRI
2890: 4d 41 52 59 20 4b 45 59 2c 20 20 20 20 20 20 20  MARY KEY,       
28a0: 2d 2d 20 4e 75 6d 65 72 69 63 20 74 61 67 20 49  -- Numeric tag I
28b0: 44 0a 40 20 20 20 74 61 67 6e 61 6d 65 20 54 45  D.@   tagname TE
28c0: 58 54 20 55 4e 49 51 55 45 20 20 20 20 20 20 20  XT UNIQUE       
28d0: 20 20 20 20 20 20 20 2d 2d 20 54 61 67 20 6e 61         -- Tag na
28e0: 6d 65 2e 0a 40 20 29 3b 0a 40 20 49 4e 53 45 52  me..@ );.@ INSER
28f0: 54 20 49 4e 54 4f 20 74 61 67 20 56 41 4c 55 45  T INTO tag VALUE
2900: 53 28 31 2c 20 27 62 67 63 6f 6c 6f 72 27 29 3b  S(1, 'bgcolor');
2910: 20 20 20 20 20 20 20 20 20 2d 2d 20 54 41 47 5f           -- TAG_
2920: 42 47 43 4f 4c 4f 52 0a 40 20 49 4e 53 45 52 54  BGCOLOR.@ INSERT
2930: 20 49 4e 54 4f 20 74 61 67 20 56 41 4c 55 45 53   INTO tag VALUES
2940: 28 32 2c 20 27 63 6f 6d 6d 65 6e 74 27 29 3b 20  (2, 'comment'); 
2950: 20 20 20 20 20 20 20 20 2d 2d 20 54 41 47 5f 43          -- TAG_C
2960: 4f 4d 4d 45 4e 54 0a 40 20 49 4e 53 45 52 54 20  OMMENT.@ INSERT 
2970: 49 4e 54 4f 20 74 61 67 20 56 41 4c 55 45 53 28  INTO tag VALUES(
2980: 33 2c 20 27 75 73 65 72 27 29 3b 20 20 20 20 20  3, 'user');     
2990: 20 20 20 20 20 20 20 2d 2d 20 54 41 47 5f 55 53         -- TAG_US
29a0: 45 52 0a 40 20 49 4e 53 45 52 54 20 49 4e 54 4f  ER.@ INSERT INTO
29b0: 20 74 61 67 20 56 41 4c 55 45 53 28 34 2c 20 27   tag VALUES(4, '
29c0: 64 61 74 65 27 29 3b 20 20 20 20 20 20 20 20 20  date');         
29d0: 20 20 20 2d 2d 20 54 41 47 5f 44 41 54 45 0a 40     -- TAG_DATE.@
29e0: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 61 67   INSERT INTO tag
29f0: 20 56 41 4c 55 45 53 28 35 2c 20 27 68 69 64 64   VALUES(5, 'hidd
2a00: 65 6e 27 29 3b 20 20 20 20 20 20 20 20 20 20 2d  en');          -
2a10: 2d 20 54 41 47 5f 48 49 44 44 45 4e 0a 40 20 49  - TAG_HIDDEN.@ I
2a20: 4e 53 45 52 54 20 49 4e 54 4f 20 74 61 67 20 56  NSERT INTO tag V
2a30: 41 4c 55 45 53 28 36 2c 20 27 70 72 69 76 61 74  ALUES(6, 'privat
2a40: 65 27 29 3b 20 20 20 20 20 20 20 20 20 2d 2d 20  e');         -- 
2a50: 54 41 47 5f 50 52 49 56 41 54 45 0a 40 20 49 4e  TAG_PRIVATE.@ IN
2a60: 53 45 52 54 20 49 4e 54 4f 20 74 61 67 20 56 41  SERT INTO tag VA
2a70: 4c 55 45 53 28 37 2c 20 27 63 6c 75 73 74 65 72  LUES(7, 'cluster
2a80: 27 29 3b 20 20 20 20 20 20 20 20 20 2d 2d 20 54  ');         -- T
2a90: 41 47 5f 43 4c 55 53 54 45 52 0a 40 20 49 4e 53  AG_CLUSTER.@ INS
2aa0: 45 52 54 20 49 4e 54 4f 20 74 61 67 20 56 41 4c  ERT INTO tag VAL
2ab0: 55 45 53 28 38 2c 20 27 62 72 61 6e 63 68 27 29  UES(8, 'branch')
2ac0: 3b 20 20 20 20 20 20 20 20 20 20 2d 2d 20 54 41  ;          -- TA
2ad0: 47 5f 42 52 41 4e 43 48 0a 40 20 49 4e 53 45 52  G_BRANCH.@ INSER
2ae0: 54 20 49 4e 54 4f 20 74 61 67 20 56 41 4c 55 45  T INTO tag VALUE
2af0: 53 28 39 2c 20 27 63 6c 6f 73 65 64 27 29 3b 20  S(9, 'closed'); 
2b00: 20 20 20 20 20 20 20 20 20 2d 2d 20 54 41 47 5f           -- TAG_
2b10: 43 4c 4f 53 45 44 0a 40 0a 40 20 2d 2d 20 41 73  CLOSED.@.@ -- As
2b20: 73 69 67 6e 6d 65 6e 74 73 20 6f 66 20 74 61 67  signments of tag
2b30: 73 20 74 6f 20 62 61 73 65 6c 69 6e 65 73 2e 20  s to baselines. 
2b40: 20 4e 6f 74 65 20 74 68 61 74 20 77 65 20 61 6c   Note that we al
2b50: 6c 6f 77 20 74 61 67 73 20 74 6f 0a 40 20 2d 2d  low tags to.@ --
2b60: 20 68 61 76 65 20 76 61 6c 75 65 73 20 61 73 73   have values ass
2b70: 69 67 6e 65 64 20 74 6f 20 74 68 65 6d 2e 20 20  igned to them.  
2b80: 53 6f 20 77 65 20 61 72 65 20 6e 6f 74 20 72 65  So we are not re
2b90: 61 6c 6c 79 20 64 65 61 6c 69 6e 67 20 77 69 74  ally dealing wit
2ba0: 68 0a 40 20 2d 2d 20 74 61 67 73 20 68 65 72 65  h.@ -- tags here
2bb0: 2e 20 20 54 68 65 73 65 20 61 72 65 20 72 65 61  .  These are rea
2bc0: 6c 6c 79 20 70 72 6f 70 65 72 74 69 65 73 2e 20  lly properties. 
2bd0: 20 42 75 74 20 77 65 20 61 72 65 20 67 6f 69 6e   But we are goin
2be0: 67 20 74 6f 0a 40 20 2d 2d 20 6b 65 65 70 20 63  g to.@ -- keep c
2bf0: 61 6c 6c 69 6e 67 20 74 68 65 6d 20 74 61 67 73  alling them tags
2c00: 20 62 65 63 61 75 73 65 20 69 6e 20 6d 61 6e 79   because in many
2c10: 20 63 61 73 65 73 20 74 68 65 20 76 61 6c 75 65   cases the value
2c20: 20 69 73 20 69 67 6e 6f 72 65 64 2e 0a 40 20 2d   is ignored..@ -
2c30: 2d 0a 40 20 43 52 45 41 54 45 20 54 41 42 4c 45  -.@ CREATE TABLE
2c40: 20 74 61 67 78 72 65 66 28 0a 40 20 20 20 74 61   tagxref(.@   ta
2c50: 67 69 64 20 49 4e 54 45 47 45 52 20 52 45 46 45  gid INTEGER REFE
2c60: 52 45 4e 43 45 53 20 74 61 67 2c 20 20 20 2d 2d  RENCES tag,   --
2c70: 20 54 68 65 20 74 61 67 20 74 68 61 74 20 61 64   The tag that ad
2c80: 64 65 64 20 6f 72 20 72 65 6d 6f 76 65 64 0a 40  ded or removed.@
2c90: 20 20 20 74 61 67 74 79 70 65 20 49 4e 54 45 47     tagtype INTEG
2ca0: 45 52 2c 20 20 20 20 20 20 20 20 20 20 20 20 20  ER,             
2cb0: 20 20 20 2d 2d 20 30 3a 63 61 6e 63 65 6c 20 20     -- 0:cancel  
2cc0: 31 3a 73 69 6e 67 6c 65 20 20 32 3a 62 72 61 6e  1:single  2:bran
2cd0: 63 68 0a 40 20 20 20 73 72 63 69 64 20 49 4e 54  ch.@   srcid INT
2ce0: 45 47 45 52 20 52 45 46 45 52 45 4e 43 45 53 20  EGER REFERENCES 
2cf0: 62 6c 6f 62 2c 20 20 2d 2d 20 41 72 74 69 66 61  blob,  -- Artifa
2d00: 63 74 20 6f 66 20 74 61 67 2e 20 30 20 66 6f 72  ct of tag. 0 for
2d10: 20 70 72 6f 70 61 67 61 74 65 64 20 74 61 67 73   propagated tags
2d20: 0a 40 20 20 20 6f 72 69 67 69 64 20 49 4e 54 45  .@   origid INTE
2d30: 47 45 52 20 52 45 46 45 52 45 4e 43 45 53 20 62  GER REFERENCES b
2d40: 6c 6f 62 2c 20 2d 2d 20 63 68 65 63 6b 2d 69 6e  lob, -- check-in
2d50: 20 68 6f 6c 64 69 6e 67 20 70 72 6f 70 61 67 61   holding propaga
2d60: 74 65 64 20 74 61 67 0a 40 20 20 20 76 61 6c 75  ted tag.@   valu
2d70: 65 20 54 45 58 54 2c 20 20 20 20 20 20 20 20 20  e TEXT,         
2d80: 20 20 20 20 20 20 20 20 20 20 20 20 2d 2d 20 56              -- V
2d90: 61 6c 75 65 20 6f 66 20 74 68 65 20 74 61 67 2e  alue of the tag.
2da0: 20 20 4d 69 67 68 74 20 62 65 20 4e 55 4c 4c 2e    Might be NULL.
2db0: 0a 40 20 20 20 6d 74 69 6d 65 20 54 49 4d 45 53  .@   mtime TIMES
2dc0: 54 41 4d 50 2c 20 20 20 20 20 20 20 20 20 20 20  TAMP,           
2dd0: 20 20 20 20 20 2d 2d 20 54 69 6d 65 20 6f 66 20       -- Time of 
2de0: 61 64 64 69 74 69 6f 6e 20 6f 72 20 72 65 6d 6f  addition or remo
2df0: 76 61 6c 0a 40 20 20 20 72 69 64 20 49 4e 54 45  val.@   rid INTE
2e00: 47 45 52 20 52 45 46 45 52 45 4e 43 45 20 62 6c  GER REFERENCE bl
2e10: 6f 62 2c 20 20 20 20 20 2d 2d 20 41 72 74 69 66  ob,     -- Artif
2e20: 61 63 74 20 74 61 67 20 69 73 20 61 70 70 6c 69  act tag is appli
2e30: 65 64 20 74 6f 0a 40 20 20 20 55 4e 49 51 55 45  ed to.@   UNIQUE
2e40: 28 72 69 64 2c 20 74 61 67 69 64 29 0a 40 20 29  (rid, tagid).@ )
2e50: 3b 0a 40 20 43 52 45 41 54 45 20 49 4e 44 45 58  ;.@ CREATE INDEX
2e60: 20 74 61 67 78 72 65 66 5f 69 31 20 4f 4e 20 74   tagxref_i1 ON t
2e70: 61 67 78 72 65 66 28 74 61 67 69 64 2c 20 6d 74  agxref(tagid, mt
2e80: 69 6d 65 29 3b 0a 40 0a 40 20 2d 2d 20 54 65 6d  ime);.@.@ -- Tem
2e90: 70 6c 61 74 65 20 66 6f 72 20 74 68 65 20 54 49  plate for the TI
2ea0: 43 4b 45 54 20 74 61 62 6c 65 0a 40 20 2d 2d 0a  CKET table.@ --.
2eb0: 40 20 2d 2d 20 4e 42 3a 20 77 68 65 6e 20 63 68  @ -- NB: when ch
2ec0: 61 6e 67 69 6e 67 20 74 68 65 20 73 63 68 65 6d  anging the schem
2ed0: 61 20 6f 66 20 74 68 65 20 54 49 43 4b 45 54 20  a of the TICKET 
2ee0: 74 61 62 6c 65 20 68 65 72 65 2c 20 61 6c 73 6f  table here, also
2ef0: 20 6d 61 6b 65 20 74 68 65 0a 40 20 2d 2d 20 73   make the.@ -- s
2f00: 61 6d 65 20 63 68 61 6e 67 65 20 69 6e 20 74 6b  ame change in tk
2f10: 74 73 65 74 75 70 2e 63 2e 0a 40 20 2d 2d 0a 40  tsetup.c..@ --.@
2f20: 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 69   CREATE TABLE ti
2f30: 63 6b 65 74 28 0a 40 20 20 20 2d 2d 20 44 6f 20  cket(.@   -- Do 
2f40: 6e 6f 74 20 63 68 61 6e 67 65 20 61 6e 79 20 63  not change any c
2f50: 6f 6c 75 6d 6e 20 74 68 61 74 20 62 65 67 69 6e  olumn that begin
2f60: 73 20 77 69 74 68 20 74 6b 74 5f 0a 40 20 20 20  s with tkt_.@   
2f70: 74 6b 74 5f 69 64 20 49 4e 54 45 47 45 52 20 50  tkt_id INTEGER P
2f80: 52 49 4d 41 52 59 20 4b 45 59 2c 0a 40 20 20 20  RIMARY KEY,.@   
2f90: 74 6b 74 5f 75 75 69 64 20 54 45 58 54 20 55 4e  tkt_uuid TEXT UN
2fa0: 49 51 55 45 2c 0a 40 20 20 20 74 6b 74 5f 6d 74  IQUE,.@   tkt_mt
2fb0: 69 6d 65 20 44 41 54 45 2c 0a 40 20 20 20 2d 2d  ime DATE,.@   --
2fc0: 20 41 64 64 20 61 73 20 6d 61 6e 79 20 66 69 65   Add as many fie
2fd0: 6c 64 20 61 73 20 72 65 71 75 69 72 65 64 20 62  ld as required b
2fe0: 65 6c 6f 77 20 74 68 69 73 20 6c 69 6e 65 0a 40  elow this line.@
2ff0: 20 20 20 74 79 70 65 20 54 45 58 54 2c 0a 40 20     type TEXT,.@ 
3000: 20 20 73 74 61 74 75 73 20 54 45 58 54 2c 0a 40    status TEXT,.@
3010: 20 20 20 73 75 62 73 79 73 74 65 6d 20 54 45 58     subsystem TEX
3020: 54 2c 0a 40 20 20 20 70 72 69 6f 72 69 74 79 20  T,.@   priority 
3030: 54 45 58 54 2c 0a 40 20 20 20 73 65 76 65 72 69  TEXT,.@   severi
3040: 74 79 20 54 45 58 54 2c 0a 40 20 20 20 66 6f 75  ty TEXT,.@   fou
3050: 6e 64 69 6e 20 54 45 58 54 2c 0a 40 20 20 20 70  ndin TEXT,.@   p
3060: 72 69 76 61 74 65 5f 63 6f 6e 74 61 63 74 20 54  rivate_contact T
3070: 45 58 54 2c 0a 40 20 20 20 72 65 73 6f 6c 75 74  EXT,.@   resolut
3080: 69 6f 6e 20 54 45 58 54 2c 0a 40 20 20 20 74 69  ion TEXT,.@   ti
3090: 74 6c 65 20 54 45 58 54 2c 0a 40 20 20 20 63 6f  tle TEXT,.@   co
30a0: 6d 6d 65 6e 74 20 54 45 58 54 0a 40 20 29 3b 0a  mment TEXT.@ );.
30b0: 3b 0a 0a 2f 2a 0a 2a 2a 20 50 72 65 64 65 66 69  ;../*.** Predefi
30c0: 6e 65 64 20 74 61 67 69 64 20 76 61 6c 75 65 73  ned tagid values
30d0: 0a 2a 2f 0a 23 69 66 20 49 4e 54 45 52 46 41 43  .*/.#if INTERFAC
30e0: 45 0a 23 20 64 65 66 69 6e 65 20 54 41 47 5f 42  E.# define TAG_B
30f0: 47 43 4f 4c 4f 52 20 20 20 20 31 20 20 20 20 20  GCOLOR    1     
3100: 2f 2a 20 53 65 74 20 74 68 65 20 62 61 63 6b 67  /* Set the backg
3110: 72 6f 75 6e 64 20 63 6f 6c 6f 72 20 66 6f 72 20  round color for 
3120: 64 69 73 70 6c 61 79 20 2a 2f 0a 23 20 64 65 66  display */.# def
3130: 69 6e 65 20 54 41 47 5f 43 4f 4d 4d 45 4e 54 20  ine TAG_COMMENT 
3140: 20 20 20 32 20 20 20 20 20 2f 2a 20 54 68 65 20     2     /* The 
3150: 63 68 65 63 6b 2d 69 6e 20 63 6f 6d 6d 65 6e 74  check-in comment
3160: 20 2a 2f 0a 23 20 64 65 66 69 6e 65 20 54 41 47   */.# define TAG
3170: 5f 55 53 45 52 20 20 20 20 20 20 20 33 20 20 20  _USER       3   
3180: 20 20 2f 2a 20 55 73 65 72 20 77 68 6f 20 6d 61    /* User who ma
3190: 64 65 20 61 20 63 68 65 63 6b 69 6e 67 20 2a 2f  de a checking */
31a0: 0a 23 20 64 65 66 69 6e 65 20 54 41 47 5f 44 41  .# define TAG_DA
31b0: 54 45 20 20 20 20 20 20 20 34 20 20 20 20 20 2f  TE       4     /
31c0: 2a 20 54 68 65 20 64 61 74 65 20 6f 66 20 61 20  * The date of a 
31d0: 63 68 65 63 6b 2d 69 6e 20 2a 2f 0a 23 20 64 65  check-in */.# de
31e0: 66 69 6e 65 20 54 41 47 5f 48 49 44 44 45 4e 20  fine TAG_HIDDEN 
31f0: 20 20 20 20 35 20 20 20 20 20 2f 2a 20 44 6f 20      5     /* Do 
3200: 6e 6f 74 20 64 69 73 70 6c 61 79 20 6f 72 20 73  not display or s
3210: 79 6e 63 20 2a 2f 0a 23 20 64 65 66 69 6e 65 20  ync */.# define 
3220: 54 41 47 5f 50 52 49 56 41 54 45 20 20 20 20 36  TAG_PRIVATE    6
3230: 20 20 20 20 20 2f 2a 20 44 69 73 70 6c 61 79 20       /* Display 
3240: 62 75 74 20 64 6f 20 6e 6f 74 20 73 79 6e 63 20  but do not sync 
3250: 2a 2f 0a 23 20 64 65 66 69 6e 65 20 54 41 47 5f  */.# define TAG_
3260: 43 4c 55 53 54 45 52 20 20 20 20 37 20 20 20 20  CLUSTER    7    
3270: 20 2f 2a 20 41 20 63 6c 75 73 74 65 72 20 2a 2f   /* A cluster */
3280: 0a 23 20 64 65 66 69 6e 65 20 54 41 47 5f 42 52  .# define TAG_BR
3290: 41 4e 43 48 20 20 20 20 20 38 20 20 20 20 20 2f  ANCH     8     /
32a0: 2a 20 56 61 6c 75 65 20 69 73 20 6e 61 6d 65 20  * Value is name 
32b0: 6f 66 20 74 68 65 20 63 75 72 72 65 6e 74 20 62  of the current b
32c0: 72 61 6e 63 68 20 2a 2f 0a 23 20 64 65 66 69 6e  ranch */.# defin
32d0: 65 20 54 41 47 5f 43 4c 4f 53 45 44 20 20 20 20  e TAG_CLOSED    
32e0: 20 39 20 20 20 20 20 2f 2a 20 44 6f 20 6e 6f 74   9     /* Do not
32f0: 20 64 69 73 70 6c 61 79 20 74 68 69 73 20 63 68   display this ch
3300: 65 63 6b 2d 69 6e 20 61 73 20 61 20 6c 65 61 66  eck-in as a leaf
3310: 20 2a 2f 0a 23 65 6e 64 69 66 0a 23 69 66 20 45   */.#endif.#if E
3320: 58 50 4f 52 54 5f 49 4e 54 45 52 46 41 43 45 0a  XPORT_INTERFACE.
3330: 23 20 64 65 66 69 6e 65 20 4d 41 58 5f 49 4e 54  # define MAX_INT
3340: 5f 54 41 47 20 20 20 20 39 20 20 20 20 20 2f 2a  _TAG    9     /*
3350: 20 54 68 65 20 6c 61 72 67 65 73 74 20 70 72 65   The largest pre
3360: 2d 61 73 73 69 67 6e 65 64 20 74 61 67 20 69 64  -assigned tag id
3370: 20 2a 2f 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a   */.#endif../*.*
3380: 2a 20 54 68 65 20 73 63 68 65 6d 61 20 66 6f 72  * The schema for
3390: 20 74 68 65 20 6c 6f 63 61 74 65 20 46 4f 53 53   the locate FOSS
33a0: 49 4c 20 64 61 74 61 62 61 73 65 20 66 69 6c 65  IL database file
33b0: 20 66 6f 75 6e 64 20 61 74 20 74 68 65 20 72 6f   found at the ro
33c0: 6f 74 0a 2a 2a 20 6f 66 20 76 65 72 79 20 63 68  ot.** of very ch
33d0: 65 63 6b 2d 6f 75 74 2e 20 20 54 68 69 73 20 64  eck-out.  This d
33e0: 61 74 61 62 61 73 65 20 63 6f 6e 74 61 69 6e 73  atabase contains
33f0: 20 74 68 65 20 63 6f 6d 70 6c 65 74 65 20 73 74   the complete st
3400: 61 74 65 20 6f 66 0a 2a 2a 20 74 68 65 20 63 68  ate of.** the ch
3410: 65 63 6b 6f 75 74 2e 0a 2a 2f 0a 63 6f 6e 73 74  eckout..*/.const
3420: 20 63 68 61 72 20 7a 4c 6f 63 61 6c 53 63 68 65   char zLocalSche
3430: 6d 61 5b 5d 20 3d 0a 40 20 2d 2d 20 54 68 65 20  ma[] =.@ -- The 
3440: 56 56 41 52 20 74 61 62 6c 65 20 68 6f 6c 64 73  VVAR table holds
3450: 20 6d 69 73 63 65 6c 6c 61 6e 6f 75 73 20 69 6e   miscellanous in
3460: 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20  formation about 
3470: 74 68 65 20 6c 6f 63 61 6c 20 64 61 74 61 62 61  the local databa
3480: 73 65 0a 40 20 2d 2d 20 69 6e 20 74 68 65 20 66  se.@ -- in the f
3490: 6f 72 6d 20 6f 66 20 6e 61 6d 65 2d 76 61 6c 75  orm of name-valu
34a0: 65 20 70 61 69 72 73 2e 20 20 54 68 69 73 20 69  e pairs.  This i
34b0: 73 20 73 69 6d 69 6c 61 72 20 74 6f 20 74 68 65  s similar to the
34c0: 20 56 41 52 20 74 61 62 6c 65 0a 40 20 2d 2d 20   VAR table.@ -- 
34d0: 74 61 62 6c 65 20 69 6e 20 74 68 65 20 72 65 70  table in the rep
34e0: 6f 73 69 74 6f 72 79 20 65 78 63 65 70 74 20 74  ository except t
34f0: 68 61 74 20 74 68 69 73 20 74 61 62 6c 65 20 68  hat this table h
3500: 6f 6c 64 73 20 69 6e 66 6f 72 6d 61 74 69 6f 6e  olds information
3510: 20 74 68 61 74 0a 40 20 2d 2d 20 69 73 20 73 70   that.@ -- is sp
3520: 65 63 69 66 69 63 20 74 6f 20 74 68 65 20 6c 6f  ecific to the lo
3530: 63 61 6c 20 63 68 65 63 6b 6f 75 74 2e 0a 40 20  cal checkout..@ 
3540: 2d 2d 0a 40 20 2d 2d 20 49 6d 70 6f 72 74 61 6e  --.@ -- Importan
3550: 74 20 56 61 72 69 61 62 6c 65 73 3a 0a 40 20 2d  t Variables:.@ -
3560: 2d 0a 40 20 2d 2d 20 20 20 20 20 72 65 70 6f 73  -.@ --     repos
3570: 69 74 6f 72 79 20 20 20 20 20 20 20 20 46 75 6c  itory        Ful
3580: 6c 20 70 61 74 68 6e 61 6d 65 20 6f 66 20 74 68  l pathname of th
3590: 65 20 72 65 70 6f 73 69 74 6f 72 79 20 64 61 74  e repository dat
35a0: 61 62 61 73 65 0a 40 20 2d 2d 20 20 20 20 20 75  abase.@ --     u
35b0: 73 65 72 2d 69 64 20 20 20 20 20 20 20 20 20 20  ser-id          
35c0: 20 55 73 65 72 69 64 20 74 6f 20 75 73 65 0a 40   Userid to use.@
35d0: 20 2d 2d 0a 40 20 43 52 45 41 54 45 20 54 41 42   --.@ CREATE TAB
35e0: 4c 45 20 76 76 61 72 28 0a 40 20 20 20 6e 61 6d  LE vvar(.@   nam
35f0: 65 20 54 45 58 54 20 50 52 49 4d 41 52 59 20 4b  e TEXT PRIMARY K
3600: 45 59 20 4e 4f 54 20 4e 55 4c 4c 2c 20 20 2d 2d  EY NOT NULL,  --
3610: 20 50 72 69 6d 61 72 79 20 6e 61 6d 65 20 6f 66   Primary name of
3620: 20 74 68 65 20 65 6e 74 72 79 0a 40 20 20 20 76   the entry.@   v
3630: 61 6c 75 65 20 43 4c 4f 42 2c 20 20 20 20 20 20  alue CLOB,      
3640: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
3650: 2d 2d 20 43 6f 6e 74 65 6e 74 20 6f 66 20 74 68  -- Content of th
3660: 65 20 6e 61 6d 65 64 20 70 61 72 61 6d 65 74 65  e named paramete
3670: 72 0a 40 20 20 20 43 48 45 43 4b 28 20 74 79 70  r.@   CHECK( typ
3680: 65 6f 66 28 6e 61 6d 65 29 3d 27 74 65 78 74 27  eof(name)='text'
3690: 20 41 4e 44 20 6c 65 6e 67 74 68 28 6e 61 6d 65   AND length(name
36a0: 29 3e 3d 31 20 29 0a 40 20 29 3b 0a 40 0a 40 20  )>=1 ).@ );.@.@ 
36b0: 2d 2d 20 45 61 63 68 20 65 6e 74 72 79 20 69 6e  -- Each entry in
36c0: 20 74 68 65 20 76 66 69 6c 65 20 74 61 62 6c 65   the vfile table
36d0: 20 72 65 70 72 65 73 65 6e 74 73 20 61 20 73 69   represents a si
36e0: 6e 67 6c 65 20 66 69 6c 65 20 69 6e 20 74 68 65  ngle file in the
36f0: 0a 40 20 2d 2d 20 63 75 72 72 65 6e 74 20 63 68  .@ -- current ch
3700: 65 63 6b 6f 75 74 2e 0a 40 20 2d 2d 0a 40 20 2d  eckout..@ --.@ -
3710: 2d 20 54 68 65 20 66 69 6c 65 2e 72 69 64 20 66  - The file.rid f
3720: 69 65 6c 64 20 69 73 20 30 20 66 6f 72 20 66 69  ield is 0 for fi
3730: 6c 65 73 20 6f 72 20 66 6f 6c 64 65 72 73 20 74  les or folders t
3740: 68 61 74 20 68 61 76 65 20 62 65 65 6e 0a 40 20  hat have been.@ 
3750: 2d 2d 20 61 64 64 65 64 20 62 75 74 20 6e 6f 74  -- added but not
3760: 20 79 65 74 20 63 6f 6d 6d 69 74 74 65 64 2e 0a   yet committed..
3770: 40 20 2d 2d 0a 40 20 2d 2d 20 56 66 69 6c 65 2e  @ --.@ -- Vfile.
3780: 63 68 6e 67 65 64 20 69 73 20 30 20 66 6f 72 20  chnged is 0 for 
3790: 75 6e 6d 6f 64 69 66 69 65 64 20 66 69 6c 65 73  unmodified files
37a0: 2c 20 31 20 66 6f 72 20 66 69 6c 65 73 20 74 68  , 1 for files th
37b0: 61 74 20 68 61 76 65 0a 40 20 2d 2d 20 62 65 65  at have.@ -- bee
37c0: 6e 20 65 64 69 74 65 64 20 6f 72 20 77 68 69 63  n edited or whic
37d0: 68 20 68 61 76 65 20 62 65 65 6e 20 73 75 62 6a  h have been subj
37e0: 65 63 74 65 64 20 74 6f 20 61 20 33 2d 77 61 79  ected to a 3-way
37f0: 20 6d 65 72 67 65 2e 20 20 0a 40 20 2d 2d 20 56   merge.  .@ -- V
3800: 66 69 6c 65 2e 63 68 6e 67 65 64 20 69 73 20 32  file.chnged is 2
3810: 20 69 66 20 74 68 65 20 66 69 6c 65 20 68 61 73   if the file has
3820: 20 62 65 65 6e 20 72 65 70 6c 61 63 65 64 20 66   been replaced f
3830: 72 6f 6d 20 61 20 64 69 66 66 65 72 65 6e 74 0a  rom a different.
3840: 40 20 2d 2d 20 76 65 72 73 69 6f 6e 20 62 79 20  @ -- version by 
3850: 74 68 65 20 6d 65 72 67 65 20 61 6e 64 20 33 20  the merge and 3 
3860: 69 66 20 74 68 65 20 66 69 6c 65 20 68 61 73 20  if the file has 
3870: 62 65 65 6e 20 61 64 64 65 64 20 62 79 20 61 20  been added by a 
3880: 6d 65 72 67 65 2e 0a 40 20 2d 2d 20 54 68 65 20  merge..@ -- The 
3890: 64 69 66 66 65 72 65 6e 63 65 20 62 65 74 77 65  difference betwe
38a0: 65 6e 20 76 66 69 6c 65 2e 63 68 6e 67 65 64 3d  en vfile.chnged=
38b0: 3d 32 20 61 6e 64 20 61 20 72 65 67 75 6c 61 72  =2 and a regular
38c0: 20 61 64 64 20 69 73 20 74 68 61 74 0a 40 20 2d   add is that.@ -
38d0: 2d 20 77 69 74 68 20 76 66 69 6c 65 2e 63 68 6e  - with vfile.chn
38e0: 67 65 64 3d 3d 32 20 77 65 20 6b 6e 6f 77 20 74  ged==2 we know t
38f0: 68 61 74 20 74 68 65 20 63 75 72 72 65 6e 74 20  hat the current 
3900: 76 65 72 73 69 6f 6e 20 6f 66 20 74 68 65 20 66  version of the f
3910: 69 6c 65 0a 40 20 2d 2d 20 69 73 20 61 6c 72 65  ile.@ -- is alre
3920: 61 64 79 20 69 6e 20 74 68 65 20 72 65 70 6f 73  ady in the repos
3930: 69 74 6f 72 79 2e 0a 40 20 2d 2d 20 0a 40 20 2d  itory..@ -- .@ -
3940: 2d 0a 40 20 43 52 45 41 54 45 20 54 41 42 4c 45  -.@ CREATE TABLE
3950: 20 76 66 69 6c 65 28 0a 40 20 20 20 69 64 20 49   vfile(.@   id I
3960: 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b  NTEGER PRIMARY K
3970: 45 59 2c 20 20 20 20 20 20 20 20 20 20 20 2d 2d  EY,           --
3980: 20 49 44 20 6f 66 20 74 68 65 20 63 68 65 63 6b   ID of the check
3990: 65 64 20 6f 75 74 20 66 69 6c 65 0a 40 20 20 20  ed out file.@   
39a0: 76 69 64 20 49 4e 54 45 47 45 52 20 52 45 46 45  vid INTEGER REFE
39b0: 52 45 4e 43 45 53 20 62 6c 6f 62 2c 20 20 20 20  RENCES blob,    
39c0: 20 20 2d 2d 20 54 68 65 20 62 61 73 65 6c 69 6e    -- The baselin
39d0: 65 20 74 68 69 73 20 66 69 6c 65 20 69 73 20 70  e this file is p
39e0: 61 72 74 20 6f 66 2e 0a 40 20 20 20 63 68 6e 67  art of..@   chng
39f0: 65 64 20 49 4e 54 20 44 45 46 41 55 4c 54 20 30  ed INT DEFAULT 0
3a00: 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 2d 2d  ,             --
3a10: 20 30 3a 75 6e 63 68 6e 67 65 64 20 31 3a 65 64   0:unchnged 1:ed
3a20: 69 74 65 64 20 32 3a 6d 2d 63 68 6e 67 20 33 3a  ited 2:m-chng 3:
3a30: 6d 2d 61 64 64 0a 40 20 20 20 64 65 6c 65 74 65  m-add.@   delete
3a40: 64 20 42 4f 4f 4c 45 41 4e 20 44 45 46 41 55 4c  d BOOLEAN DEFAUL
3a50: 54 20 30 2c 20 20 20 20 20 20 20 20 2d 2d 20 54  T 0,        -- T
3a60: 72 75 65 20 69 66 20 64 65 6c 65 74 65 64 20 0a  rue if deleted .
3a70: 40 20 20 20 72 69 64 20 49 4e 54 45 47 45 52 2c  @   rid INTEGER,
3a80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
3a90: 20 20 20 20 20 20 2d 2d 20 4f 72 69 67 69 6e 61        -- Origina
3aa0: 6c 6c 79 20 66 72 6f 6d 20 74 68 69 73 20 72 65  lly from this re
3ab0: 70 6f 73 69 74 6f 72 79 20 72 65 63 6f 72 64 0a  pository record.
3ac0: 40 20 20 20 6d 72 69 64 20 49 4e 54 45 47 45 52  @   mrid INTEGER
3ad0: 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  ,               
3ae0: 20 20 20 20 20 20 2d 2d 20 42 61 73 65 64 20 6f        -- Based o
3af0: 6e 20 74 68 69 73 20 72 65 63 6f 72 64 20 64 75  n this record du
3b00: 65 20 74 6f 20 61 20 6d 65 72 67 65 0a 40 20 20  e to a merge.@  
3b10: 20 6d 74 69 6d 65 20 49 4e 54 45 47 45 52 2c 20   mtime INTEGER, 
3b20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
3b30: 20 20 20 2d 2d 20 4d 6f 64 69 66 69 63 61 74 69     -- Modificati
3b40: 6f 6e 20 74 69 6d 65 20 6f 66 20 66 69 6c 65 20  on time of file 
3b50: 6f 6e 20 64 69 73 6b 0a 40 20 20 20 70 61 74 68  on disk.@   path
3b60: 6e 61 6d 65 20 54 45 58 54 2c 20 20 20 20 20 20  name TEXT,      
3b70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2d 2d                --
3b80: 20 46 75 6c 6c 20 70 61 74 68 6e 61 6d 65 20 72   Full pathname r
3b90: 65 6c 61 74 69 76 65 20 74 6f 20 72 6f 6f 74 0a  elative to root.
3ba0: 40 20 20 20 6f 72 69 67 6e 61 6d 65 20 54 45 58  @   origname TEX
3bb0: 54 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 20  T,              
3bc0: 20 20 20 20 20 20 2d 2d 20 4f 72 69 67 69 6e 61        -- Origina
3bd0: 6c 20 70 61 74 68 6e 61 6d 65 2e 20 4e 55 4c 4c  l pathname. NULL
3be0: 20 69 66 20 75 6e 63 68 61 6e 67 65 64 0a 40 20   if unchanged.@ 
3bf0: 20 20 55 4e 49 51 55 45 28 70 61 74 68 6e 61 6d    UNIQUE(pathnam
3c00: 65 2c 76 69 64 29 0a 40 20 29 3b 0a 40 0a 40 20  e,vid).@ );.@.@ 
3c10: 2d 2d 20 54 68 69 73 20 74 61 62 6c 65 20 68 6f  -- This table ho
3c20: 6c 64 73 20 61 20 72 65 63 6f 72 64 20 6f 66 20  lds a record of 
3c30: 75 6e 63 6f 6d 6d 69 74 74 65 64 20 6d 65 72 67  uncommitted merg
3c40: 65 73 20 69 6e 20 74 68 65 20 6c 6f 63 61 6c 0a  es in the local.
3c50: 40 20 2d 2d 20 66 69 6c 65 20 74 72 65 65 2e 20  @ -- file tree. 
3c60: 20 49 66 20 61 20 56 46 49 4c 45 20 65 6e 74 72   If a VFILE entr
3c70: 79 20 77 69 74 68 20 69 64 20 68 61 73 20 6d 65  y with id has me
3c80: 72 67 65 64 20 77 69 74 68 20 61 6e 6f 74 68 65  rged with anothe
3c90: 72 0a 40 20 2d 2d 20 72 65 63 6f 72 64 2c 20 74  r.@ -- record, t
3ca0: 68 65 72 65 20 69 73 20 61 6e 20 65 6e 74 72 79  here is an entry
3cb0: 20 69 6e 20 74 68 69 73 20 74 61 62 6c 65 20 77   in this table w
3cc0: 69 74 68 20 28 69 64 2c 6d 65 72 67 65 29 20 77  ith (id,merge) w
3cd0: 68 65 72 65 0a 40 20 2d 2d 20 6d 65 72 67 65 20  here.@ -- merge 
3ce0: 69 73 20 74 68 65 20 52 45 43 4f 52 44 20 74 61  is the RECORD ta
3cf0: 62 6c 65 20 65 6e 74 72 79 20 74 68 61 74 20 74  ble entry that t
3d00: 68 65 20 66 69 6c 65 20 6d 65 72 67 65 64 20 61  he file merged a
3d10: 67 61 69 6e 73 74 2e 0a 40 20 2d 2d 20 41 6e 20  gainst..@ -- An 
3d20: 69 64 20 6f 66 20 30 20 68 65 72 65 20 6d 65 61  id of 0 here mea
3d30: 6e 73 20 74 68 65 20 76 65 72 73 69 6f 6e 20 72  ns the version r
3d40: 65 63 6f 72 64 20 69 74 73 65 6c 66 2e 0a 40 0a  ecord itself..@.
3d50: 40 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 76  @ CREATE TABLE v
3d60: 6d 65 72 67 65 28 0a 40 20 20 20 69 64 20 49 4e  merge(.@   id IN
3d70: 54 45 47 45 52 20 52 45 46 45 52 45 4e 43 45 53  TEGER REFERENCES
3d80: 20 76 66 69 6c 65 2c 20 20 20 20 20 20 2d 2d 20   vfile,      -- 
3d90: 56 46 49 4c 45 20 65 6e 74 72 79 20 74 68 61 74  VFILE entry that
3da0: 20 68 61 73 20 62 65 65 6e 20 6d 65 72 67 65 64   has been merged
3db0: 0a 40 20 20 20 6d 65 72 67 65 20 49 4e 54 45 47  .@   merge INTEG
3dc0: 45 52 2c 20 20 20 20 20 20 20 20 20 20 20 20 20  ER,             
3dd0: 20 20 20 20 20 20 20 2d 2d 20 4d 65 72 67 65 64         -- Merged
3de0: 20 77 69 74 68 20 74 68 69 73 20 72 65 63 6f 72   with this recor
3df0: 64 0a 40 20 20 20 55 4e 49 51 55 45 28 69 64 2c  d.@   UNIQUE(id,
3e00: 20 6d 65 72 67 65 29 0a 40 20 29 3b 0a 40 20 20   merge).@ );.@  
3e10: 20 0a 3b 0a                                       .;.