Fossil SCM

Relax the schema requirements. This branch of Fossil can now work with older database schemas. A "fossil rebuild" is still recommended, and goofy displays, especially of the /finfo page, might result if the rebuild is omitted. But the obsolete schema errors are avoided. This is expected to simplify the upgrade path.

drh 2015-01-26 13:08 UTC mlink-improvements
Commit 3f739d4da7340ec89e4e8364cd7d627ec60cfdcb
2 files changed +10 -1 +4 -13
+10 -1
--- src/db.c
+++ src/db.c
@@ -1175,10 +1175,20 @@
11751175
g.zRepositoryName = mprintf("%s", zDbName);
11761176
db_open_or_attach(g.zRepositoryName, "repository", 0);
11771177
g.repositoryOpen = 1;
11781178
/* Cache "allow-symlinks" option, because we'll need it on every stat call */
11791179
g.allowSymlinks = db_get_boolean("allow-symlinks", 0);
1180
+ g.zAuxSchema = db_get("aux-schema","");
1181
+ if( !db_table_has_column("repository","mlink","isaux") ){
1182
+ db_begin_transaction();
1183
+ db_multi_exec(
1184
+ "ALTER TABLE %s.mlink ADD COLUMN pmid INTEGER DEFAULT 0;"
1185
+ "ALTER TABLE %s.mlink ADD COLUMN isaux INTEGER DEFAULT 0;",
1186
+ db_name("repository"), db_name("repository")
1187
+ );
1188
+ db_end_transaction(0);
1189
+ }
11801190
}
11811191
11821192
/*
11831193
** Flags for the db_find_and_open_repository() function.
11841194
*/
@@ -1242,11 +1252,10 @@
12421252
12431253
/*
12441254
** Return TRUE if the schema is out-of-date
12451255
*/
12461256
int db_schema_is_outofdate(void){
1247
- if( g.zAuxSchema==0 ) g.zAuxSchema = db_get("aux-schema","");
12481257
return strcmp(g.zAuxSchema,AUX_SCHEMA_MIN)<0
12491258
|| strcmp(g.zAuxSchema,AUX_SCHEMA_MAX)>0;
12501259
}
12511260
12521261
/*
12531262
--- src/db.c
+++ src/db.c
@@ -1175,10 +1175,20 @@
1175 g.zRepositoryName = mprintf("%s", zDbName);
1176 db_open_or_attach(g.zRepositoryName, "repository", 0);
1177 g.repositoryOpen = 1;
1178 /* Cache "allow-symlinks" option, because we'll need it on every stat call */
1179 g.allowSymlinks = db_get_boolean("allow-symlinks", 0);
 
 
 
 
 
 
 
 
 
 
1180 }
1181
1182 /*
1183 ** Flags for the db_find_and_open_repository() function.
1184 */
@@ -1242,11 +1252,10 @@
1242
1243 /*
1244 ** Return TRUE if the schema is out-of-date
1245 */
1246 int db_schema_is_outofdate(void){
1247 if( g.zAuxSchema==0 ) g.zAuxSchema = db_get("aux-schema","");
1248 return strcmp(g.zAuxSchema,AUX_SCHEMA_MIN)<0
1249 || strcmp(g.zAuxSchema,AUX_SCHEMA_MAX)>0;
1250 }
1251
1252 /*
1253
--- src/db.c
+++ src/db.c
@@ -1175,10 +1175,20 @@
1175 g.zRepositoryName = mprintf("%s", zDbName);
1176 db_open_or_attach(g.zRepositoryName, "repository", 0);
1177 g.repositoryOpen = 1;
1178 /* Cache "allow-symlinks" option, because we'll need it on every stat call */
1179 g.allowSymlinks = db_get_boolean("allow-symlinks", 0);
1180 g.zAuxSchema = db_get("aux-schema","");
1181 if( !db_table_has_column("repository","mlink","isaux") ){
1182 db_begin_transaction();
1183 db_multi_exec(
1184 "ALTER TABLE %s.mlink ADD COLUMN pmid INTEGER DEFAULT 0;"
1185 "ALTER TABLE %s.mlink ADD COLUMN isaux INTEGER DEFAULT 0;",
1186 db_name("repository"), db_name("repository")
1187 );
1188 db_end_transaction(0);
1189 }
1190 }
1191
1192 /*
1193 ** Flags for the db_find_and_open_repository() function.
1194 */
@@ -1242,11 +1252,10 @@
1252
1253 /*
1254 ** Return TRUE if the schema is out-of-date
1255 */
1256 int db_schema_is_outofdate(void){
 
1257 return strcmp(g.zAuxSchema,AUX_SCHEMA_MIN)<0
1258 || strcmp(g.zAuxSchema,AUX_SCHEMA_MAX)>0;
1259 }
1260
1261 /*
1262
+4 -13
--- src/schema.c
+++ src/schema.c
@@ -44,12 +44,15 @@
4444
** a date) which can change frequently. When the content schema changes,
4545
** we have to execute special procedures to update the schema. When
4646
** the aux schema changes, all we need to do is rebuild the database.
4747
*/
4848
#define CONTENT_SCHEMA "2"
49
-#define AUX_SCHEMA_MIN "2015-01-24"
49
+#define AUX_SCHEMA_MIN "2011-04-25 19:50"
5050
#define AUX_SCHEMA_MAX "2015-01-24"
51
+/* NB: Some features require the latest schema. Warning or error messages
52
+** will appear if an older schema is used. However, the older schemas are
53
+** adequate for many common functions. */
5154
5255
#endif /* INTERFACE */
5356
5457
5558
/*
@@ -225,20 +228,10 @@
225228
@ CREATE TABLE filename(
226229
@ fnid INTEGER PRIMARY KEY, -- Filename ID
227230
@ name TEXT UNIQUE -- Name of file page
228231
@ );
229232
@
230
-@
231
-@ -- A "file class" is like a filename except that it remains constant
232
-@ -- across renames.
233
-@ --
234
-@ CREATE TABLE fileclass(
235
-@ fclass INTEGER PRIMARY KEY, -- Unique id for this fileclass
236
-@ ckid INTEGER REFERENCES plink(cid), -- Checkin where file originates
237
-@ fnid INTEGER REFERENCES filename -- Name of the file in ckid
238
-@ );
239
-@
240233
@ -- Linkages between checkins, files created by each checkin, and
241234
@ -- the names of those files.
242235
@ --
243236
@ -- Each entry represents a file that changed content from pid to fid
244237
@ -- due to the check-in that goes from pmid to mid. fnid is the name
@@ -254,11 +247,10 @@
254247
@ -- fid = File ID.
255248
@ -- pmid = Parent Manifest ID.
256249
@ -- pid = Parent file ID.
257250
@ -- fnid = File Name ID.
258251
@ -- pfnid = Parent File Name ID.
259
-@ -- fclass = FileCLASS id.
260252
@ -- isaux = pmid IS AUXiliary parent, not primary parent
261253
@ --
262254
@ -- pid==0 if the file is added by checkin mid.
263255
@ -- fid==0 if the file is removed by checkin mid.
264256
@ --
@@ -268,11 +260,10 @@
268260
@ pmid INTEGER REFERENCES plink(cid), -- Checkin that contains pid
269261
@ pid INTEGER REFERENCES blob, -- Prev file content. 0 if new
270262
@ fnid INTEGER REFERENCES filename, -- Name of the file
271263
@ pfnid INTEGER REFERENCES filename, -- Previous name. 0 if unchanged
272264
@ mperm INTEGER, -- File permissions. 1==exec
273
-@ fclass INTEGER REFERENCE fileclass, -- fid is an instance of this class
274265
@ isaux BOOLEAN DEFAULT 0 -- TRUE if pmid is the primary
275266
@ );
276267
@ CREATE INDEX mlink_i1 ON mlink(mid);
277268
@ CREATE INDEX mlink_i2 ON mlink(fnid);
278269
@ CREATE INDEX mlink_i3 ON mlink(fid);
279270
--- src/schema.c
+++ src/schema.c
@@ -44,12 +44,15 @@
44 ** a date) which can change frequently. When the content schema changes,
45 ** we have to execute special procedures to update the schema. When
46 ** the aux schema changes, all we need to do is rebuild the database.
47 */
48 #define CONTENT_SCHEMA "2"
49 #define AUX_SCHEMA_MIN "2015-01-24"
50 #define AUX_SCHEMA_MAX "2015-01-24"
 
 
 
51
52 #endif /* INTERFACE */
53
54
55 /*
@@ -225,20 +228,10 @@
225 @ CREATE TABLE filename(
226 @ fnid INTEGER PRIMARY KEY, -- Filename ID
227 @ name TEXT UNIQUE -- Name of file page
228 @ );
229 @
230 @
231 @ -- A "file class" is like a filename except that it remains constant
232 @ -- across renames.
233 @ --
234 @ CREATE TABLE fileclass(
235 @ fclass INTEGER PRIMARY KEY, -- Unique id for this fileclass
236 @ ckid INTEGER REFERENCES plink(cid), -- Checkin where file originates
237 @ fnid INTEGER REFERENCES filename -- Name of the file in ckid
238 @ );
239 @
240 @ -- Linkages between checkins, files created by each checkin, and
241 @ -- the names of those files.
242 @ --
243 @ -- Each entry represents a file that changed content from pid to fid
244 @ -- due to the check-in that goes from pmid to mid. fnid is the name
@@ -254,11 +247,10 @@
254 @ -- fid = File ID.
255 @ -- pmid = Parent Manifest ID.
256 @ -- pid = Parent file ID.
257 @ -- fnid = File Name ID.
258 @ -- pfnid = Parent File Name ID.
259 @ -- fclass = FileCLASS id.
260 @ -- isaux = pmid IS AUXiliary parent, not primary parent
261 @ --
262 @ -- pid==0 if the file is added by checkin mid.
263 @ -- fid==0 if the file is removed by checkin mid.
264 @ --
@@ -268,11 +260,10 @@
268 @ pmid INTEGER REFERENCES plink(cid), -- Checkin that contains pid
269 @ pid INTEGER REFERENCES blob, -- Prev file content. 0 if new
270 @ fnid INTEGER REFERENCES filename, -- Name of the file
271 @ pfnid INTEGER REFERENCES filename, -- Previous name. 0 if unchanged
272 @ mperm INTEGER, -- File permissions. 1==exec
273 @ fclass INTEGER REFERENCE fileclass, -- fid is an instance of this class
274 @ isaux BOOLEAN DEFAULT 0 -- TRUE if pmid is the primary
275 @ );
276 @ CREATE INDEX mlink_i1 ON mlink(mid);
277 @ CREATE INDEX mlink_i2 ON mlink(fnid);
278 @ CREATE INDEX mlink_i3 ON mlink(fid);
279
--- src/schema.c
+++ src/schema.c
@@ -44,12 +44,15 @@
44 ** a date) which can change frequently. When the content schema changes,
45 ** we have to execute special procedures to update the schema. When
46 ** the aux schema changes, all we need to do is rebuild the database.
47 */
48 #define CONTENT_SCHEMA "2"
49 #define AUX_SCHEMA_MIN "2011-04-25 19:50"
50 #define AUX_SCHEMA_MAX "2015-01-24"
51 /* NB: Some features require the latest schema. Warning or error messages
52 ** will appear if an older schema is used. However, the older schemas are
53 ** adequate for many common functions. */
54
55 #endif /* INTERFACE */
56
57
58 /*
@@ -225,20 +228,10 @@
228 @ CREATE TABLE filename(
229 @ fnid INTEGER PRIMARY KEY, -- Filename ID
230 @ name TEXT UNIQUE -- Name of file page
231 @ );
232 @
 
 
 
 
 
 
 
 
 
 
233 @ -- Linkages between checkins, files created by each checkin, and
234 @ -- the names of those files.
235 @ --
236 @ -- Each entry represents a file that changed content from pid to fid
237 @ -- due to the check-in that goes from pmid to mid. fnid is the name
@@ -254,11 +247,10 @@
247 @ -- fid = File ID.
248 @ -- pmid = Parent Manifest ID.
249 @ -- pid = Parent file ID.
250 @ -- fnid = File Name ID.
251 @ -- pfnid = Parent File Name ID.
 
252 @ -- isaux = pmid IS AUXiliary parent, not primary parent
253 @ --
254 @ -- pid==0 if the file is added by checkin mid.
255 @ -- fid==0 if the file is removed by checkin mid.
256 @ --
@@ -268,11 +260,10 @@
260 @ pmid INTEGER REFERENCES plink(cid), -- Checkin that contains pid
261 @ pid INTEGER REFERENCES blob, -- Prev file content. 0 if new
262 @ fnid INTEGER REFERENCES filename, -- Name of the file
263 @ pfnid INTEGER REFERENCES filename, -- Previous name. 0 if unchanged
264 @ mperm INTEGER, -- File permissions. 1==exec
 
265 @ isaux BOOLEAN DEFAULT 0 -- TRUE if pmid is the primary
266 @ );
267 @ CREATE INDEX mlink_i1 ON mlink(mid);
268 @ CREATE INDEX mlink_i2 ON mlink(fnid);
269 @ CREATE INDEX mlink_i3 ON mlink(fid);
270

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button