diff --git a/db/constraints.sql b/db/constraints.sql index c7eb61fb20..bd27b52d1b 100644 --- a/db/constraints.sql +++ b/db/constraints.sql @@ -178,3 +178,9 @@ alter table post_ratings alter table sent_email add index sent_email_userid(userid); -- for delete account + +alter table consent + add index userid_cname(userid, consent_name); + +alter table consent_type + add index consent_name(shortname); diff --git a/db/content.sql b/db/content.sql new file mode 100644 index 0000000000..7512d4eb69 --- /dev/null +++ b/db/content.sql @@ -0,0 +1,9 @@ +/* + This file contants inital content for any tables. + + The table must be first defined in schema.sql before any content + is added! +*/ +insert into consent_type (consent_id, shortname, description, enabled, protected, privacypref) + values (1, 'ENROLL', 'General terms-of-use for this BOINC project.', 0, 1, 0), + (2, 'STATSEXPORT', 'Do you consent to exporting your data to BOINC statistics aggregation Web sites?', 0, 1, 1); diff --git a/db/schema.sql b/db/schema.sql index 29309b459d..d383308cae 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -41,6 +41,8 @@ -- fields ending with id (but not _id) are treated specially -- by the Python code (db_base.py) +-- Put initial content of any table in content.sql, and not in this file. + create table platform ( id integer not null auto_increment, create_time integer not null, @@ -824,7 +826,3 @@ create table consent_type ( privacypref integer not null, primary key (consent_id) ) engine=InnoDB; - -insert into consent_type (consent_id, shortname, description, enabled, protected, privacypref) - values (1, 'ENROLL', 'General terms-of-use for this BOINC project.', 0, 1, 0), - (2, 'STATSEXPORT', 'Do you consent to exporting your data to BOINC statistics aggregation Web sites?', 0, 1, 1); diff --git a/html/ops/db_update.php b/html/ops/db_update.php index 037db08289..f1574e7495 100644 --- a/html/ops/db_update.php +++ b/html/ops/db_update.php @@ -1171,7 +1171,8 @@ function update_5_17_2018() { consent_flag tinyint not null, consent_not_required tinyint not null, source varchar(255) not null, - primary key (id) + primary key (id), + index userid_cname (userid, consent_name) ) engine=InnoDB; "); @@ -1182,13 +1183,14 @@ function update_5_17_2018() { enabled integer not null, protected integer not null, privacypref integer not null, - primary key (consent_id) + primary key (consent_id), + index consent_name (shortname) ) engine=InnoDB; "); do_query("insert into consent_type (consent_id, shortname, description, enabled, protected, privacypref) values - (1, 'ENROLL', 'General terms-of-use for this BOINC project.', 0, 1, 10); + (1, 'ENROLL', 'General terms-of-use for this BOINC project.', 0, 1, 0); "); do_query("insert into consent_type (consent_id, shortname, description, enabled, protected, privacypref) values diff --git a/py/Boinc/database.py b/py/Boinc/database.py index f73807391c..369457d212 100644 --- a/py/Boinc/database.py +++ b/py/Boinc/database.py @@ -281,13 +281,15 @@ def create_database(srcdir, config = None, drop_first = False): import boinc_path_config config = config or configxml.default_config().config connect(config, nodb=True) - cursor = get_dbconnection().cursor() + dbcon = get_dbconnection() + cursor = dbcon.cursor() if drop_first: cursor.execute("drop database if exists %s"%config.db_name) cursor.execute("create database %s"%config.db_name) cursor.execute("use %s"%config.db_name) - for file in ['schema.sql', 'constraints.sql']: + for file in ['schema.sql', 'constraints.sql', 'content.sql']: _execute_sql_script(cursor, os.path.join(srcdir, 'db', file)) + dbcon.commit() cursor.close() # alias