ENGINE-538: fixed part of the upgrade code in default; this will likely impact no one, and testing the SQL will be a bit complicated, but this should at least prevent the worst from happening because of 3.25
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Mon, 08 Apr 2019 10:38:26 +0200
changeset 34640e0f802640bb
parent 3424 ba7efe8cfa2e
child 3472 df00e438b8c4
ENGINE-538: fixed part of the upgrade code in default; this will likely impact no one, and testing the SQL will be a bit complicated, but this should at least prevent the worst from happening because of 3.25
src/pEpEngine.c
     1.1 --- a/src/pEpEngine.c	Mon Apr 01 12:12:48 2019 +0200
     1.2 +++ b/src/pEpEngine.c	Mon Apr 08 10:38:26 2019 +0200
     1.3 @@ -930,8 +930,7 @@
     1.4                      _session->db,
     1.5                      "PRAGMA foreign_keys=off;\n"
     1.6                      "BEGIN TRANSACTION;\n"
     1.7 -                    "ALTER TABLE identity RENAME TO _identity_old;\n"
     1.8 -                    "create table identity (\n"
     1.9 +                    "create table _identity_new (\n"
    1.10                      "   address text,\n"
    1.11                      "   user_id text\n"
    1.12                      "       references person (id)\n"
    1.13 @@ -944,10 +943,13 @@
    1.14                      "   is_own integer default 0,\n"
    1.15                      "   primary key (address, user_id)\n"
    1.16                      ");\n"
    1.17 -                    "INSERT INTO identity SELECT * FROM _identity_old;\n"
    1.18 -                    "DROP TABLE _identity_old;\n"
    1.19 -                    "ALTER TABLE trust RENAME TO _trust_old;\n"
    1.20 -                    "create table trust (\n"
    1.21 +                    "INSERT INTO _identity_new SELECT * FROM identity;\n"
    1.22 +                    "DROP TABLE identity;\n"
    1.23 +                    "ALTER TABLE _identity_new RENAME TO identity;\n"
    1.24 +                    "COMMIT;\n"
    1.25 +                    "\n"
    1.26 +                    "BEGIN_TRANSACTION;\n"
    1.27 +                    "create table _trust_new (\n"
    1.28                      "   user_id text not null\n"
    1.29                      "       references person (id)\n"
    1.30                      "       on delete cascade on update cascade,\n"
    1.31 @@ -958,8 +960,9 @@
    1.32                      "   comment text,\n"
    1.33                      "   primary key (user_id, pgp_keypair_fpr)\n"
    1.34                      ");\n"
    1.35 -                    "INSERT INTO trust SELECT * FROM _trust_old;\n"
    1.36 -                    "DROP TABLE _trust_old;\n"
    1.37 +                    "INSERT INTO _trust_new SELECT * FROM trust;\n"
    1.38 +                    "DROP TABLE trust;\n"
    1.39 +                    "ALTER TABLE _trust_new RENAME TO trust;\n"
    1.40                      "COMMIT;\n"
    1.41                      "\n"
    1.42                      "PRAGMA foreign_keys=on;\n"
    1.43 @@ -1018,8 +1021,7 @@
    1.44                      _session->db,
    1.45                      "PRAGMA foreign_keys=off;\n"
    1.46                      "BEGIN TRANSACTION;\n"
    1.47 -                    "ALTER TABLE identity RENAME TO _identity_old;\n"
    1.48 -                    "create table identity (\n"
    1.49 +                    "create table _identity_new (\n"
    1.50                      "   address text,\n"
    1.51                      "   user_id text\n"
    1.52                      "       references person (id)\n"
    1.53 @@ -1033,14 +1035,15 @@
    1.54                      "   timestamp integer default (datetime('now')),\n"
    1.55                      "   primary key (address, user_id)\n"
    1.56                      ");\n"
    1.57 -                    "INSERT INTO identity (address, user_id, main_key_id, "
    1.58 +                    "INSERT INTO _identity_new (address, user_id, main_key_id, "
    1.59                      "                      comment, flags, is_own) "
    1.60 -                    "   SELECT _identity_old.address, _identity_old.user_id, "
    1.61 -                    "          _identity_old.main_key_id, _identity_old.comment, "
    1.62 -                    "          _identity_old.flags, _identity_old.is_own "
    1.63 -                    "   FROM _identity_old "
    1.64 +                    "   SELECT identity.address, identity.user_id, "
    1.65 +                    "          identity.main_key_id, identity.comment, "
    1.66 +                    "          identity.flags, identity.is_own "
    1.67 +                    "   FROM identity "
    1.68                      "   WHERE 1;\n"
    1.69 -                    "DROP TABLE _identity_old;\n"
    1.70 +                    "DROP TABLE identity;\n"
    1.71 +                    "ALTER TABLE _identity_new RENAME TO identity;\n"
    1.72                      "COMMIT;\n"
    1.73                      "\n"
    1.74                      "PRAGMA foreign_keys=on;\n"