ENGINE-532 (ENGINE-531): Removed device_group from DDL ENGINE-531
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Fri, 29 Mar 2019 09:22:06 +0100
branchENGINE-531
changeset 342060ed7ce30858
parent 3419 4d74b3f06a4a
child 3421 d7fc3647f02b
ENGINE-532 (ENGINE-531): Removed device_group from DDL
src/pEpEngine.c
src/pEpEngine.h
src/pEp_internal.h
     1.1 --- a/src/pEpEngine.c	Fri Mar 29 08:39:28 2019 +0100
     1.2 +++ b/src/pEpEngine.c	Fri Mar 29 09:22:06 2019 +0100
     1.3 @@ -163,9 +163,8 @@
     1.4  // Set person, but if already exist, only update.
     1.5  // if main_key_id already set, don't touch.
     1.6  static const char *sql_set_person = 
     1.7 -     "insert into person (id, username, lang, main_key_id, device_group)"
     1.8 -     "  values (?1, ?2, ?3, ?4, "
     1.9 -     "          (select device_group from person where id = ?1)) ;";
    1.10 +     "insert into person (id, username, lang, main_key_id)"
    1.11 +     "  values (?1, ?2, ?3, ?4) ;";
    1.12  
    1.13  static const char *sql_update_person = 
    1.14      "update person "
    1.15 @@ -174,9 +173,7 @@
    1.16      "       main_key_id =  "
    1.17      "           (select coalesce( "
    1.18      "               (select main_key_id from person where id = ?1), " 
    1.19 -    "                upper(replace(?4,' ','')))),"         
    1.20 -    "       device_group = "
    1.21 -    "           (select device_group from person where id = ?1)"
    1.22 +    "                upper(replace(?4,' ',''))))"         
    1.23      "   where id = ?1 ;";
    1.24  
    1.25  // Will cascade.
    1.26 @@ -195,10 +192,6 @@
    1.27      "select count(*) from person "
    1.28      "   where id = ?1 ;";
    1.29  
    1.30 -static const char *sql_set_device_group = 
    1.31 -    "update person set device_group = ?1 "
    1.32 -    "   where id = ?2;";
    1.33 -
    1.34  // This will cascade to identity and trust
    1.35  static const char* sql_replace_userid =
    1.36      "update person set id = ?1 " 
    1.37 @@ -230,10 +223,6 @@
    1.38      "       limit 1) "
    1.39      "where id = ?1 ; ";
    1.40  
    1.41 -static const char *sql_get_device_group = 
    1.42 -    "select device_group from person "
    1.43 -    "where id = ?1;";
    1.44 -
    1.45  static const char *sql_set_pgp_keypair = 
    1.46      "insert or ignore into pgp_keypair (fpr) "
    1.47      "values (upper(replace(?1,' ',''))) ;";
    1.48 @@ -737,7 +726,7 @@
    1.49      sqlite3_busy_timeout(_session->system_db, 1000);
    1.50  
    1.51  // increment this when patching DDL
    1.52 -#define _DDL_USER_VERSION "9"
    1.53 +#define _DDL_USER_VERSION "10"
    1.54  
    1.55      if (in_first) {
    1.56  
    1.57 @@ -784,7 +773,7 @@
    1.58                  "       on delete set null,\n"
    1.59                  "   lang text,\n"
    1.60                  "   comment text,\n"
    1.61 -                "   device_group text,\n"
    1.62 +//                "   device_group text,\n"
    1.63                  "   is_pEp_user integer default 0\n"
    1.64                  ");\n"
    1.65                  "create table if not exists identity (\n"
    1.66 @@ -904,7 +893,10 @@
    1.67          if (version == 1) {
    1.68              bool version_changed = true;
    1.69              if (db_contains_table(_session, "social_graph") > 0) {
    1.70 -                version = 9;
    1.71 +                if (!table_contains_column(_session, "person", "device_group"))
    1.72 +                    version = 10;
    1.73 +                else
    1.74 +                    version = 9;
    1.75              }            
    1.76              else if (table_contains_column(_session, "identity", "timestamp") > 0) {
    1.77                  version = 8;
    1.78 @@ -967,12 +959,13 @@
    1.79              // }
    1.80              
    1.81              if (version < 2) {
    1.82 +                // N.B. addition of device_group column removed in DDL v10
    1.83                  int_result = sqlite3_exec(
    1.84                      _session->db,
    1.85                      "alter table pgp_keypair\n"
    1.86 -                    "   add column flags integer default 0;\n"
    1.87 -                    "alter table person\n"
    1.88 -                    "   add column device_group text;\n",
    1.89 +                    "   add column flags integer default 0;\n",
    1.90 +                    // "alter table person\n"
    1.91 +                    // "   add column device_group text;\n",
    1.92                      NULL,
    1.93                      NULL,
    1.94                      NULL
    1.95 @@ -1176,6 +1169,40 @@
    1.96                  );
    1.97                  assert(int_result == SQLITE_OK);    
    1.98              }
    1.99 +            if (version < 10 && version > 1) {
   1.100 +                int_result = sqlite3_exec(
   1.101 +                    _session->db,                
   1.102 +                    "PRAGMA foreign_keys=off;\n"
   1.103 +                    "BEGIN TRANSACTION;\n"
   1.104 +                    "ALTER TABLE person RENAME TO _person_old;\n"                
   1.105 +                    "create table if not exists person (\n"
   1.106 +                    "   id text primary key,\n"
   1.107 +                    "   username text not null,\n"
   1.108 +                    "   main_key_id text\n"
   1.109 +                    "       references pgp_keypair (fpr)\n"
   1.110 +                    "       on delete set null,\n"
   1.111 +                    "   lang text,\n"
   1.112 +                    "   comment text,\n"
   1.113 +                    "   is_pEp_user integer default 0\n"
   1.114 +                    ");\n"
   1.115 +                    "INSERT INTO person (id, username, main_key_id, "
   1.116 +                    "                    lang, comment, is_pEp_user) "
   1.117 +                    "   SELECT _person_old.id, _person_old.username, "
   1.118 +                    "          _person_old.main_key_id, _person_old.lang, "
   1.119 +                    "          _person_old.comment, _person_old.is_pEp_user "
   1.120 +                    "   FROM _person_old "
   1.121 +                    "   WHERE 1;\n"
   1.122 +                    "DROP TABLE _person_old;\n"
   1.123 +                    "COMMIT;\n"
   1.124 +                    "\n"
   1.125 +                    "PRAGMA foreign_keys=on;\n"
   1.126 +                    ,
   1.127 +                    NULL,
   1.128 +                    NULL,
   1.129 +                    NULL
   1.130 +                );
   1.131 +                assert(int_result == SQLITE_OK);    
   1.132 +            }
   1.133          }        
   1.134          else { 
   1.135              // Version from DB was 0, it means this is initial setup.
   1.136 @@ -1347,13 +1374,13 @@
   1.137              &_session->get_own_address_binding_from_contact, NULL);
   1.138      assert(int_result == SQLITE_OK);
   1.139  
   1.140 -    int_result = sqlite3_prepare_v2(_session->db, sql_set_device_group,
   1.141 -            (int)strlen(sql_set_device_group), &_session->set_device_group, NULL);
   1.142 -    assert(int_result == SQLITE_OK);
   1.143 -
   1.144 -    int_result = sqlite3_prepare_v2(_session->db, sql_get_device_group,
   1.145 -            (int)strlen(sql_get_device_group), &_session->get_device_group, NULL);
   1.146 -    assert(int_result == SQLITE_OK);
   1.147 +    // int_result = sqlite3_prepare_v2(_session->db, sql_set_device_group,
   1.148 +    //         (int)strlen(sql_set_device_group), &_session->set_device_group, NULL);
   1.149 +    // assert(int_result == SQLITE_OK);
   1.150 +    // 
   1.151 +    // int_result = sqlite3_prepare_v2(_session->db, sql_get_device_group,
   1.152 +    //         (int)strlen(sql_get_device_group), &_session->get_device_group, NULL);
   1.153 +    // assert(int_result == SQLITE_OK);
   1.154  
   1.155      int_result = sqlite3_prepare_v2(_session->db, sql_set_pgp_keypair,
   1.156              (int)strlen(sql_set_pgp_keypair), &_session->set_pgp_keypair,
   1.157 @@ -1638,10 +1665,10 @@
   1.158                  sqlite3_finalize(session->was_id_for_revoke_contacted);   
   1.159              if (session->get_last_contacted)
   1.160                  sqlite3_finalize(session->get_last_contacted);                                       
   1.161 -            if (session->set_device_group)
   1.162 -                sqlite3_finalize(session->set_device_group);
   1.163 -            if (session->get_device_group)
   1.164 -                sqlite3_finalize(session->get_device_group);
   1.165 +            // if (session->set_device_group)
   1.166 +            //     sqlite3_finalize(session->set_device_group);
   1.167 +            // if (session->get_device_group)
   1.168 +            //     sqlite3_finalize(session->get_device_group);
   1.169              if (session->set_pgp_keypair)
   1.170                  sqlite3_finalize(session->set_pgp_keypair);
   1.171              if (session->exists_identity_entry)
   1.172 @@ -3169,93 +3196,93 @@
   1.173      return PEP_STATUS_OK;
   1.174  }
   1.175  
   1.176 -DYNAMIC_API PEP_STATUS set_device_group(
   1.177 -        PEP_SESSION session,
   1.178 -        const char *group_name
   1.179 -    )
   1.180 -{
   1.181 -    int result;
   1.182 -
   1.183 -    assert(session);
   1.184 -
   1.185 -    if (!(session && group_name))
   1.186 -        return PEP_ILLEGAL_VALUE;
   1.187 -
   1.188 -    // 1. Get own user_id
   1.189 -    char* user_id = NULL;
   1.190 -    PEP_STATUS status = get_default_own_userid(session, &user_id);
   1.191 -    
   1.192 -    // No user_id is returned in this case, no need to free;
   1.193 -    if (status != PEP_STATUS_OK)
   1.194 -        return status;
   1.195 -        
   1.196 -    // 2. Set device group
   1.197 -    sqlite3_reset(session->set_device_group);
   1.198 -    if(group_name){
   1.199 -        sqlite3_bind_text(session->set_device_group, 1, group_name, -1,
   1.200 -                SQLITE_STATIC);
   1.201 -    } else {
   1.202 -        sqlite3_bind_null(session->set_device_group, 1);
   1.203 -    }
   1.204 -    
   1.205 -    sqlite3_bind_text(session->set_device_group, 2, user_id, -1,
   1.206 -            SQLITE_STATIC);
   1.207 -
   1.208 -    result = sqlite3_step(session->set_device_group);
   1.209 -    sqlite3_reset(session->set_device_group);
   1.210 -    
   1.211 -    free(user_id);
   1.212 -    
   1.213 -    if (result != SQLITE_DONE)
   1.214 -        return PEP_CANNOT_SET_PERSON;
   1.215 -
   1.216 -    return PEP_STATUS_OK;
   1.217 -}
   1.218 -
   1.219 -DYNAMIC_API PEP_STATUS get_device_group(PEP_SESSION session, char **group_name)
   1.220 -{
   1.221 -    PEP_STATUS status = PEP_STATUS_OK;
   1.222 -    int result;
   1.223 -
   1.224 -    assert(session);
   1.225 -    assert(group_name);
   1.226 -
   1.227 -    if (!(session && group_name))
   1.228 -        return PEP_ILLEGAL_VALUE;
   1.229 -
   1.230 -    // 1. Get own user_id
   1.231 -    char* user_id = NULL;
   1.232 -    status = get_default_own_userid(session, &user_id);
   1.233 -    
   1.234 -    // No user_id is returned in this case, no need to free;
   1.235 -    if (status != PEP_STATUS_OK)
   1.236 -        return status;
   1.237 -
   1.238 -    // 2. get device group
   1.239 -    sqlite3_reset(session->get_device_group);
   1.240 -    sqlite3_bind_text(session->get_device_group, 1, user_id, -1,
   1.241 -            SQLITE_STATIC);
   1.242 -
   1.243 -    result = sqlite3_step(session->get_device_group);
   1.244 -    switch (result) {
   1.245 -    case SQLITE_ROW: {
   1.246 -        const char *_group_name = (const char *)sqlite3_column_text(session->get_device_group, 0);
   1.247 -        if(_group_name){
   1.248 -            *group_name = strdup(_group_name);
   1.249 -                if(*group_name == NULL)
   1.250 -                    status = PEP_OUT_OF_MEMORY;
   1.251 -        }
   1.252 -        break;
   1.253 -    }
   1.254 - 
   1.255 -    default:
   1.256 -        status = PEP_RECORD_NOT_FOUND;
   1.257 -    }
   1.258 -
   1.259 -    free(user_id);
   1.260 -    sqlite3_reset(session->get_device_group);
   1.261 -    return status;
   1.262 -}
   1.263 +// DYNAMIC_API PEP_STATUS set_device_group(
   1.264 +//         PEP_SESSION session,
   1.265 +//         const char *group_name
   1.266 +//     )
   1.267 +// {
   1.268 +//     int result;
   1.269 +// 
   1.270 +//     assert(session);
   1.271 +// 
   1.272 +//     if (!(session && group_name))
   1.273 +//         return PEP_ILLEGAL_VALUE;
   1.274 +// 
   1.275 +//     // 1. Get own user_id
   1.276 +//     char* user_id = NULL;
   1.277 +//     PEP_STATUS status = get_default_own_userid(session, &user_id);
   1.278 +// 
   1.279 +//     // No user_id is returned in this case, no need to free;
   1.280 +//     if (status != PEP_STATUS_OK)
   1.281 +//         return status;
   1.282 +// 
   1.283 +//     // 2. Set device group
   1.284 +//     sqlite3_reset(session->set_device_group);
   1.285 +//     if(group_name){
   1.286 +//         sqlite3_bind_text(session->set_device_group, 1, group_name, -1,
   1.287 +//                 SQLITE_STATIC);
   1.288 +//     } else {
   1.289 +//         sqlite3_bind_null(session->set_device_group, 1);
   1.290 +//     }
   1.291 +// 
   1.292 +//     sqlite3_bind_text(session->set_device_group, 2, user_id, -1,
   1.293 +//             SQLITE_STATIC);
   1.294 +// 
   1.295 +//     result = sqlite3_step(session->set_device_group);
   1.296 +//     sqlite3_reset(session->set_device_group);
   1.297 +// 
   1.298 +//     free(user_id);
   1.299 +// 
   1.300 +//     if (result != SQLITE_DONE)
   1.301 +//         return PEP_CANNOT_SET_PERSON;
   1.302 +// 
   1.303 +//     return PEP_STATUS_OK;
   1.304 +// }
   1.305 +// 
   1.306 +// DYNAMIC_API PEP_STATUS get_device_group(PEP_SESSION session, char **group_name)
   1.307 +// {
   1.308 +//     PEP_STATUS status = PEP_STATUS_OK;
   1.309 +//     int result;
   1.310 +// 
   1.311 +//     assert(session);
   1.312 +//     assert(group_name);
   1.313 +// 
   1.314 +//     if (!(session && group_name))
   1.315 +//         return PEP_ILLEGAL_VALUE;
   1.316 +// 
   1.317 +//     // 1. Get own user_id
   1.318 +//     char* user_id = NULL;
   1.319 +//     status = get_default_own_userid(session, &user_id);
   1.320 +// 
   1.321 +//     // No user_id is returned in this case, no need to free;
   1.322 +//     if (status != PEP_STATUS_OK)
   1.323 +//         return status;
   1.324 +// 
   1.325 +//     // 2. get device group
   1.326 +//     sqlite3_reset(session->get_device_group);
   1.327 +//     sqlite3_bind_text(session->get_device_group, 1, user_id, -1,
   1.328 +//             SQLITE_STATIC);
   1.329 +// 
   1.330 +//     result = sqlite3_step(session->get_device_group);
   1.331 +//     switch (result) {
   1.332 +//     case SQLITE_ROW: {
   1.333 +//         const char *_group_name = (const char *)sqlite3_column_text(session->get_device_group, 0);
   1.334 +//         if(_group_name){
   1.335 +//             *group_name = strdup(_group_name);
   1.336 +//                 if(*group_name == NULL)
   1.337 +//                     status = PEP_OUT_OF_MEMORY;
   1.338 +//         }
   1.339 +//         break;
   1.340 +//     }
   1.341 +// 
   1.342 +//     default:
   1.343 +//         status = PEP_RECORD_NOT_FOUND;
   1.344 +//     }
   1.345 +// 
   1.346 +//     free(user_id);
   1.347 +//     sqlite3_reset(session->get_device_group);
   1.348 +//     return status;
   1.349 +// }
   1.350  
   1.351  DYNAMIC_API PEP_STATUS set_identity_flags(
   1.352          PEP_SESSION session,
     2.1 --- a/src/pEpEngine.h	Fri Mar 29 08:39:28 2019 +0100
     2.2 +++ b/src/pEpEngine.h	Fri Mar 29 09:22:06 2019 +0100
     2.3 @@ -865,38 +865,38 @@
     2.4          const char* alias_id);
     2.5  
     2.6  
     2.7 -// set_device_group() - update own person's device group
     2.8 -//
     2.9 -//    parameters:
    2.10 -//        session (in)        session handle
    2.11 -//        group_name (in)     new group name
    2.12 -//
    2.13 -//    return value:
    2.14 -//        PEP_STATUS_OK = 0             device group was updated
    2.15 -//        PEP_CANNOT_SET_PERSON         update failed
    2.16 -
    2.17 -DYNAMIC_API PEP_STATUS set_device_group(
    2.18 -        PEP_SESSION session,
    2.19 -        const char *group_name
    2.20 -    );
    2.21 -
    2.22 -// get_device_group() - get own person's device group
    2.23 -//
    2.24 -//    parameters:
    2.25 -//        session (in)        session handle
    2.26 -//        group_name (in)     new group name
    2.27 -//
    2.28 -//    return value:
    2.29 -//        PEP_STATUS_OK = 0             couldn't get device group
    2.30 -//        PEP_RECORD_NOT_FOUND          update failed
    2.31 -//
    2.32 -//    caveat:
    2.33 -//        the ownerships of group_name is going to the caller
    2.34 -
    2.35 -DYNAMIC_API PEP_STATUS get_device_group(
    2.36 -        PEP_SESSION session, 
    2.37 -        char **group_name
    2.38 -    );
    2.39 +// // set_device_group() - update own person's device group
    2.40 +// //
    2.41 +// //    parameters:
    2.42 +// //        session (in)        session handle
    2.43 +// //        group_name (in)     new group name
    2.44 +// //
    2.45 +// //    return value:
    2.46 +// //        PEP_STATUS_OK = 0             device group was updated
    2.47 +// //        PEP_CANNOT_SET_PERSON         update failed
    2.48 +// 
    2.49 +// DYNAMIC_API PEP_STATUS set_device_group(
    2.50 +//         PEP_SESSION session,
    2.51 +//         const char *group_name
    2.52 +//     );
    2.53 +// 
    2.54 +// // get_device_group() - get own person's device group
    2.55 +// //
    2.56 +// //    parameters:
    2.57 +// //        session (in)        session handle
    2.58 +// //        group_name (in)     new group name
    2.59 +// //
    2.60 +// //    return value:
    2.61 +// //        PEP_STATUS_OK = 0             couldn't get device group
    2.62 +// //        PEP_RECORD_NOT_FOUND          update failed
    2.63 +// //
    2.64 +// //    caveat:
    2.65 +// //        the ownerships of group_name is going to the caller
    2.66 +// 
    2.67 +// DYNAMIC_API PEP_STATUS get_device_group(
    2.68 +//         PEP_SESSION session, 
    2.69 +//         char **group_name
    2.70 +//     );
    2.71  
    2.72  // set_identity_flags() - update identity flags on existing identity
    2.73  //
     3.1 --- a/src/pEp_internal.h	Fri Mar 29 08:39:28 2019 +0100
     3.2 +++ b/src/pEp_internal.h	Fri Mar 29 09:22:06 2019 +0100
     3.3 @@ -178,8 +178,8 @@
     3.4      sqlite3_stmt *get_contacted_ids_from_revoke_fpr;
     3.5      sqlite3_stmt *was_id_for_revoke_contacted;
     3.6      sqlite3_stmt *get_last_contacted;
     3.7 -    sqlite3_stmt *set_device_group;
     3.8 -    sqlite3_stmt *get_device_group;
     3.9 +    // sqlite3_stmt *set_device_group;
    3.10 +    // sqlite3_stmt *get_device_group;
    3.11      sqlite3_stmt *set_pgp_keypair;
    3.12      sqlite3_stmt *set_identity_entry;
    3.13      sqlite3_stmt *update_identity_entry;