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.
Commit
3f739d4da7340ec89e4e8364cd7d627ec60cfdcb
Parent
3c3c166c896b4e0…
2 files changed
+10
-1
+4
-13
M
src/db.c
+10
-1
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -1175,10 +1175,20 @@ | ||
| 1175 | 1175 | g.zRepositoryName = mprintf("%s", zDbName); |
| 1176 | 1176 | db_open_or_attach(g.zRepositoryName, "repository", 0); |
| 1177 | 1177 | g.repositoryOpen = 1; |
| 1178 | 1178 | /* Cache "allow-symlinks" option, because we'll need it on every stat call */ |
| 1179 | 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 | + } | |
| 1180 | 1190 | } |
| 1181 | 1191 | |
| 1182 | 1192 | /* |
| 1183 | 1193 | ** Flags for the db_find_and_open_repository() function. |
| 1184 | 1194 | */ |
| @@ -1242,11 +1252,10 @@ | ||
| 1242 | 1252 | |
| 1243 | 1253 | /* |
| 1244 | 1254 | ** Return TRUE if the schema is out-of-date |
| 1245 | 1255 | */ |
| 1246 | 1256 | int db_schema_is_outofdate(void){ |
| 1247 | - if( g.zAuxSchema==0 ) g.zAuxSchema = db_get("aux-schema",""); | |
| 1248 | 1257 | return strcmp(g.zAuxSchema,AUX_SCHEMA_MIN)<0 |
| 1249 | 1258 | || strcmp(g.zAuxSchema,AUX_SCHEMA_MAX)>0; |
| 1250 | 1259 | } |
| 1251 | 1260 | |
| 1252 | 1261 | /* |
| 1253 | 1262 |
| --- 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 @@ | ||
| 44 | 44 | ** a date) which can change frequently. When the content schema changes, |
| 45 | 45 | ** we have to execute special procedures to update the schema. When |
| 46 | 46 | ** the aux schema changes, all we need to do is rebuild the database. |
| 47 | 47 | */ |
| 48 | 48 | #define CONTENT_SCHEMA "2" |
| 49 | -#define AUX_SCHEMA_MIN "2015-01-24" | |
| 49 | +#define AUX_SCHEMA_MIN "2011-04-25 19:50" | |
| 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. */ | |
| 51 | 54 | |
| 52 | 55 | #endif /* INTERFACE */ |
| 53 | 56 | |
| 54 | 57 | |
| 55 | 58 | /* |
| @@ -225,20 +228,10 @@ | ||
| 225 | 228 | @ CREATE TABLE filename( |
| 226 | 229 | @ fnid INTEGER PRIMARY KEY, -- Filename ID |
| 227 | 230 | @ name TEXT UNIQUE -- Name of file page |
| 228 | 231 | @ ); |
| 229 | 232 | @ |
| 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 | 233 | @ -- Linkages between checkins, files created by each checkin, and |
| 241 | 234 | @ -- the names of those files. |
| 242 | 235 | @ -- |
| 243 | 236 | @ -- Each entry represents a file that changed content from pid to fid |
| 244 | 237 | @ -- due to the check-in that goes from pmid to mid. fnid is the name |
| @@ -254,11 +247,10 @@ | ||
| 254 | 247 | @ -- fid = File ID. |
| 255 | 248 | @ -- pmid = Parent Manifest ID. |
| 256 | 249 | @ -- pid = Parent file ID. |
| 257 | 250 | @ -- fnid = File Name ID. |
| 258 | 251 | @ -- pfnid = Parent File Name ID. |
| 259 | -@ -- fclass = FileCLASS id. | |
| 260 | 252 | @ -- isaux = pmid IS AUXiliary parent, not primary parent |
| 261 | 253 | @ -- |
| 262 | 254 | @ -- pid==0 if the file is added by checkin mid. |
| 263 | 255 | @ -- fid==0 if the file is removed by checkin mid. |
| 264 | 256 | @ -- |
| @@ -268,11 +260,10 @@ | ||
| 268 | 260 | @ pmid INTEGER REFERENCES plink(cid), -- Checkin that contains pid |
| 269 | 261 | @ pid INTEGER REFERENCES blob, -- Prev file content. 0 if new |
| 270 | 262 | @ fnid INTEGER REFERENCES filename, -- Name of the file |
| 271 | 263 | @ pfnid INTEGER REFERENCES filename, -- Previous name. 0 if unchanged |
| 272 | 264 | @ mperm INTEGER, -- File permissions. 1==exec |
| 273 | -@ fclass INTEGER REFERENCE fileclass, -- fid is an instance of this class | |
| 274 | 265 | @ isaux BOOLEAN DEFAULT 0 -- TRUE if pmid is the primary |
| 275 | 266 | @ ); |
| 276 | 267 | @ CREATE INDEX mlink_i1 ON mlink(mid); |
| 277 | 268 | @ CREATE INDEX mlink_i2 ON mlink(fnid); |
| 278 | 269 | @ CREATE INDEX mlink_i3 ON mlink(fid); |
| 279 | 270 |
| --- 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 |