Hex Artifact Content
Not logged in

Artifact e222adb420eb837c8849a776ac8ca7187e21f82b:

File src/schema.c part of check-in [09c4adeb6f] - Rework the tag system so that propagation to children is a property of each tag and does not depend on the tag name beginning with "br". Older tag artifacts might not work. The database will need to be rebuilt after upgrading to this version. by drh on 2007-09-22 23:41:29.

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 2c 20 20 20 20 20  EXT UNIQUE,     
0b30: 20 20 20 20 20 20 20 20 20 20 2d 2d 20 53 48 41            -- 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 20 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 29 3b 0a 40 20 43 52 45 41 54 45 20 54 41 42   );.@ CREATE TAB
0bb0: 4c 45 20 64 65 6c 74 61 28 0a 40 20 20 20 72 69  LE delta(.@   ri
0bc0: 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52  d INTEGER PRIMAR
0bd0: 59 20 4b 45 59 2c 20 20 20 20 20 20 20 20 20 20  Y KEY,          
0be0: 20 20 20 20 20 20 20 2d 2d 20 52 65 63 6f 72 64         -- Record
0bf0: 20 49 44 0a 40 20 20 20 73 72 63 69 64 20 49 4e   ID.@   srcid IN
0c00: 54 45 47 45 52 20 4e 4f 54 20 4e 55 4c 4c 20 52  TEGER NOT NULL R
0c10: 45 46 45 52 45 4e 43 45 53 20 62 6c 6f 62 20 20  EFERENCES blob  
0c20: 20 2d 2d 20 52 65 63 6f 72 64 20 68 6f 6c 64 69   -- Record holdi
0c30: 6e 67 20 73 6f 75 72 63 65 20 64 6f 63 75 6d 65  ng source docume
0c40: 6e 74 0a 40 20 29 3b 0a 40 20 43 52 45 41 54 45  nt.@ );.@ CREATE
0c50: 20 49 4e 44 45 58 20 64 65 6c 74 61 5f 69 31 20   INDEX delta_i1 
0c60: 4f 4e 20 64 65 6c 74 61 28 73 72 63 69 64 29 3b  ON delta(srcid);
0c70: 0a 40 0a 40 20 2d 2d 20 57 68 65 6e 65 76 65 72  .@.@ -- Whenever
0c80: 20 6e 65 77 20 62 6c 6f 62 73 20 61 72 65 20 72   new blobs are r
0c90: 65 63 65 69 76 65 64 20 69 6e 74 6f 20 74 68 65  eceived into the
0ca0: 20 72 65 70 6f 73 69 74 6f 72 79 2c 20 61 6e 20   repository, an 
0cb0: 65 6e 74 72 79 0a 40 20 2d 2d 20 69 6e 20 74 68  entry.@ -- in th
0cc0: 69 73 20 74 61 62 6c 65 20 72 65 63 6f 72 64 73  is table records
0cd0: 20 74 68 65 20 73 6f 75 72 63 65 20 6f 66 20 74   the source of t
0ce0: 68 65 20 62 6c 6f 62 2e 0a 40 20 2d 2d 0a 40 20  he blob..@ --.@ 
0cf0: 43 52 45 41 54 45 20 54 41 42 4c 45 20 72 63 76  CREATE TABLE rcv
0d00: 66 72 6f 6d 28 0a 40 20 20 20 72 63 76 69 64 20  from(.@   rcvid 
0d10: 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20  INTEGER PRIMARY 
0d20: 4b 45 59 2c 20 20 20 20 20 20 2d 2d 20 52 65 63  KEY,      -- Rec
0d30: 65 69 76 65 64 2d 46 72 6f 6d 20 49 44 0a 40 20  eived-From ID.@ 
0d40: 20 20 75 69 64 20 49 4e 54 45 47 45 52 20 52 45    uid INTEGER RE
0d50: 46 45 52 45 4e 43 45 53 20 75 73 65 72 2c 20 20  FERENCES user,  
0d60: 20 20 2d 2d 20 55 73 65 72 20 6c 6f 67 69 6e 0a    -- User login.
0d70: 40 20 20 20 6d 74 69 6d 65 20 44 41 54 45 54 49  @   mtime DATETI
0d80: 4d 45 2c 20 20 20 20 20 20 20 20 20 20 20 20 20  ME,             
0d90: 20 20 20 20 2d 2d 20 54 69 6d 65 20 6f 72 20 72      -- Time or r
0da0: 65 63 65 69 70 74 0a 40 20 20 20 6e 6f 6e 63 65  eceipt.@   nonce
0db0: 20 54 45 58 54 20 55 4e 49 51 55 45 2c 20 20 20   TEXT UNIQUE,   
0dc0: 20 20 20 20 20 20 20 20 20 20 20 2d 2d 20 4e 6f             -- No
0dd0: 6e 63 65 20 75 73 65 64 20 66 6f 72 20 6c 6f 67  nce used for log
0de0: 69 6e 0a 40 20 20 20 69 70 61 64 64 72 20 54 45  in.@   ipaddr TE
0df0: 58 54 20 20 20 20 20 20 20 20 20 20 20 20 20 20  XT              
0e00: 20 20 20 20 20 20 20 2d 2d 20 52 65 6d 6f 74 65         -- Remote
0e10: 20 49 50 20 61 64 64 72 65 73 73 2e 20 20 4e 55   IP address.  NU
0e20: 4c 4c 20 66 6f 72 20 64 69 72 65 63 74 2e 0a 40  LL for direct..@
0e30: 20 29 3b 0a 40 0a 40 20 2d 2d 20 49 6e 66 6f 72   );.@.@ -- Infor
0e40: 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20 75 73 65  mation about use
0e50: 72 73 0a 40 20 2d 2d 0a 40 20 43 52 45 41 54 45  rs.@ --.@ CREATE
0e60: 20 54 41 42 4c 45 20 75 73 65 72 28 0a 40 20 20   TABLE user(.@  
0e70: 20 75 69 64 20 49 4e 54 45 47 45 52 20 50 52 49   uid INTEGER PRI
0e80: 4d 41 52 59 20 4b 45 59 2c 20 20 20 20 20 20 20  MARY KEY,       
0e90: 20 2d 2d 20 55 73 65 72 20 49 44 0a 40 20 20 20   -- User ID.@   
0ea0: 6c 6f 67 69 6e 20 54 45 58 54 2c 20 20 20 20 20  login TEXT,     
0eb0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0ec0: 2d 2d 20 6c 6f 67 69 6e 20 6e 61 6d 65 20 6f 66  -- login name of
0ed0: 20 74 68 65 20 75 73 65 72 0a 40 20 20 20 70 77   the user.@   pw
0ee0: 20 54 45 58 54 2c 20 20 20 20 20 20 20 20 20 20   TEXT,          
0ef0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2d 2d                --
0f00: 20 70 61 73 73 77 6f 72 64 0a 40 20 20 20 63 61   password.@   ca
0f10: 70 20 54 45 58 54 2c 20 20 20 20 20 20 20 20 20  p TEXT,         
0f20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2d 2d                --
0f30: 20 43 61 70 61 62 69 6c 69 74 69 65 73 20 6f 66   Capabilities of
0f40: 20 74 68 69 73 20 75 73 65 72 0a 40 20 20 20 63   this user.@   c
0f50: 6f 6f 6b 69 65 20 54 45 58 54 2c 20 20 20 20 20  ookie TEXT,     
0f60: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2d                 -
0f70: 2d 20 57 57 57 20 6c 6f 67 69 6e 20 63 6f 6f 6b  - WWW login cook
0f80: 69 65 0a 40 20 20 20 69 70 61 64 64 72 20 54 45  ie.@   ipaddr TE
0f90: 58 54 2c 20 20 20 20 20 20 20 20 20 20 20 20 20  XT,             
0fa0: 20 20 20 20 20 20 20 2d 2d 20 49 50 20 61 64 64         -- IP add
0fb0: 72 65 73 73 20 66 6f 72 20 77 68 69 63 68 20 63  ress for which c
0fc0: 6f 6f 6b 69 65 20 69 73 20 76 61 6c 69 64 0a 40  ookie is valid.@
0fd0: 20 20 20 63 65 78 70 69 72 65 20 44 41 54 45 54     cexpire DATET
0fe0: 49 4d 45 2c 20 20 20 20 20 20 20 20 20 20 20 20  IME,            
0ff0: 20 20 20 2d 2d 20 54 69 6d 65 20 77 68 65 6e 20     -- Time when 
1000: 63 6f 6f 6b 69 65 20 65 78 70 69 72 65 73 0a 40  cookie expires.@
1010: 20 20 20 69 6e 66 6f 20 54 45 58 54 2c 20 20 20     info TEXT,   
1020: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1030: 20 20 20 2d 2d 20 63 6f 6e 74 61 63 74 20 69 6e     -- contact in
1040: 66 6f 72 6d 61 74 69 6f 6e 0a 40 20 20 20 70 68  formation.@   ph
1050: 6f 74 6f 20 42 4c 4f 42 20 20 20 20 20 20 20 20  oto BLOB        
1060: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2d 2d                --
1070: 20 4a 50 45 47 20 69 6d 61 67 65 20 6f 66 20 74   JPEG image of t
1080: 68 69 73 20 75 73 65 72 0a 40 20 29 3b 0a 40 0a  his user.@ );.@.
1090: 40 20 2d 2d 20 54 68 65 20 56 41 52 20 74 61 62  @ -- The VAR tab
10a0: 6c 65 20 68 6f 6c 64 73 20 6d 69 73 63 65 6c 6c  le holds miscell
10b0: 61 6e 6f 75 73 20 69 6e 66 6f 72 6d 61 74 69 6f  anous informatio
10c0: 6e 20 61 62 6f 75 74 20 74 68 65 20 72 65 70 6f  n about the repo
10d0: 73 69 74 6f 72 79 2e 0a 40 20 2d 2d 20 69 6e 20  sitory..@ -- in 
10e0: 74 68 65 20 66 6f 72 6d 20 6f 66 20 6e 61 6d 65  the form of name
10f0: 2d 76 61 6c 75 65 20 70 61 69 72 73 2e 0a 40 20  -value pairs..@ 
1100: 2d 2d 0a 40 20 43 52 45 41 54 45 20 54 41 42 4c  --.@ CREATE TABL
1110: 45 20 63 6f 6e 66 69 67 28 0a 40 20 20 20 6e 61  E config(.@   na
1120: 6d 65 20 54 45 58 54 20 50 52 49 4d 41 52 59 20  me TEXT PRIMARY 
1130: 4b 45 59 20 4e 4f 54 20 4e 55 4c 4c 2c 20 20 2d  KEY NOT NULL,  -
1140: 2d 20 50 72 69 6d 61 72 79 20 6e 61 6d 65 20 6f  - Primary name o
1150: 66 20 74 68 65 20 65 6e 74 72 79 0a 40 20 20 20  f the entry.@   
1160: 76 61 6c 75 65 20 43 4c 4f 42 2c 20 20 20 20 20  value CLOB,     
1170: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1180: 20 2d 2d 20 43 6f 6e 74 65 6e 74 20 6f 66 20 74   -- Content of t
1190: 68 65 20 6e 61 6d 65 64 20 70 61 72 61 6d 65 74  he named paramet
11a0: 65 72 0a 40 20 20 20 43 48 45 43 4b 28 20 74 79  er.@   CHECK( ty
11b0: 70 65 6f 66 28 6e 61 6d 65 29 3d 27 74 65 78 74  peof(name)='text
11c0: 27 20 41 4e 44 20 6c 65 6e 67 74 68 28 6e 61 6d  ' AND length(nam
11d0: 65 29 3e 3d 31 20 29 0a 40 20 29 3b 0a 3b 0a 63  e)>=1 ).@ );.;.c
11e0: 6f 6e 73 74 20 63 68 61 72 20 7a 52 65 70 6f 73  onst char zRepos
11f0: 69 74 6f 72 79 53 63 68 65 6d 61 32 5b 5d 20 3d  itorySchema2[] =
1200: 0a 40 20 2d 2d 20 46 69 6c 65 6e 61 6d 65 73 0a  .@ -- Filenames.
1210: 40 20 2d 2d 0a 40 20 43 52 45 41 54 45 20 54 41  @ --.@ CREATE TA
1220: 42 4c 45 20 66 69 6c 65 6e 61 6d 65 28 0a 40 20  BLE filename(.@ 
1230: 20 20 66 6e 69 64 20 49 4e 54 45 47 45 52 20 50    fnid INTEGER P
1240: 52 49 4d 41 52 59 20 4b 45 59 2c 20 20 20 20 2d  RIMARY KEY,    -
1250: 2d 20 46 69 6c 65 6e 61 6d 65 20 49 44 0a 40 20  - Filename ID.@ 
1260: 20 20 6e 61 6d 65 20 54 45 58 54 20 55 4e 49 51    name TEXT UNIQ
1270: 55 45 20 20 20 20 20 20 20 20 20 20 20 20 20 2d  UE             -
1280: 2d 20 4e 61 6d 65 20 6f 66 20 66 69 6c 65 20 70  - Name of file p
1290: 61 67 65 0a 40 20 29 3b 0a 40 0a 40 20 2d 2d 20  age.@ );.@.@ -- 
12a0: 4c 69 6e 6b 61 67 65 73 20 62 65 74 77 65 65 6e  Linkages between
12b0: 20 6d 61 6e 69 66 65 73 74 73 2c 20 66 69 6c 65   manifests, file
12c0: 73 20 63 72 65 61 74 65 64 20 62 79 20 74 68 61  s created by tha
12d0: 74 20 6d 61 6e 69 66 65 73 74 2c 20 61 6e 64 0a  t manifest, and.
12e0: 40 20 2d 2d 20 74 68 65 20 6e 61 6d 65 73 20 6f  @ -- the names o
12f0: 66 20 74 68 6f 73 65 20 66 69 6c 65 73 2e 0a 40  f those files..@
1300: 20 2d 2d 0a 40 20 2d 2d 20 70 69 64 3d 3d 30 20   --.@ -- pid==0 
1310: 69 66 20 74 68 65 20 66 69 6c 65 20 69 73 20 61  if the file is a
1320: 64 64 65 64 20 62 79 20 63 68 65 63 6b 2d 69 6e  dded by check-in
1330: 20 6d 69 64 2e 0a 40 20 2d 2d 20 66 69 64 3d 3d   mid..@ -- fid==
1340: 30 20 69 66 20 74 68 65 20 66 69 6c 65 20 69 73  0 if the file is
1350: 20 72 65 6d 6f 76 65 64 20 62 79 20 63 68 65 63   removed by chec
1360: 6b 2d 69 6e 20 6d 69 64 2e 0a 40 20 2d 2d 0a 40  k-in mid..@ --.@
1370: 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 6d 6c   CREATE TABLE ml
1380: 69 6e 6b 28 0a 40 20 20 20 6d 69 64 20 49 4e 54  ink(.@   mid INT
1390: 45 47 45 52 20 52 45 46 45 52 45 4e 43 45 53 20  EGER REFERENCES 
13a0: 62 6c 6f 62 2c 20 20 20 20 20 20 20 20 2d 2d 20  blob,        -- 
13b0: 4d 61 6e 69 66 65 73 74 20 49 44 20 77 68 65 72  Manifest ID wher
13c0: 65 20 63 68 61 6e 67 65 20 6f 63 63 75 72 73 0a  e change occurs.
13d0: 40 20 20 20 70 69 64 20 49 4e 54 45 47 45 52 20  @   pid INTEGER 
13e0: 52 45 46 45 52 45 4e 43 45 53 20 62 6c 6f 62 2c  REFERENCES blob,
13f0: 20 20 20 20 20 20 20 20 2d 2d 20 46 69 6c 65 20          -- File 
1400: 49 44 20 69 6e 20 70 61 72 65 6e 74 20 6d 61 6e  ID in parent man
1410: 69 66 65 73 74 0a 40 20 20 20 66 69 64 20 49 4e  ifest.@   fid IN
1420: 54 45 47 45 52 20 52 45 46 45 52 45 4e 43 45 53  TEGER REFERENCES
1430: 20 62 6c 6f 62 2c 20 20 20 20 20 20 20 20 2d 2d   blob,        --
1440: 20 43 68 61 6e 67 65 64 20 66 69 6c 65 20 49 44   Changed file ID
1450: 20 69 6e 20 74 68 69 73 20 6d 61 6e 69 66 65 73   in this manifes
1460: 74 0a 40 20 20 20 66 6e 69 64 20 49 4e 54 45 47  t.@   fnid INTEG
1470: 45 52 20 52 45 46 45 52 45 4e 43 45 53 20 66 69  ER REFERENCES fi
1480: 6c 65 6e 61 6d 65 20 20 20 20 2d 2d 20 4e 61 6d  lename    -- Nam
1490: 65 20 6f 66 20 74 68 65 20 66 69 6c 65 0a 40 20  e of the file.@ 
14a0: 29 3b 0a 40 20 43 52 45 41 54 45 20 49 4e 44 45  );.@ CREATE INDE
14b0: 58 20 6d 6c 69 6e 6b 5f 69 31 20 4f 4e 20 6d 6c  X mlink_i1 ON ml
14c0: 69 6e 6b 28 6d 69 64 29 3b 0a 40 20 43 52 45 41  ink(mid);.@ CREA
14d0: 54 45 20 49 4e 44 45 58 20 6d 6c 69 6e 6b 5f 69  TE INDEX mlink_i
14e0: 32 20 4f 4e 20 6d 6c 69 6e 6b 28 66 6e 69 64 29  2 ON mlink(fnid)
14f0: 3b 0a 40 20 43 52 45 41 54 45 20 49 4e 44 45 58  ;.@ CREATE INDEX
1500: 20 6d 6c 69 6e 6b 5f 69 33 20 4f 4e 20 6d 6c 69   mlink_i3 ON mli
1510: 6e 6b 28 66 69 64 29 3b 0a 40 20 43 52 45 41 54  nk(fid);.@ CREAT
1520: 45 20 49 4e 44 45 58 20 6d 6c 69 6e 6b 5f 69 34  E INDEX mlink_i4
1530: 20 4f 4e 20 6d 6c 69 6e 6b 28 70 69 64 29 3b 0a   ON mlink(pid);.
1540: 40 0a 40 20 2d 2d 20 50 61 72 65 6e 74 2f 63 68  @.@ -- Parent/ch
1550: 69 6c 64 20 6c 69 6e 6b 61 67 65 73 0a 40 20 2d  ild linkages.@ -
1560: 2d 0a 40 20 43 52 45 41 54 45 20 54 41 42 4c 45  -.@ CREATE TABLE
1570: 20 70 6c 69 6e 6b 28 0a 40 20 20 20 70 69 64 20   plink(.@   pid 
1580: 49 4e 54 45 47 45 52 20 52 45 46 45 52 45 4e 43  INTEGER REFERENC
1590: 45 53 20 62 6c 6f 62 2c 20 20 20 20 2d 2d 20 50  ES blob,    -- P
15a0: 61 72 65 6e 74 20 6d 61 6e 69 66 65 73 74 0a 40  arent manifest.@
15b0: 20 20 20 63 69 64 20 49 4e 54 45 47 45 52 20 52     cid INTEGER R
15c0: 45 46 45 52 45 4e 43 45 53 20 62 6c 6f 62 2c 20  EFERENCES blob, 
15d0: 20 20 20 2d 2d 20 43 68 69 6c 64 20 6d 61 6e 69     -- Child mani
15e0: 66 65 73 74 0a 40 20 20 20 69 73 70 72 69 6d 20  fest.@   isprim 
15f0: 42 4f 4f 4c 45 41 4e 2c 20 20 20 20 20 20 20 20  BOOLEAN,        
1600: 20 20 20 20 20 20 20 20 20 2d 2d 20 70 69 64 20           -- pid 
1610: 69 73 20 74 68 65 20 70 72 69 6d 61 72 79 20 70  is the primary p
1620: 61 72 65 6e 74 20 6f 66 20 63 69 64 0a 40 20 20  arent of cid.@  
1630: 20 6d 74 69 6d 65 20 44 41 54 45 54 49 4d 45 2c   mtime DATETIME,
1640: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1650: 20 2d 2d 20 74 68 65 20 64 61 74 65 2f 74 69 6d   -- the date/tim
1660: 65 20 73 74 61 6d 70 20 6f 6e 20 63 69 64 0a 40  e stamp on cid.@
1670: 20 20 20 55 4e 49 51 55 45 28 70 69 64 2c 20 63     UNIQUE(pid, c
1680: 69 64 29 0a 40 20 29 3b 0a 40 20 43 52 45 41 54  id).@ );.@ CREAT
1690: 45 20 49 4e 44 45 58 20 70 6c 69 6e 6b 5f 69 32  E INDEX plink_i2
16a0: 20 4f 4e 20 70 6c 69 6e 6b 28 63 69 64 29 3b 0a   ON plink(cid);.
16b0: 40 0a 40 20 2d 2d 20 45 76 65 6e 74 73 20 75 73  @.@ -- Events us
16c0: 65 64 20 74 6f 20 67 65 6e 65 72 61 74 65 20 61  ed to generate a
16d0: 20 74 69 6d 65 6c 69 6e 65 0a 40 20 2d 2d 0a 40   timeline.@ --.@
16e0: 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 65 76   CREATE TABLE ev
16f0: 65 6e 74 28 0a 40 20 20 20 74 79 70 65 20 54 45  ent(.@   type TE
1700: 58 54 2c 20 20 20 20 20 20 20 20 20 20 20 20 20  XT,             
1710: 20 20 20 20 20 20 20 20 20 2d 2d 20 54 79 70 65           -- Type
1720: 20 6f 66 20 65 76 65 6e 74 0a 40 20 20 20 6d 74   of event.@   mt
1730: 69 6d 65 20 44 41 54 45 54 49 4d 45 2c 20 20 20  ime DATETIME,   
1740: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2d 2d                --
1750: 20 44 61 74 65 20 61 6e 64 20 74 69 6d 65 20 77   Date and time w
1760: 68 65 6e 20 74 68 65 20 65 76 65 6e 74 20 6f 63  hen the event oc
1770: 63 75 72 73 0a 40 20 20 20 6f 62 6a 69 64 20 49  curs.@   objid I
1780: 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b  NTEGER PRIMARY K
1790: 45 59 2c 20 20 20 20 20 20 2d 2d 20 41 73 73 6f  EY,      -- Asso
17a0: 63 69 61 74 65 64 20 72 65 63 6f 72 64 20 49 44  ciated record ID
17b0: 0a 40 20 20 20 75 69 64 20 49 4e 54 45 47 45 52  .@   uid INTEGER
17c0: 20 52 45 46 45 52 45 4e 43 45 53 20 75 73 65 72   REFERENCES user
17d0: 2c 20 20 20 20 2d 2d 20 55 73 65 72 20 77 68 6f  ,    -- User who
17e0: 20 63 61 75 73 65 64 20 74 68 65 20 65 76 65 6e   caused the even
17f0: 74 0a 40 20 20 20 62 67 63 6f 6c 6f 72 20 54 45  t.@   bgcolor TE
1800: 58 54 2c 20 20 20 20 20 20 20 20 20 20 20 20 20  XT,             
1810: 20 20 20 20 20 20 2d 2d 20 43 6f 6c 6f 72 20 73        -- Color s
1820: 65 74 20 62 79 20 27 62 67 63 6f 6c 6f 72 27 20  et by 'bgcolor' 
1830: 70 72 6f 70 65 72 74 79 0a 40 20 20 20 62 72 62  property.@   brb
1840: 67 63 6f 6c 6f 72 20 54 45 58 54 2c 20 20 20 20  gcolor TEXT,    
1850: 20 20 20 20 20 20 20 20 20 20 20 20 20 2d 2d 20               -- 
1860: 43 6f 6c 6f 72 20 73 65 74 20 62 79 20 27 62 72  Color set by 'br
1870: 2d 62 67 63 6f 6c 6f 72 27 20 70 72 6f 70 65 72  -bgcolor' proper
1880: 74 79 0a 40 20 20 20 65 75 73 65 72 20 54 45 58  ty.@   euser TEX
1890: 54 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 20  T,              
18a0: 20 20 20 20 20 20 20 2d 2d 20 55 73 65 72 20 73         -- User s
18b0: 65 74 20 62 79 20 27 75 73 65 72 27 20 70 72 6f  et by 'user' pro
18c0: 70 65 72 74 79 0a 40 20 20 20 75 73 65 72 20 54  perty.@   user T
18d0: 45 58 54 2c 20 20 20 20 20 20 20 20 20 20 20 20  EXT,            
18e0: 20 20 20 20 20 20 20 20 20 20 2d 2d 20 4e 61 6d            -- Nam
18f0: 65 20 6f 66 20 74 68 65 20 75 73 65 72 0a 40 20  e of the user.@ 
1900: 20 20 65 63 6f 6d 6d 65 6e 74 20 54 45 58 54 2c    ecomment TEXT,
1910: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1920: 20 20 2d 2d 20 43 6f 6d 6d 65 6e 74 20 73 65 74    -- Comment set
1930: 20 62 79 20 27 63 6f 6d 6d 65 6e 74 27 20 70 72   by 'comment' pr
1940: 6f 70 65 72 74 79 0a 40 20 20 20 63 6f 6d 6d 65  operty.@   comme
1950: 6e 74 20 54 45 58 54 20 20 20 20 20 20 20 20 20  nt TEXT         
1960: 20 20 20 20 20 20 20 20 20 20 20 2d 2d 20 43 6f             -- Co
1970: 6d 6d 65 6e 74 20 64 65 73 63 72 69 62 69 6e 67  mment describing
1980: 20 74 68 65 20 65 76 65 6e 74 0a 40 20 29 3b 0a   the event.@ );.
1990: 40 20 43 52 45 41 54 45 20 49 4e 44 45 58 20 65  @ CREATE INDEX e
19a0: 76 65 6e 74 5f 69 31 20 4f 4e 20 65 76 65 6e 74  vent_i1 ON event
19b0: 28 6d 74 69 6d 65 29 3b 0a 40 0a 40 20 2d 2d 20  (mtime);.@.@ -- 
19c0: 41 20 72 65 63 6f 72 64 20 6f 66 20 70 68 61 6e  A record of phan
19d0: 74 6f 6d 73 2e 20 20 41 20 70 68 61 6e 74 6f 6d  toms.  A phantom
19e0: 20 69 73 20 61 20 72 65 63 6f 72 64 20 66 6f 72   is a record for
19f0: 20 77 68 69 63 68 20 77 65 20 6b 6e 6f 77 20 74   which we know t
1a00: 68 65 0a 40 20 2d 2d 20 55 55 49 44 20 62 75 74  he.@ -- UUID but
1a10: 20 77 65 20 64 6f 20 6e 6f 74 20 28 79 65 74 29   we do not (yet)
1a20: 20 6b 6e 6f 77 20 74 68 65 20 66 69 6c 65 20 63   know the file c
1a30: 6f 6e 74 65 6e 74 2e 0a 40 20 2d 2d 0a 40 20 43  ontent..@ --.@ C
1a40: 52 45 41 54 45 20 54 41 42 4c 45 20 70 68 61 6e  REATE TABLE phan
1a50: 74 6f 6d 28 0a 40 20 20 20 72 69 64 20 49 4e 54  tom(.@   rid INT
1a60: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59  EGER PRIMARY KEY
1a70: 20 20 20 20 20 20 20 20 20 2d 2d 20 52 65 63 6f           -- Reco
1a80: 72 64 20 49 44 20 6f 66 20 74 68 65 20 70 68 61  rd ID of the pha
1a90: 6e 74 6f 6d 0a 40 20 29 3b 0a 40 0a 40 20 2d 2d  ntom.@ );.@.@ --
1aa0: 20 55 6e 63 6c 75 73 74 65 72 65 64 20 72 65 63   Unclustered rec
1ab0: 6f 72 64 73 2e 20 20 41 6e 20 75 6e 63 6c 75 73  ords.  An unclus
1ac0: 74 65 72 65 64 20 72 65 63 6f 72 64 20 69 73 20  tered record is 
1ad0: 61 20 72 65 63 6f 72 64 20 28 69 6e 63 6c 75 64  a record (includ
1ae0: 69 6e 67 0a 40 20 2d 2d 20 61 20 63 6c 75 73 74  ing.@ -- a clust
1af0: 65 72 20 72 65 63 6f 72 64 73 20 74 68 65 6d 73  er records thems
1b00: 65 6c 76 65 73 29 20 74 68 61 74 20 69 73 20 6e  elves) that is n
1b10: 6f 74 20 6d 65 6e 74 69 6f 6e 65 64 20 62 79 20  ot mentioned by 
1b20: 73 6f 6d 65 20 6f 74 68 65 72 0a 40 20 2d 2d 20  some other.@ -- 
1b30: 63 6c 75 73 74 65 72 2e 0a 40 20 2d 2d 0a 40 20  cluster..@ --.@ 
1b40: 2d 2d 20 50 68 61 6e 74 6f 6d 73 20 61 72 65 20  -- Phantoms are 
1b50: 75 73 75 61 6c 6c 79 20 69 6e 63 6c 75 64 65 64  usually included
1b60: 20 69 6e 20 74 68 65 20 75 6e 63 6c 75 73 74 65   in the uncluste
1b70: 72 65 64 20 74 61 62 6c 65 2e 20 20 41 20 6e 65  red table.  A ne
1b80: 77 20 63 6c 75 73 74 65 72 0a 40 20 2d 2d 20 77  w cluster.@ -- w
1b90: 69 6c 6c 20 6e 65 76 65 72 20 62 65 20 63 72 65  ill never be cre
1ba0: 61 74 65 64 20 74 68 61 74 20 63 6f 6e 74 61 69  ated that contai
1bb0: 6e 73 20 61 20 70 68 61 6e 74 6f 6d 2e 20 20 42  ns a phantom.  B
1bc0: 75 74 20 61 6e 6f 74 68 65 72 20 72 65 70 6f 73  ut another repos
1bd0: 69 74 6f 72 79 0a 40 20 2d 2d 20 6d 69 67 68 74  itory.@ -- might
1be0: 20 73 65 6e 64 20 75 73 20 61 20 63 6c 75 73 74   send us a clust
1bf0: 65 72 20 74 68 61 74 20 63 6f 6e 74 61 69 6e 73  er that contains
1c00: 20 65 6e 74 72 69 65 73 20 74 68 61 74 20 61 72   entries that ar
1c10: 65 20 70 68 61 6e 74 6f 6d 73 20 74 6f 0a 40 20  e phantoms to.@ 
1c20: 2d 2d 20 75 73 2e 0a 40 20 2d 2d 0a 40 20 43 52  -- us..@ --.@ CR
1c30: 45 41 54 45 20 54 41 42 4c 45 20 75 6e 63 6c 75  EATE TABLE unclu
1c40: 73 74 65 72 65 64 28 0a 40 20 20 20 72 69 64 20  stered(.@   rid 
1c50: 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20  INTEGER PRIMARY 
1c60: 4b 45 59 20 20 20 20 20 20 20 20 20 2d 2d 20 52  KEY         -- R
1c70: 65 63 6f 72 64 20 49 44 20 6f 66 20 74 68 65 20  ecord ID of the 
1c80: 75 6e 63 6c 75 73 74 65 72 65 64 20 66 69 6c 65  unclustered file
1c90: 0a 40 20 29 3b 0a 40 0a 40 20 2d 2d 20 52 65 63  .@ );.@.@ -- Rec
1ca0: 6f 72 64 73 20 77 68 69 63 68 20 68 61 76 65 20  ords which have 
1cb0: 6e 65 76 65 72 20 62 65 65 6e 20 70 75 73 68 65  never been pushe
1cc0: 64 20 74 6f 20 61 6e 6f 74 68 65 72 20 73 65 72  d to another ser
1cd0: 76 65 72 2e 20 20 54 68 69 73 20 69 73 0a 40 20  ver.  This is.@ 
1ce0: 2d 2d 20 75 73 65 64 20 74 6f 20 72 65 64 75 63  -- used to reduc
1cf0: 65 20 70 75 73 68 20 6f 70 65 72 61 74 69 6f 6e  e push operation
1d00: 73 20 74 6f 20 61 20 73 69 6e 67 6c 65 20 48 54  s to a single HT
1d10: 54 50 20 72 65 71 75 65 73 74 20 69 6e 20 74 68  TP request in th
1d20: 65 0a 40 20 2d 2d 20 63 6f 6d 6d 6f 6e 20 63 61  e.@ -- common ca
1d30: 73 65 20 77 68 65 6e 20 6f 6e 65 20 72 65 70 6f  se when one repo
1d40: 73 69 74 6f 72 79 20 6f 6e 6c 79 20 74 61 6c 6b  sitory only talk
1d50: 73 20 74 6f 20 61 20 73 69 6e 67 6c 65 20 73 65  s to a single se
1d60: 72 76 65 72 2e 0a 40 20 2d 2d 0a 40 20 43 52 45  rver..@ --.@ CRE
1d70: 41 54 45 20 54 41 42 4c 45 20 75 6e 73 65 6e 74  ATE TABLE unsent
1d80: 28 0a 40 20 20 20 72 69 64 20 49 4e 54 45 47 45  (.@   rid INTEGE
1d90: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 20 20 20  R PRIMARY KEY   
1da0: 20 20 20 20 20 20 2d 2d 20 52 65 63 6f 72 64 20        -- Record 
1db0: 49 44 20 6f 66 20 74 68 65 20 70 68 61 6e 74 6f  ID of the phanto
1dc0: 6d 0a 40 20 29 3b 0a 40 0a 40 20 2d 2d 20 45 61  m.@ );.@.@ -- Ea
1dd0: 63 68 20 62 61 73 65 6c 69 6e 65 20 6f 72 20 6d  ch baseline or m
1de0: 61 6e 69 66 65 73 74 20 63 61 6e 20 68 61 76 65  anifest can have
1df0: 20 6f 6e 65 20 6f 72 20 6d 6f 72 65 20 74 61 67   one or more tag
1e00: 73 2e 20 20 41 20 74 61 67 0a 40 20 2d 2d 20 69  s.  A tag.@ -- i
1e10: 73 20 64 65 66 69 6e 65 64 20 62 79 20 61 20 72  s defined by a r
1e20: 6f 77 20 69 6e 20 74 68 65 20 6e 65 78 74 20 74  ow in the next t
1e30: 61 62 6c 65 2e 0a 40 20 2d 2d 20 0a 40 20 2d 2d  able..@ -- .@ --
1e40: 20 54 61 67 73 20 74 68 61 74 20 62 65 67 69 6e   Tags that begin
1e50: 20 77 69 74 68 20 22 62 72 22 20 61 75 74 6f 6d   with "br" autom
1e60: 61 74 69 63 61 6c 6c 79 20 70 72 6f 70 61 67 61  atically propaga
1e70: 74 65 20 74 6f 20 64 69 72 65 63 74 0a 40 20 2d  te to direct.@ -
1e80: 2d 20 63 68 69 6c 64 72 65 6e 2c 20 62 75 74 20  - children, but 
1e90: 6e 6f 74 20 74 6f 20 6d 65 72 67 65 20 63 68 69  not to merge chi
1ea0: 6c 64 72 65 6e 2e 0a 40 20 2d 2d 0a 40 20 43 52  ldren..@ --.@ CR
1eb0: 45 41 54 45 20 54 41 42 4c 45 20 74 61 67 28 0a  EATE TABLE tag(.
1ec0: 40 20 20 20 74 61 67 69 64 20 49 4e 54 45 47 45  @   tagid INTEGE
1ed0: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 20  R PRIMARY KEY,  
1ee0: 20 20 20 20 20 2d 2d 20 4e 75 6d 65 72 69 63 20       -- Numeric 
1ef0: 74 61 67 20 49 44 0a 40 20 20 20 74 61 67 6e 61  tag ID.@   tagna
1f00: 6d 65 20 54 45 58 54 20 55 4e 49 51 55 45 20 20  me TEXT UNIQUE  
1f10: 20 20 20 20 20 20 20 20 20 20 20 20 2d 2d 20 54              -- T
1f20: 61 67 20 6e 61 6d 65 2e 0a 40 20 29 3b 0a 40 20  ag name..@ );.@ 
1f30: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 61 67 20  INSERT INTO tag 
1f40: 56 41 4c 55 45 53 28 31 2c 20 27 62 67 63 6f 6c  VALUES(1, 'bgcol
1f50: 6f 72 27 29 3b 20 20 20 20 20 20 20 20 20 2d 2d  or');         --
1f60: 20 54 41 47 5f 42 47 43 4f 4c 4f 52 0a 40 20 49   TAG_BGCOLOR.@ I
1f70: 4e 53 45 52 54 20 49 4e 54 4f 20 74 61 67 20 56  NSERT INTO tag V
1f80: 41 4c 55 45 53 28 32 2c 20 27 63 6f 6d 6d 65 6e  ALUES(2, 'commen
1f90: 74 27 29 3b 20 20 20 20 20 20 20 20 20 2d 2d 20  t');         -- 
1fa0: 54 41 47 5f 43 4f 4d 4d 45 4e 54 0a 40 20 49 4e  TAG_COMMENT.@ IN
1fb0: 53 45 52 54 20 49 4e 54 4f 20 74 61 67 20 56 41  SERT INTO tag VA
1fc0: 4c 55 45 53 28 33 2c 20 27 75 73 65 72 27 29 3b  LUES(3, 'user');
1fd0: 20 20 20 20 20 20 20 20 20 20 20 20 2d 2d 20 54              -- T
1fe0: 41 47 5f 55 53 45 52 0a 40 0a 40 20 2d 2d 20 41  AG_USER.@.@ -- A
1ff0: 73 73 69 67 6e 6d 65 6e 74 73 20 6f 66 20 74 61  ssignments of ta
2000: 67 73 20 74 6f 20 62 61 73 65 6c 69 6e 65 73 2e  gs to baselines.
2010: 20 20 4e 6f 74 65 20 74 68 61 74 20 77 65 20 61    Note that we a
2020: 6c 6c 6f 77 20 74 61 67 73 20 74 6f 0a 40 20 2d  llow tags to.@ -
2030: 2d 20 68 61 76 65 20 76 61 6c 75 65 73 20 61 73  - have values as
2040: 73 69 67 6e 65 64 20 74 6f 20 74 68 65 6d 2e 20  signed to them. 
2050: 20 53 6f 20 77 65 20 61 72 65 20 6e 6f 74 20 72   So we are not r
2060: 65 61 6c 6c 79 20 64 65 61 6c 69 6e 67 20 77 69  eally dealing wi
2070: 74 68 0a 40 20 2d 2d 20 74 61 67 73 20 68 65 72  th.@ -- tags her
2080: 65 2e 20 20 54 68 65 73 65 20 61 72 65 20 72 65  e.  These are re
2090: 61 6c 6c 79 20 70 72 6f 70 65 72 74 69 65 73 2e  ally properties.
20a0: 20 20 42 75 74 20 77 65 20 61 72 65 20 67 6f 69    But we are goi
20b0: 6e 67 20 74 6f 0a 40 20 2d 2d 20 6b 65 65 70 20  ng to.@ -- keep 
20c0: 63 61 6c 6c 69 6e 67 20 74 68 65 6d 20 74 61 67  calling them tag
20d0: 73 20 62 65 63 61 75 73 65 20 69 6e 20 6d 61 6e  s because in man
20e0: 79 20 63 61 73 65 73 20 74 68 65 20 76 61 6c 75  y cases the valu
20f0: 65 20 69 73 20 69 67 6e 6f 72 65 64 2e 0a 40 20  e is ignored..@ 
2100: 2d 2d 0a 40 20 43 52 45 41 54 45 20 54 41 42 4c  --.@ CREATE TABL
2110: 45 20 74 61 67 78 72 65 66 28 0a 40 20 20 20 74  E tagxref(.@   t
2120: 61 67 69 64 20 49 4e 54 45 47 45 52 20 52 45 46  agid INTEGER REF
2130: 45 52 45 4e 43 45 53 20 74 61 67 2c 20 20 20 2d  ERENCES tag,   -
2140: 2d 20 54 68 65 20 74 61 67 20 74 68 61 74 20 61  - The tag that a
2150: 64 64 65 64 20 6f 72 20 72 65 6d 6f 76 65 64 0a  dded or removed.
2160: 40 20 20 20 74 61 67 74 79 70 65 20 49 4e 54 45  @   tagtype INTE
2170: 47 45 52 2c 20 20 20 20 20 20 20 20 20 20 20 20  GER,            
2180: 20 20 20 20 2d 2d 20 30 3a 63 61 6e 63 65 6c 20      -- 0:cancel 
2190: 20 31 3a 73 69 6e 67 6c 65 20 20 32 3a 62 72 61   1:single  2:bra
21a0: 6e 63 68 0a 40 20 20 20 73 72 63 69 64 20 49 4e  nch.@   srcid IN
21b0: 54 45 47 45 52 20 52 45 46 45 52 45 4e 43 45 53  TEGER REFERENCES
21c0: 20 62 6c 6f 62 2c 20 20 2d 2d 20 4f 72 69 67 69   blob,  -- Origi
21d0: 6e 20 6f 66 20 74 68 65 20 74 61 67 2e 20 30 20  n of the tag. 0 
21e0: 66 6f 72 20 70 72 6f 70 61 67 61 74 65 64 20 74  for propagated t
21f0: 61 67 73 0a 40 20 20 20 76 61 6c 75 65 20 54 45  ags.@   value TE
2200: 58 54 2c 20 20 20 20 20 20 20 20 20 20 20 20 20  XT,             
2210: 20 20 20 20 20 20 20 20 2d 2d 20 56 61 6c 75 65          -- Value
2220: 20 6f 66 20 74 68 65 20 74 61 67 2e 20 20 4d 69   of the tag.  Mi
2230: 67 68 74 20 62 65 20 4e 55 4c 4c 2e 0a 40 20 20  ght be NULL..@  
2240: 20 6d 74 69 6d 65 20 54 49 4d 45 53 54 41 4d 50   mtime TIMESTAMP
2250: 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  ,               
2260: 20 2d 2d 20 54 69 6d 65 20 6f 66 20 61 64 64 69   -- Time of addi
2270: 74 69 6f 6e 20 6f 72 20 72 65 6d 6f 76 61 6c 0a  tion or removal.
2280: 40 20 20 20 72 69 64 20 49 4e 54 45 47 45 52 20  @   rid INTEGER 
2290: 52 45 46 45 52 45 4e 43 45 20 62 6c 6f 62 2c 20  REFERENCE blob, 
22a0: 20 20 20 20 2d 2d 20 42 61 73 65 6c 69 6e 65 20      -- Baseline 
22b0: 74 68 61 74 20 74 61 67 20 61 64 64 65 64 2f 72  that tag added/r
22c0: 65 6d 6f 76 65 64 20 66 72 6f 6d 0a 40 20 20 20  emoved from.@   
22d0: 55 4e 49 51 55 45 28 72 69 64 2c 20 74 61 67 69  UNIQUE(rid, tagi
22e0: 64 29 0a 40 20 29 3b 0a 40 20 43 52 45 41 54 45  d).@ );.@ CREATE
22f0: 20 49 4e 44 45 58 20 74 61 67 78 72 65 66 5f 69   INDEX tagxref_i
2300: 31 20 4f 4e 20 74 61 67 78 72 65 66 28 74 61 67  1 ON tagxref(tag
2310: 69 64 29 3b 0a 3b 0a 0a 2f 2a 0a 2a 2a 20 50 72  id);.;../*.** Pr
2320: 65 64 65 66 69 6e 65 64 20 74 61 67 69 64 20 76  edefined tagid v
2330: 61 6c 75 65 73 0a 2a 2f 0a 23 69 66 20 49 4e 54  alues.*/.#if INT
2340: 45 52 46 41 43 45 0a 23 20 64 65 66 69 6e 65 20  ERFACE.# define 
2350: 54 41 47 5f 42 47 43 4f 4c 4f 52 20 20 20 20 31  TAG_BGCOLOR    1
2360: 0a 23 20 64 65 66 69 6e 65 20 54 41 47 5f 43 4f  .# define TAG_CO
2370: 4d 4d 45 4e 54 20 20 20 20 32 0a 23 20 64 65 66  MMENT    2.# def
2380: 69 6e 65 20 54 41 47 5f 55 53 45 52 20 20 20 20  ine TAG_USER    
2390: 20 20 20 33 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a     3.#endif../*.
23a0: 2a 2a 20 54 68 65 20 73 63 68 65 6d 61 20 66 6f  ** The schema fo
23b0: 72 20 74 68 65 20 6c 6f 63 61 74 65 20 46 4f 53  r the locate FOS
23c0: 53 49 4c 20 64 61 74 61 62 61 73 65 20 66 69 6c  SIL database fil
23d0: 65 20 66 6f 75 6e 64 20 61 74 20 74 68 65 20 72  e found at the r
23e0: 6f 6f 74 0a 2a 2a 20 6f 66 20 76 65 72 79 20 63  oot.** of very c
23f0: 68 65 63 6b 2d 6f 75 74 2e 20 20 54 68 69 73 20  heck-out.  This 
2400: 64 61 74 61 62 61 73 65 20 63 6f 6e 74 61 69 6e  database contain
2410: 73 20 74 68 65 20 63 6f 6d 70 6c 65 74 65 20 73  s the complete s
2420: 74 61 74 65 20 6f 66 0a 2a 2a 20 74 68 65 20 63  tate of.** the c
2430: 68 65 63 6b 6f 75 74 2e 0a 2a 2f 0a 63 6f 6e 73  heckout..*/.cons
2440: 74 20 63 68 61 72 20 7a 4c 6f 63 61 6c 53 63 68  t char zLocalSch
2450: 65 6d 61 5b 5d 20 3d 0a 40 20 2d 2d 20 54 68 65  ema[] =.@ -- The
2460: 20 56 56 41 52 20 74 61 62 6c 65 20 68 6f 6c 64   VVAR table hold
2470: 73 20 6d 69 73 63 65 6c 6c 61 6e 6f 75 73 20 69  s miscellanous i
2480: 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74  nformation about
2490: 20 74 68 65 20 6c 6f 63 61 6c 20 64 61 74 61 62   the local datab
24a0: 61 73 65 0a 40 20 2d 2d 20 69 6e 20 74 68 65 20  ase.@ -- in the 
24b0: 66 6f 72 6d 20 6f 66 20 6e 61 6d 65 2d 76 61 6c  form of name-val
24c0: 75 65 20 70 61 69 72 73 2e 20 20 54 68 69 73 20  ue pairs.  This 
24d0: 69 73 20 73 69 6d 69 6c 61 72 20 74 6f 20 74 68  is similar to th
24e0: 65 20 56 41 52 20 74 61 62 6c 65 0a 40 20 2d 2d  e VAR table.@ --
24f0: 20 74 61 62 6c 65 20 69 6e 20 74 68 65 20 72 65   table in the re
2500: 70 6f 73 69 74 6f 72 79 20 65 78 63 65 70 74 20  pository except 
2510: 74 68 61 74 20 74 68 69 73 20 74 61 62 6c 65 20  that this table 
2520: 68 6f 6c 64 73 20 69 6e 66 6f 72 6d 61 74 69 6f  holds informatio
2530: 6e 20 74 68 61 74 0a 40 20 2d 2d 20 69 73 20 73  n that.@ -- is s
2540: 70 65 63 69 66 69 63 20 74 6f 20 74 68 65 20 6c  pecific to the l
2550: 6f 63 61 6c 20 63 68 65 63 6b 6f 75 74 2e 0a 40  ocal checkout..@
2560: 20 2d 2d 0a 40 20 2d 2d 20 49 6d 70 6f 72 74 61   --.@ -- Importa
2570: 6e 74 20 56 61 72 69 61 62 6c 65 73 3a 0a 40 20  nt Variables:.@ 
2580: 2d 2d 0a 40 20 2d 2d 20 20 20 20 20 72 65 70 6f  --.@ --     repo
2590: 73 69 74 6f 72 79 20 20 20 20 20 20 20 20 46 75  sitory        Fu
25a0: 6c 6c 20 70 61 74 68 6e 61 6d 65 20 6f 66 20 74  ll pathname of t
25b0: 68 65 20 72 65 70 6f 73 69 74 6f 72 79 20 64 61  he repository da
25c0: 74 61 62 61 73 65 0a 40 20 2d 2d 20 20 20 20 20  tabase.@ --     
25d0: 75 73 65 72 2d 69 64 20 20 20 20 20 20 20 20 20  user-id         
25e0: 20 20 55 73 65 72 69 64 20 74 6f 20 75 73 65 0a    Userid to use.
25f0: 40 20 2d 2d 0a 40 20 43 52 45 41 54 45 20 54 41  @ --.@ CREATE TA
2600: 42 4c 45 20 76 76 61 72 28 0a 40 20 20 20 6e 61  BLE vvar(.@   na
2610: 6d 65 20 54 45 58 54 20 50 52 49 4d 41 52 59 20  me TEXT PRIMARY 
2620: 4b 45 59 20 4e 4f 54 20 4e 55 4c 4c 2c 20 20 2d  KEY NOT NULL,  -
2630: 2d 20 50 72 69 6d 61 72 79 20 6e 61 6d 65 20 6f  - Primary name o
2640: 66 20 74 68 65 20 65 6e 74 72 79 0a 40 20 20 20  f the entry.@   
2650: 76 61 6c 75 65 20 43 4c 4f 42 2c 20 20 20 20 20  value CLOB,     
2660: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2670: 20 2d 2d 20 43 6f 6e 74 65 6e 74 20 6f 66 20 74   -- Content of t
2680: 68 65 20 6e 61 6d 65 64 20 70 61 72 61 6d 65 74  he named paramet
2690: 65 72 0a 40 20 20 20 43 48 45 43 4b 28 20 74 79  er.@   CHECK( ty
26a0: 70 65 6f 66 28 6e 61 6d 65 29 3d 27 74 65 78 74  peof(name)='text
26b0: 27 20 41 4e 44 20 6c 65 6e 67 74 68 28 6e 61 6d  ' AND length(nam
26c0: 65 29 3e 3d 31 20 29 0a 40 20 29 3b 0a 40 0a 40  e)>=1 ).@ );.@.@
26d0: 20 2d 2d 20 45 61 63 68 20 65 6e 74 72 79 20 69   -- Each entry i
26e0: 6e 20 74 68 65 20 76 66 69 6c 65 20 74 61 62 6c  n the vfile tabl
26f0: 65 20 72 65 70 72 65 73 65 6e 74 73 20 61 20 73  e represents a s
2700: 69 6e 67 6c 65 20 66 69 6c 65 20 6f 72 20 66 6f  ingle file or fo
2710: 6c 64 65 72 0a 40 20 2d 2d 20 74 68 61 74 20 69  lder.@ -- that i
2720: 73 20 70 61 72 74 20 6f 66 20 61 20 76 65 72 73  s part of a vers
2730: 69 6f 6e 2e 0a 40 20 2d 2d 0a 40 20 2d 2d 20 54  ion..@ --.@ -- T
2740: 68 65 20 66 69 6c 65 2e 72 69 64 20 66 69 65 6c  he file.rid fiel
2750: 64 20 69 73 20 30 20 66 6f 72 20 66 69 6c 65 73  d is 0 for files
2760: 20 6f 72 20 66 6f 6c 64 65 72 73 20 74 68 61 74   or folders that
2770: 20 68 61 76 65 20 62 65 65 6e 0a 40 20 2d 2d 20   have been.@ -- 
2780: 61 64 64 65 64 20 62 75 74 20 6e 6f 74 20 79 65  added but not ye
2790: 74 20 63 6f 6d 6d 69 74 74 65 64 2e 0a 40 20 2d  t committed..@ -
27a0: 2d 0a 40 20 2d 2d 20 56 66 69 6c 65 2e 63 68 6e  -.@ -- Vfile.chn
27b0: 67 65 64 20 69 73 20 30 20 66 6f 72 20 75 6e 6d  ged is 0 for unm
27c0: 6f 64 69 66 69 65 64 20 66 69 6c 65 73 2c 20 31  odified files, 1
27d0: 20 66 6f 72 20 66 69 6c 65 73 20 74 68 61 74 20   for files that 
27e0: 68 61 76 65 0a 40 20 2d 2d 20 62 65 65 6e 20 65  have.@ -- been e
27f0: 64 69 74 65 64 20 6f 72 20 77 68 69 63 68 20 68  dited or which h
2800: 61 76 65 20 62 65 65 6e 20 73 75 62 6a 65 63 74  ave been subject
2810: 65 64 20 74 6f 20 61 20 33 2d 77 61 79 20 6d 65  ed to a 3-way me
2820: 72 67 65 2e 20 20 0a 40 20 2d 2d 20 56 66 69 6c  rge.  .@ -- Vfil
2830: 65 2e 63 68 6e 67 65 64 20 69 73 20 32 20 69 66  e.chnged is 2 if
2840: 20 74 68 65 20 66 69 6c 65 20 68 61 73 20 62 65   the file has be
2850: 65 6e 20 72 65 70 6c 61 63 65 64 20 66 72 6f 6d  en replaced from
2860: 20 61 20 64 69 66 66 65 72 65 6e 74 0a 40 20 2d   a different.@ -
2870: 2d 20 76 65 72 73 69 6f 6e 20 62 79 20 74 68 65  - version by the
2880: 20 6d 65 72 67 65 20 61 6e 64 20 33 20 69 66 20   merge and 3 if 
2890: 74 68 65 20 66 69 6c 65 20 68 61 73 20 62 65 65  the file has bee
28a0: 6e 20 61 64 64 65 64 20 62 79 20 61 20 6d 65 72  n added by a mer
28b0: 67 65 2e 0a 40 20 2d 2d 20 54 68 65 20 64 69 66  ge..@ -- The dif
28c0: 66 65 72 65 6e 63 65 20 62 65 74 77 65 65 6e 20  ference between 
28d0: 76 66 69 6c 65 2e 63 68 6e 67 65 64 3d 3d 32 20  vfile.chnged==2 
28e0: 61 6e 64 20 61 20 72 65 67 75 6c 61 72 20 61 64  and a regular ad
28f0: 64 20 69 73 20 74 68 61 74 0a 40 20 2d 2d 20 77  d is that.@ -- w
2900: 69 74 68 20 76 66 69 6c 65 2e 63 68 6e 67 65 64  ith vfile.chnged
2910: 3d 3d 32 20 77 65 20 6b 6e 6f 77 20 74 68 61 74  ==2 we know that
2920: 20 74 68 65 20 63 75 72 72 65 6e 74 20 76 65 72   the current ver
2930: 73 69 6f 6e 20 6f 66 20 74 68 65 20 66 69 6c 65  sion of the file
2940: 0a 40 20 2d 2d 20 69 73 20 61 6c 72 65 61 64 79  .@ -- is already
2950: 20 69 6e 20 74 68 65 20 72 65 70 6f 73 69 74 6f   in the reposito
2960: 72 79 2e 0a 40 20 2d 2d 20 0a 40 20 2d 2d 0a 40  ry..@ -- .@ --.@
2970: 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 76 66   CREATE TABLE vf
2980: 69 6c 65 28 0a 40 20 20 20 69 64 20 49 4e 54 45  ile(.@   id INTE
2990: 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c  GER PRIMARY KEY,
29a0: 20 20 20 20 20 20 20 20 20 20 20 2d 2d 20 49 44             -- ID
29b0: 20 6f 66 20 74 68 65 20 63 68 65 63 6b 65 64 20   of the checked 
29c0: 6f 75 74 20 66 69 6c 65 0a 40 20 20 20 76 69 64  out file.@   vid
29d0: 20 49 4e 54 45 47 45 52 20 52 45 46 45 52 45 4e   INTEGER REFEREN
29e0: 43 45 53 20 62 6c 6f 62 2c 20 20 20 20 20 20 2d  CES blob,      -
29f0: 2d 20 54 68 65 20 76 65 72 73 69 6f 6e 20 74 68  - The version th
2a00: 69 73 20 66 69 6c 65 20 69 73 20 70 61 72 74 20  is file is part 
2a10: 6f 66 2e 0a 40 20 20 20 63 68 6e 67 65 64 20 49  of..@   chnged I
2a20: 4e 54 20 44 45 46 41 55 4c 54 20 30 2c 20 20 20  NT DEFAULT 0,   
2a30: 20 20 20 20 20 20 20 20 20 20 2d 2d 20 30 3a 75            -- 0:u
2a40: 6e 63 68 6e 67 65 64 20 31 3a 65 64 69 74 65 64  nchnged 1:edited
2a50: 20 32 3a 6d 2d 63 68 6e 67 20 33 3a 6d 2d 61 64   2:m-chng 3:m-ad
2a60: 64 0a 40 20 20 20 64 65 6c 65 74 65 64 20 42 4f  d.@   deleted BO
2a70: 4f 4c 45 41 4e 20 44 45 46 41 55 4c 54 20 30 2c  OLEAN DEFAULT 0,
2a80: 20 20 20 20 20 20 20 20 2d 2d 20 54 72 75 65 20          -- True 
2a90: 69 66 20 64 65 6c 65 74 65 64 20 0a 40 20 20 20  if deleted .@   
2aa0: 72 69 64 20 49 4e 54 45 47 45 52 2c 20 20 20 20  rid INTEGER,    
2ab0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2ac0: 20 20 2d 2d 20 4f 72 69 67 69 6e 61 6c 6c 79 20    -- Originally 
2ad0: 66 72 6f 6d 20 74 68 69 73 20 72 65 70 6f 73 69  from this reposi
2ae0: 74 6f 72 79 20 72 65 63 6f 72 64 0a 40 20 20 20  tory record.@   
2af0: 6d 72 69 64 20 49 4e 54 45 47 45 52 2c 20 20 20  mrid INTEGER,   
2b00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2b10: 20 20 2d 2d 20 42 61 73 65 64 20 6f 6e 20 74 68    -- Based on th
2b20: 69 73 20 72 65 63 6f 72 64 20 64 75 65 20 74 6f  is record due to
2b30: 20 61 20 6d 65 72 67 65 0a 40 20 20 20 70 61 74   a merge.@   pat
2b40: 68 6e 61 6d 65 20 54 45 58 54 2c 20 20 20 20 20  hname TEXT,     
2b50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2d                 -
2b60: 2d 20 46 75 6c 6c 20 70 61 74 68 6e 61 6d 65 0a  - Full pathname.
2b70: 40 20 20 20 55 4e 49 51 55 45 28 70 61 74 68 6e  @   UNIQUE(pathn
2b80: 61 6d 65 2c 76 69 64 29 0a 40 20 29 3b 0a 40 0a  ame,vid).@ );.@.
2b90: 40 20 2d 2d 20 54 68 69 73 20 74 61 62 6c 65 20  @ -- This table 
2ba0: 68 6f 6c 64 73 20 61 20 72 65 63 6f 72 64 20 6f  holds a record o
2bb0: 66 20 75 6e 63 6f 6d 6d 69 74 74 65 64 20 6d 65  f uncommitted me
2bc0: 72 67 65 73 20 69 6e 20 74 68 65 20 6c 6f 63 61  rges in the loca
2bd0: 6c 0a 40 20 2d 2d 20 66 69 6c 65 20 74 72 65 65  l.@ -- file tree
2be0: 2e 20 20 49 66 20 61 20 56 46 49 4c 45 20 65 6e  .  If a VFILE en
2bf0: 74 72 79 20 77 69 74 68 20 69 64 20 68 61 73 20  try with id has 
2c00: 6d 65 72 67 65 64 20 77 69 74 68 20 61 6e 6f 74  merged with anot
2c10: 68 65 72 0a 40 20 2d 2d 20 72 65 63 6f 72 64 2c  her.@ -- record,
2c20: 20 74 68 65 72 65 20 69 73 20 61 6e 20 65 6e 74   there is an ent
2c30: 72 79 20 69 6e 20 74 68 69 73 20 74 61 62 6c 65  ry in this table
2c40: 20 77 69 74 68 20 28 69 64 2c 6d 65 72 67 65 29   with (id,merge)
2c50: 20 77 68 65 72 65 0a 40 20 2d 2d 20 6d 65 72 67   where.@ -- merg
2c60: 65 20 69 73 20 74 68 65 20 52 45 43 4f 52 44 20  e is the RECORD 
2c70: 74 61 62 6c 65 20 65 6e 74 72 79 20 74 68 61 74  table entry that
2c80: 20 74 68 65 20 66 69 6c 65 20 6d 65 72 67 65 64   the file merged
2c90: 20 61 67 61 69 6e 73 74 2e 0a 40 20 2d 2d 20 41   against..@ -- A
2ca0: 6e 20 69 64 20 6f 66 20 30 20 68 65 72 65 20 6d  n id of 0 here m
2cb0: 65 61 6e 73 20 74 68 65 20 76 65 72 73 69 6f 6e  eans the version
2cc0: 20 72 65 63 6f 72 64 20 69 74 73 65 6c 66 2e 0a   record itself..
2cd0: 40 0a 40 20 43 52 45 41 54 45 20 54 41 42 4c 45  @.@ CREATE TABLE
2ce0: 20 76 6d 65 72 67 65 28 0a 40 20 20 20 69 64 20   vmerge(.@   id 
2cf0: 49 4e 54 45 47 45 52 20 52 45 46 45 52 45 4e 43  INTEGER REFERENC
2d00: 45 53 20 76 66 69 6c 65 2c 20 20 20 20 20 20 2d  ES vfile,      -
2d10: 2d 20 56 46 49 4c 45 20 65 6e 74 72 79 20 74 68  - VFILE entry th
2d20: 61 74 20 68 61 73 20 62 65 65 6e 20 6d 65 72 67  at has been merg
2d30: 65 64 0a 40 20 20 20 6d 65 72 67 65 20 49 4e 54  ed.@   merge INT
2d40: 45 47 45 52 2c 20 20 20 20 20 20 20 20 20 20 20  EGER,           
2d50: 20 20 20 20 20 20 20 20 20 2d 2d 20 4d 65 72 67           -- Merg
2d60: 65 64 20 77 69 74 68 20 74 68 69 73 20 72 65 63  ed with this rec
2d70: 6f 72 64 0a 40 20 20 20 55 4e 49 51 55 45 28 69  ord.@   UNIQUE(i
2d80: 64 2c 20 6d 65 72 67 65 29 0a 40 20 29 3b 0a 40  d, merge).@ );.@
2d90: 20 20 20 0a 3b 0a 0a 63 6f 6e 73 74 20 63 68 61     .;..const cha
2da0: 72 20 7a 53 65 72 76 65 72 54 65 6d 70 53 63 68  r zServerTempSch
2db0: 65 6d 61 5b 5d 20 3d 0a 40 20 2d 2d 20 41 20 63  ema[] =.@ -- A c
2dc0: 6f 70 79 20 6f 66 20 74 68 65 20 76 66 69 6c 65  opy of the vfile
2dd0: 20 74 61 62 6c 65 20 73 63 68 65 6d 61 20 75 73   table schema us
2de0: 65 64 20 62 79 20 74 68 65 20 57 57 57 20 73 65  ed by the WWW se
2df0: 72 76 65 72 0a 40 20 2d 2d 0a 40 20 43 52 45 41  rver.@ --.@ CREA
2e00: 54 45 20 54 45 4d 50 20 54 41 42 4c 45 20 76 66  TE TEMP TABLE vf
2e10: 69 6c 65 28 0a 40 20 20 20 69 64 20 49 4e 54 45  ile(.@   id INTE
2e20: 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c  GER PRIMARY KEY,
2e30: 20 20 20 20 20 20 20 20 20 20 20 2d 2d 20 49 44             -- ID
2e40: 20 6f 66 20 74 68 65 20 63 68 65 63 6b 65 64 20   of the checked 
2e50: 6f 75 74 20 66 69 6c 65 0a 40 20 20 20 76 69 64  out file.@   vid
2e60: 20 49 4e 54 45 47 45 52 20 52 45 46 45 52 45 4e   INTEGER REFEREN
2e70: 43 45 53 20 72 65 63 6f 72 64 2c 20 20 20 20 2d  CES record,    -
2e80: 2d 20 54 68 65 20 76 65 72 73 69 6f 6e 20 74 68  - The version th
2e90: 69 73 20 66 69 6c 65 20 69 73 20 70 61 72 74 20  is file is part 
2ea0: 6f 66 2e 0a 40 20 20 20 63 68 6e 67 65 64 20 49  of..@   chnged I
2eb0: 4e 54 20 44 45 46 41 55 4c 54 20 30 2c 20 20 20  NT DEFAULT 0,   
2ec0: 20 20 20 20 20 20 20 20 20 20 2d 2d 20 30 3a 75            -- 0:u
2ed0: 6e 63 68 6e 67 65 64 20 31 3a 65 64 69 74 65 64  nchnged 1:edited
2ee0: 20 32 3a 6d 2d 63 68 6e 67 20 33 3a 6d 2d 61 64   2:m-chng 3:m-ad
2ef0: 64 0a 40 20 20 20 64 65 6c 65 74 65 64 20 42 4f  d.@   deleted BO
2f00: 4f 4c 45 41 4e 20 44 45 46 41 55 4c 54 20 30 2c  OLEAN DEFAULT 0,
2f10: 20 20 20 20 20 20 20 20 2d 2d 20 54 72 75 65 20          -- True 
2f20: 69 66 20 64 65 6c 65 74 65 64 20 0a 40 20 20 20  if deleted .@   
2f30: 72 69 64 20 49 4e 54 45 47 45 52 2c 20 20 20 20  rid INTEGER,    
2f40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2f50: 20 20 2d 2d 20 4f 72 69 67 69 6e 61 6c 6c 79 20    -- Originally 
2f60: 66 72 6f 6d 20 74 68 69 73 20 72 65 70 6f 73 69  from this reposi
2f70: 74 6f 72 79 20 72 65 63 6f 72 64 0a 40 20 20 20  tory record.@   
2f80: 6d 72 69 64 20 49 4e 54 45 47 45 52 2c 20 20 20  mrid INTEGER,   
2f90: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2fa0: 20 20 2d 2d 20 42 61 73 65 64 20 6f 6e 20 74 68    -- Based on th
2fb0: 69 73 20 72 65 63 6f 72 64 20 64 75 65 20 74 6f  is record due to
2fc0: 20 61 20 6d 65 72 67 65 0a 40 20 20 20 70 61 74   a merge.@   pat
2fd0: 68 6e 61 6d 65 20 54 45 58 54 2c 20 20 20 20 20  hname TEXT,     
2fe0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2d                 -
2ff0: 2d 20 46 75 6c 6c 20 70 61 74 68 6e 61 6d 65 0a  - Full pathname.
3000: 40 20 20 20 55 4e 49 51 55 45 28 70 61 74 68 6e  @   UNIQUE(pathn
3010: 61 6d 65 2c 76 69 64 29 0a 40 20 29 3b 0a 3b 0a  ame,vid).@ );.;.