Fossil SCM

Enhance the database aux-schema version checking so that it will accept a range of schema versions. Fix the current implementation to work with or without the PLINK.BASEID enhancement.

drh 2014-11-28 14:29 UTC baseline-in-plink
Commit 0d4b33d3a410d9f754db7858566e5c085bd22c77
+1 -1
--- src/clone.c
+++ src/clone.c
@@ -164,11 +164,11 @@
164164
db_begin_transaction();
165165
db_record_repository_filename(g.argv[3]);
166166
db_initial_setup(0, 0, zDefaultUser, 0);
167167
user_select();
168168
db_set("content-schema", CONTENT_SCHEMA, 0);
169
- db_set("aux-schema", AUX_SCHEMA, 0);
169
+ db_set("aux-schema", AUX_SCHEMA_MAX, 0);
170170
db_set("rebuilt", get_version(), 0);
171171
remember_or_get_http_auth(zHttpAuth, urlFlags & URL_REMEMBER, g.argv[2]);
172172
url_remember();
173173
if( g.zSSLIdentity!=0 ){
174174
/* If the --ssl-identity option was specified, store it as a setting */
175175
--- src/clone.c
+++ src/clone.c
@@ -164,11 +164,11 @@
164 db_begin_transaction();
165 db_record_repository_filename(g.argv[3]);
166 db_initial_setup(0, 0, zDefaultUser, 0);
167 user_select();
168 db_set("content-schema", CONTENT_SCHEMA, 0);
169 db_set("aux-schema", AUX_SCHEMA, 0);
170 db_set("rebuilt", get_version(), 0);
171 remember_or_get_http_auth(zHttpAuth, urlFlags & URL_REMEMBER, g.argv[2]);
172 url_remember();
173 if( g.zSSLIdentity!=0 ){
174 /* If the --ssl-identity option was specified, store it as a setting */
175
--- src/clone.c
+++ src/clone.c
@@ -164,11 +164,11 @@
164 db_begin_transaction();
165 db_record_repository_filename(g.argv[3]);
166 db_initial_setup(0, 0, zDefaultUser, 0);
167 user_select();
168 db_set("content-schema", CONTENT_SCHEMA, 0);
169 db_set("aux-schema", AUX_SCHEMA_MAX, 0);
170 db_set("rebuilt", get_version(), 0);
171 remember_or_get_http_auth(zHttpAuth, urlFlags & URL_REMEMBER, g.argv[2]);
172 url_remember();
173 if( g.zSSLIdentity!=0 ){
174 /* If the --ssl-identity option was specified, store it as a setting */
175
+8 -8
--- src/db.c
+++ src/db.c
@@ -1117,13 +1117,13 @@
11171117
11181118
/*
11191119
** Return TRUE if the schema is out-of-date
11201120
*/
11211121
int db_schema_is_outofdate(void){
1122
- return db_exists("SELECT 1 FROM config"
1123
- " WHERE name='aux-schema'"
1124
- " AND value<>%Q", AUX_SCHEMA);
1122
+ g.zAuxSchema = db_text(0, "SELECT value FROM config WHERE name='aux-schema'");
1123
+ return strcmp(g.zAuxSchema,AUX_SCHEMA_MIN)<0
1124
+ || strcmp(g.zAuxSchema,AUX_SCHEMA_MAX)>0;
11251125
}
11261126
11271127
/*
11281128
** Return true if the database is writeable
11291129
*/
@@ -1138,14 +1138,14 @@
11381138
void db_verify_schema(void){
11391139
if( db_schema_is_outofdate() ){
11401140
#ifdef FOSSIL_ENABLE_JSON
11411141
g.json.resultCode = FSL_JSON_E_DB_NEEDS_REBUILD;
11421142
#endif
1143
- fossil_warning("incorrect repository schema version");
1144
- fossil_warning("your repository has schema version \"%s\" "
1145
- "but this binary expects version \"%s\"",
1146
- db_get("aux-schema",0), AUX_SCHEMA);
1143
+ fossil_warning("incorrect repository schema version: "
1144
+ "current repository schema version is \"%s\" "
1145
+ "but need versions between \"%s\" and \"%s\".",
1146
+ db_get("aux-schema",0), AUX_SCHEMA_MIN, AUX_SCHEMA_MAX);
11471147
fossil_fatal("run \"fossil rebuild\" to fix this problem");
11481148
}
11491149
}
11501150
11511151
@@ -1393,11 +1393,11 @@
13931393
char *zDate;
13941394
Blob hash;
13951395
Blob manifest;
13961396
13971397
db_set("content-schema", CONTENT_SCHEMA, 0);
1398
- db_set("aux-schema", AUX_SCHEMA, 0);
1398
+ db_set("aux-schema", AUX_SCHEMA_MAX, 0);
13991399
db_set("rebuilt", get_version(), 0);
14001400
if( makeServerCodes ){
14011401
db_setup_server_and_project_codes(0);
14021402
}
14031403
if( !db_is_global("autosync") ) db_set_int("autosync", 1, 0);
14041404
--- src/db.c
+++ src/db.c
@@ -1117,13 +1117,13 @@
1117
1118 /*
1119 ** Return TRUE if the schema is out-of-date
1120 */
1121 int db_schema_is_outofdate(void){
1122 return db_exists("SELECT 1 FROM config"
1123 " WHERE name='aux-schema'"
1124 " AND value<>%Q", AUX_SCHEMA);
1125 }
1126
1127 /*
1128 ** Return true if the database is writeable
1129 */
@@ -1138,14 +1138,14 @@
1138 void db_verify_schema(void){
1139 if( db_schema_is_outofdate() ){
1140 #ifdef FOSSIL_ENABLE_JSON
1141 g.json.resultCode = FSL_JSON_E_DB_NEEDS_REBUILD;
1142 #endif
1143 fossil_warning("incorrect repository schema version");
1144 fossil_warning("your repository has schema version \"%s\" "
1145 "but this binary expects version \"%s\"",
1146 db_get("aux-schema",0), AUX_SCHEMA);
1147 fossil_fatal("run \"fossil rebuild\" to fix this problem");
1148 }
1149 }
1150
1151
@@ -1393,11 +1393,11 @@
1393 char *zDate;
1394 Blob hash;
1395 Blob manifest;
1396
1397 db_set("content-schema", CONTENT_SCHEMA, 0);
1398 db_set("aux-schema", AUX_SCHEMA, 0);
1399 db_set("rebuilt", get_version(), 0);
1400 if( makeServerCodes ){
1401 db_setup_server_and_project_codes(0);
1402 }
1403 if( !db_is_global("autosync") ) db_set_int("autosync", 1, 0);
1404
--- src/db.c
+++ src/db.c
@@ -1117,13 +1117,13 @@
1117
1118 /*
1119 ** Return TRUE if the schema is out-of-date
1120 */
1121 int db_schema_is_outofdate(void){
1122 g.zAuxSchema = db_text(0, "SELECT value FROM config WHERE name='aux-schema'");
1123 return strcmp(g.zAuxSchema,AUX_SCHEMA_MIN)<0
1124 || strcmp(g.zAuxSchema,AUX_SCHEMA_MAX)>0;
1125 }
1126
1127 /*
1128 ** Return true if the database is writeable
1129 */
@@ -1138,14 +1138,14 @@
1138 void db_verify_schema(void){
1139 if( db_schema_is_outofdate() ){
1140 #ifdef FOSSIL_ENABLE_JSON
1141 g.json.resultCode = FSL_JSON_E_DB_NEEDS_REBUILD;
1142 #endif
1143 fossil_warning("incorrect repository schema version: "
1144 "current repository schema version is \"%s\" "
1145 "but need versions between \"%s\" and \"%s\".",
1146 db_get("aux-schema",0), AUX_SCHEMA_MIN, AUX_SCHEMA_MAX);
1147 fossil_fatal("run \"fossil rebuild\" to fix this problem");
1148 }
1149 }
1150
1151
@@ -1393,11 +1393,11 @@
1393 char *zDate;
1394 Blob hash;
1395 Blob manifest;
1396
1397 db_set("content-schema", CONTENT_SCHEMA, 0);
1398 db_set("aux-schema", AUX_SCHEMA_MAX, 0);
1399 db_set("rebuilt", get_version(), 0);
1400 if( makeServerCodes ){
1401 db_setup_server_and_project_codes(0);
1402 }
1403 if( !db_is_global("autosync") ) db_set_int("autosync", 1, 0);
1404
+2 -1
--- src/main.c
+++ src/main.c
@@ -125,10 +125,11 @@
125125
const char *zErrlog; /* Log errors to this file, if not NULL */
126126
int isConst; /* True if the output is unchanging & cacheable */
127127
const char *zVfsName; /* The VFS to use for database connections */
128128
sqlite3 *db; /* The connection to the databases */
129129
sqlite3 *dbConfig; /* Separate connection for global_config table */
130
+ char *zAuxSchema; /* Main repository aux-schema */
130131
int useAttach; /* True if global_config is attached to repository */
131132
const char *zConfigDbName;/* Path of the config database. NULL if not open */
132133
sqlite3_int64 now; /* Seconds since 1970 */
133134
int repositoryOpen; /* True if the main repository database is open */
134135
char *zRepositoryOption; /* Most recent cached repository option value */
@@ -969,11 +970,11 @@
969970
const char *zRc;
970971
#endif
971972
fossil_print("Compiled on %s %s using %s (%d-bit)\n",
972973
__DATE__, __TIME__, COMPILER_NAME, sizeof(void*)*8);
973974
fossil_print("SQLite %s %.30s\n", sqlite3_libversion(), sqlite3_sourceid());
974
- fossil_print("Schema version %s\n", AUX_SCHEMA);
975
+ fossil_print("Schema version %s\n", AUX_SCHEMA_MAX);
975976
#if defined(FOSSIL_ENABLE_MINIZ)
976977
fossil_print("miniz %s, loaded %s\n", MZ_VERSION, mz_version());
977978
#else
978979
fossil_print("zlib %s, loaded %s\n", ZLIB_VERSION, zlibVersion());
979980
#endif
980981
--- src/main.c
+++ src/main.c
@@ -125,10 +125,11 @@
125 const char *zErrlog; /* Log errors to this file, if not NULL */
126 int isConst; /* True if the output is unchanging & cacheable */
127 const char *zVfsName; /* The VFS to use for database connections */
128 sqlite3 *db; /* The connection to the databases */
129 sqlite3 *dbConfig; /* Separate connection for global_config table */
 
130 int useAttach; /* True if global_config is attached to repository */
131 const char *zConfigDbName;/* Path of the config database. NULL if not open */
132 sqlite3_int64 now; /* Seconds since 1970 */
133 int repositoryOpen; /* True if the main repository database is open */
134 char *zRepositoryOption; /* Most recent cached repository option value */
@@ -969,11 +970,11 @@
969 const char *zRc;
970 #endif
971 fossil_print("Compiled on %s %s using %s (%d-bit)\n",
972 __DATE__, __TIME__, COMPILER_NAME, sizeof(void*)*8);
973 fossil_print("SQLite %s %.30s\n", sqlite3_libversion(), sqlite3_sourceid());
974 fossil_print("Schema version %s\n", AUX_SCHEMA);
975 #if defined(FOSSIL_ENABLE_MINIZ)
976 fossil_print("miniz %s, loaded %s\n", MZ_VERSION, mz_version());
977 #else
978 fossil_print("zlib %s, loaded %s\n", ZLIB_VERSION, zlibVersion());
979 #endif
980
--- src/main.c
+++ src/main.c
@@ -125,10 +125,11 @@
125 const char *zErrlog; /* Log errors to this file, if not NULL */
126 int isConst; /* True if the output is unchanging & cacheable */
127 const char *zVfsName; /* The VFS to use for database connections */
128 sqlite3 *db; /* The connection to the databases */
129 sqlite3 *dbConfig; /* Separate connection for global_config table */
130 char *zAuxSchema; /* Main repository aux-schema */
131 int useAttach; /* True if global_config is attached to repository */
132 const char *zConfigDbName;/* Path of the config database. NULL if not open */
133 sqlite3_int64 now; /* Seconds since 1970 */
134 int repositoryOpen; /* True if the main repository database is open */
135 char *zRepositoryOption; /* Most recent cached repository option value */
@@ -969,11 +970,11 @@
970 const char *zRc;
971 #endif
972 fossil_print("Compiled on %s %s using %s (%d-bit)\n",
973 __DATE__, __TIME__, COMPILER_NAME, sizeof(void*)*8);
974 fossil_print("SQLite %s %.30s\n", sqlite3_libversion(), sqlite3_sourceid());
975 fossil_print("Schema version %s\n", AUX_SCHEMA_MAX);
976 #if defined(FOSSIL_ENABLE_MINIZ)
977 fossil_print("miniz %s, loaded %s\n", MZ_VERSION, mz_version());
978 #else
979 fossil_print("zlib %s, loaded %s\n", ZLIB_VERSION, zlibVersion());
980 #endif
981
+14 -4
--- src/manifest.c
+++ src/manifest.c
@@ -1783,14 +1783,24 @@
17831783
}else{
17841784
sqlite3_snprintf(sizeof(zBaseId), zBaseId, "NULL");
17851785
}
17861786
for(i=0; i<p->nParent; i++){
17871787
int pid = uuid_to_rid(p->azParent[i], 1);
1788
- db_multi_exec(
1789
- "INSERT OR IGNORE INTO plink(pid, cid, isprim, mtime, baseid)"
1790
- "VALUES(%d, %d, %d, %.17g, %s)",
1791
- pid, rid, i==0, p->rDate, zBaseId/*safe-for-%s*/);
1788
+ if( strcmp(g.zAuxSchema,"2014-11-24 20:35")>=0 ){
1789
+ /* Support for PLINK.BASEID added on 2014-11-24 */
1790
+ db_multi_exec(
1791
+ "INSERT OR IGNORE INTO plink(pid, cid, isprim, mtime, baseid)"
1792
+ "VALUES(%d, %d, %d, %.17g, %s)",
1793
+ pid, rid, i==0, p->rDate, zBaseId/*safe-for-%s*/);
1794
+ }else{
1795
+ /* Continue to work with older schema to avoid an unnecessary
1796
+ ** rebuild */
1797
+ db_multi_exec(
1798
+ "INSERT OR IGNORE INTO plink(pid, cid, isprim, mtime)"
1799
+ "VALUES(%d, %d, %d, %.17g)",
1800
+ pid, rid, i==0, p->rDate);
1801
+ }
17921802
if( i==0 ){
17931803
add_mlink(pid, 0, rid, p);
17941804
parentid = pid;
17951805
}
17961806
}
17971807
--- src/manifest.c
+++ src/manifest.c
@@ -1783,14 +1783,24 @@
1783 }else{
1784 sqlite3_snprintf(sizeof(zBaseId), zBaseId, "NULL");
1785 }
1786 for(i=0; i<p->nParent; i++){
1787 int pid = uuid_to_rid(p->azParent[i], 1);
1788 db_multi_exec(
1789 "INSERT OR IGNORE INTO plink(pid, cid, isprim, mtime, baseid)"
1790 "VALUES(%d, %d, %d, %.17g, %s)",
1791 pid, rid, i==0, p->rDate, zBaseId/*safe-for-%s*/);
 
 
 
 
 
 
 
 
 
 
1792 if( i==0 ){
1793 add_mlink(pid, 0, rid, p);
1794 parentid = pid;
1795 }
1796 }
1797
--- src/manifest.c
+++ src/manifest.c
@@ -1783,14 +1783,24 @@
1783 }else{
1784 sqlite3_snprintf(sizeof(zBaseId), zBaseId, "NULL");
1785 }
1786 for(i=0; i<p->nParent; i++){
1787 int pid = uuid_to_rid(p->azParent[i], 1);
1788 if( strcmp(g.zAuxSchema,"2014-11-24 20:35")>=0 ){
1789 /* Support for PLINK.BASEID added on 2014-11-24 */
1790 db_multi_exec(
1791 "INSERT OR IGNORE INTO plink(pid, cid, isprim, mtime, baseid)"
1792 "VALUES(%d, %d, %d, %.17g, %s)",
1793 pid, rid, i==0, p->rDate, zBaseId/*safe-for-%s*/);
1794 }else{
1795 /* Continue to work with older schema to avoid an unnecessary
1796 ** rebuild */
1797 db_multi_exec(
1798 "INSERT OR IGNORE INTO plink(pid, cid, isprim, mtime)"
1799 "VALUES(%d, %d, %d, %.17g)",
1800 pid, rid, i==0, p->rDate);
1801 }
1802 if( i==0 ){
1803 add_mlink(pid, 0, rid, p);
1804 parentid = pid;
1805 }
1806 }
1807
+1 -1
--- src/rebuild.c
+++ src/rebuild.c
@@ -591,11 +591,11 @@
591591
reconstruct_private_table();
592592
db_multi_exec(
593593
"REPLACE INTO config(name,value,mtime) VALUES('content-schema',%Q,now());"
594594
"REPLACE INTO config(name,value,mtime) VALUES('aux-schema',%Q,now());"
595595
"REPLACE INTO config(name,value,mtime) VALUES('rebuilt',%Q,now());",
596
- CONTENT_SCHEMA, AUX_SCHEMA, get_version()
596
+ CONTENT_SCHEMA, AUX_SCHEMA_MAX, get_version()
597597
);
598598
if( errCnt && !forceFlag ){
599599
fossil_print(
600600
"%d errors. Rolling back changes. Use --force to force a commit.\n",
601601
errCnt
602602
--- src/rebuild.c
+++ src/rebuild.c
@@ -591,11 +591,11 @@
591 reconstruct_private_table();
592 db_multi_exec(
593 "REPLACE INTO config(name,value,mtime) VALUES('content-schema',%Q,now());"
594 "REPLACE INTO config(name,value,mtime) VALUES('aux-schema',%Q,now());"
595 "REPLACE INTO config(name,value,mtime) VALUES('rebuilt',%Q,now());",
596 CONTENT_SCHEMA, AUX_SCHEMA, get_version()
597 );
598 if( errCnt && !forceFlag ){
599 fossil_print(
600 "%d errors. Rolling back changes. Use --force to force a commit.\n",
601 errCnt
602
--- src/rebuild.c
+++ src/rebuild.c
@@ -591,11 +591,11 @@
591 reconstruct_private_table();
592 db_multi_exec(
593 "REPLACE INTO config(name,value,mtime) VALUES('content-schema',%Q,now());"
594 "REPLACE INTO config(name,value,mtime) VALUES('aux-schema',%Q,now());"
595 "REPLACE INTO config(name,value,mtime) VALUES('rebuilt',%Q,now());",
596 CONTENT_SCHEMA, AUX_SCHEMA_MAX, get_version()
597 );
598 if( errCnt && !forceFlag ){
599 fossil_print(
600 "%d errors. Rolling back changes. Use --force to force a commit.\n",
601 errCnt
602
+2 -1
--- src/schema.c
+++ src/schema.c
@@ -44,11 +44,12 @@
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 "2014-11-24 20:35"
49
+#define AUX_SCHEMA_MIN "2011-04-25 19:50"
50
+#define AUX_SCHEMA_MAX "2014-11-24 20:35"
5051
5152
#endif /* INTERFACE */
5253
5354
5455
/*
5556
--- src/schema.c
+++ src/schema.c
@@ -44,11 +44,12 @@
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 "2014-11-24 20:35"
 
50
51 #endif /* INTERFACE */
52
53
54 /*
55
--- src/schema.c
+++ src/schema.c
@@ -44,11 +44,12 @@
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 "2014-11-24 20:35"
51
52 #endif /* INTERFACE */
53
54
55 /*
56

Keyboard Shortcuts

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