Fossil SCM

Factor out the ALTER TABLE statements that add the JX column to the USER and REPORTFMT tables into separate subroutines.

drh 2022-11-18 12:11 json-meta-data
Commit 8f6d7dacbbfeb165b37efa6eb169e8e6c7116abbd9cfb2e7fc3d281ef08d01ed
+4 -9
--- src/configure.c
+++ src/configure.c
@@ -447,19 +447,14 @@
447447
blob_append_sql(&sql, ",%s", azToken[jj+1] /*safe-for-%s*/);
448448
}
449449
db_protect_only(PROTECT_SENSITIVE);
450450
451451
/* Make sure tables have the "jx" column */
452
- if( strcmp(&zName[1],"user")==0
453
- && db_table_has_column("repository","user","jx")==0
454
- ){
455
- db_multi_exec("ALTER TABLE repository.user ADD COLUMN jx TEXT");
456
- }else
457
- if( strcmp(&zName[1],"reportfmt")==0
458
- && db_table_has_column("repository","reportfmt","jx")==0
459
- ){
460
- db_multi_exec("ALTER TABLE repository.reportfmt ADD COLUMN jx TEXT");
452
+ if( strcmp(&zName[1],"user")==0 ){
453
+ user_update_user_table();
454
+ }else if( strcmp(&zName[1],"reportfmt")==0 ){
455
+ report_update_reportfmt_table();
461456
}
462457
463458
db_multi_exec("%s)", blob_sql_text(&sql));
464459
465460
if( db_changes()==0 ){
466461
--- src/configure.c
+++ src/configure.c
@@ -447,19 +447,14 @@
447 blob_append_sql(&sql, ",%s", azToken[jj+1] /*safe-for-%s*/);
448 }
449 db_protect_only(PROTECT_SENSITIVE);
450
451 /* Make sure tables have the "jx" column */
452 if( strcmp(&zName[1],"user")==0
453 && db_table_has_column("repository","user","jx")==0
454 ){
455 db_multi_exec("ALTER TABLE repository.user ADD COLUMN jx TEXT");
456 }else
457 if( strcmp(&zName[1],"reportfmt")==0
458 && db_table_has_column("repository","reportfmt","jx")==0
459 ){
460 db_multi_exec("ALTER TABLE repository.reportfmt ADD COLUMN jx TEXT");
461 }
462
463 db_multi_exec("%s)", blob_sql_text(&sql));
464
465 if( db_changes()==0 ){
466
--- src/configure.c
+++ src/configure.c
@@ -447,19 +447,14 @@
447 blob_append_sql(&sql, ",%s", azToken[jj+1] /*safe-for-%s*/);
448 }
449 db_protect_only(PROTECT_SENSITIVE);
450
451 /* Make sure tables have the "jx" column */
452 if( strcmp(&zName[1],"user")==0 ){
453 user_update_user_table();
454 }else if( strcmp(&zName[1],"reportfmt")==0 ){
455 report_update_reportfmt_table();
 
 
 
 
 
456 }
457
458 db_multi_exec("%s)", blob_sql_text(&sql));
459
460 if( db_changes()==0 ){
461
+13
--- src/report.c
+++ src/report.c
@@ -253,10 +253,23 @@
253253
break;
254254
}
255255
}
256256
return rc;
257257
}
258
+
259
+/*
260
+** Make sure the reportfmt table is up-to-date. It should contain
261
+** the "jx" column (as of version 2.21). If it does not, add it.
262
+**
263
+** The "jx" column is intended to hold a JSON object containing optional
264
+** key-value pairs.
265
+*/
266
+void report_update_reportfmt_table(void){
267
+ if( db_table_has_column("repository","reportfmt","jx")==0 ){
268
+ db_multi_exec("ALTER TABLE repository.reportfmt ADD COLUMN jx TEXT;");
269
+ }
270
+}
258271
259272
/*
260273
** Activate the ticket report query authorizer. Must be followed by an
261274
** eventual call to report_unrestrict_sql().
262275
*/
263276
--- src/report.c
+++ src/report.c
@@ -253,10 +253,23 @@
253 break;
254 }
255 }
256 return rc;
257 }
 
 
 
 
 
 
 
 
 
 
 
 
 
258
259 /*
260 ** Activate the ticket report query authorizer. Must be followed by an
261 ** eventual call to report_unrestrict_sql().
262 */
263
--- src/report.c
+++ src/report.c
@@ -253,10 +253,23 @@
253 break;
254 }
255 }
256 return rc;
257 }
258
259 /*
260 ** Make sure the reportfmt table is up-to-date. It should contain
261 ** the "jx" column (as of version 2.21). If it does not, add it.
262 **
263 ** The "jx" column is intended to hold a JSON object containing optional
264 ** key-value pairs.
265 */
266 void report_update_reportfmt_table(void){
267 if( db_table_has_column("repository","reportfmt","jx")==0 ){
268 db_multi_exec("ALTER TABLE repository.reportfmt ADD COLUMN jx TEXT;");
269 }
270 }
271
272 /*
273 ** Activate the ticket report query authorizer. Must be followed by an
274 ** eventual call to report_unrestrict_sql().
275 */
276
+13
--- src/user.c
+++ src/user.c
@@ -573,10 +573,23 @@
573573
user_select();
574574
fossil_print("Final g.zLogin: %s\n", g.zLogin);
575575
fossil_print("Final g.userUid: %d\n", g.userUid);
576576
}
577577
578
+
579
+/*
580
+** Make sure the USER table is up-to-date. It should contain
581
+** the "JX" column (as of version 2.21). If it does not, add it.
582
+**
583
+** The "JX" column is intended to hold a JSON object containing optional
584
+** key-value pairs.
585
+*/
586
+void user_update_user_table(void){
587
+ if( db_table_has_column("repository","user","jx")==0 ){
588
+ db_multi_exec("ALTER TABLE repository.user ADD COLUMN jx TEXT;");
589
+ }
590
+}
578591
579592
/*
580593
** COMMAND: test-hash-passwords
581594
**
582595
** Usage: %fossil test-hash-passwords REPOSITORY
583596
--- src/user.c
+++ src/user.c
@@ -573,10 +573,23 @@
573 user_select();
574 fossil_print("Final g.zLogin: %s\n", g.zLogin);
575 fossil_print("Final g.userUid: %d\n", g.userUid);
576 }
577
 
 
 
 
 
 
 
 
 
 
 
 
 
578
579 /*
580 ** COMMAND: test-hash-passwords
581 **
582 ** Usage: %fossil test-hash-passwords REPOSITORY
583
--- src/user.c
+++ src/user.c
@@ -573,10 +573,23 @@
573 user_select();
574 fossil_print("Final g.zLogin: %s\n", g.zLogin);
575 fossil_print("Final g.userUid: %d\n", g.userUid);
576 }
577
578
579 /*
580 ** Make sure the USER table is up-to-date. It should contain
581 ** the "JX" column (as of version 2.21). If it does not, add it.
582 **
583 ** The "JX" column is intended to hold a JSON object containing optional
584 ** key-value pairs.
585 */
586 void user_update_user_table(void){
587 if( db_table_has_column("repository","user","jx")==0 ){
588 db_multi_exec("ALTER TABLE repository.user ADD COLUMN jx TEXT;");
589 }
590 }
591
592 /*
593 ** COMMAND: test-hash-passwords
594 **
595 ** Usage: %fossil test-hash-passwords REPOSITORY
596

Keyboard Shortcuts

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