ENGINE-382: changed alter table with non-constant default for timestamp to copy-insert-drop for version 8
authorKrista Bennett <krista@pep-project.org>
Fri, 16 Feb 2018 08:35:04 +0100
changeset 2509dde6a233c9dd
parent 2507 27d82316d474
child 2510 9ef5d24075d4
ENGINE-382: changed alter table with non-constant default for timestamp to copy-insert-drop for version 8
src/pEpEngine.c
     1.1 --- a/src/pEpEngine.c	Thu Feb 15 00:36:33 2018 +0100
     1.2 +++ b/src/pEpEngine.c	Fri Feb 16 08:35:04 2018 +0100
     1.3 @@ -976,13 +976,34 @@
     1.4              if (version < 8) {
     1.5                  int_result = sqlite3_exec(
     1.6                      _session->db,
     1.7 -                    "alter table identity \n"
     1.8 -                    "   add column timestamp timestamp integer default (datetime('now'));\n",
     1.9 +                    "PRAGMA foreign_keys=off;\n"
    1.10 +                    "BEGIN TRANSACTION;\n"
    1.11 +                    "ALTER TABLE identity RENAME TO _identity_old;\n"
    1.12 +                    "create table identity (\n"
    1.13 +                    "   address text,\n"
    1.14 +                    "   user_id text\n"
    1.15 +                    "       references person (id)\n"
    1.16 +                    "       on delete cascade on update cascade,\n"
    1.17 +                    "   main_key_id text\n"
    1.18 +                    "       references pgp_keypair (fpr)\n"
    1.19 +                    "       on delete set null,\n"
    1.20 +                    "   comment text,\n"
    1.21 +                    "   flags integer default 0,\n"
    1.22 +                    "   is_own integer default 0,\n"
    1.23 +                    "   timestamp integer default (datetime('now')),\n"
    1.24 +                    "   primary key (address, user_id)\n"
    1.25 +                    ");\n"
    1.26 +                    "INSERT INTO identity SELECT * FROM _identity_old;\n"
    1.27 +                    "DROP TABLE _identity_old;\n"
    1.28 +                    "COMMIT;\n"
    1.29 +                    "\n"
    1.30 +                    "PRAGMA foreign_keys=on;\n"
    1.31 +                    ,
    1.32                      NULL,
    1.33                      NULL,
    1.34                      NULL
    1.35                  );
    1.36 -                assert(int_result == SQLITE_OK);
    1.37 +                assert(int_result == SQLITE_OK);    
    1.38              }
    1.39          }        
    1.40          else {