Browse Source

ENGINE-633: Force DB upgrade to message version 2.1 for all pEp partners and 2.2 for all non-group own identities

IPS-2
Krista Bennett 11 months ago
parent
commit
5f5d1f7b37
1 changed files with 98 additions and 60 deletions
  1. +98
    -60
      src/engine_sql.c

+ 98
- 60
src/engine_sql.c View File

@ -1358,50 +1358,7 @@ static PEP_STATUS _upgrade_DB_to_ver_10(PEP_SESSION session) {
return PEP_STATUS_OK;
}
static PEP_STATUS _upgrade_DB_to_ver_12(PEP_SESSION session) {
PEP_STATUS status = PEP_STATUS_OK;
int int_result = sqlite3_exec(
session->db,
"create index if not exists identity_userid_addr on identity(address, user_id);\n",
NULL,
NULL,
NULL
);
assert(int_result == SQLITE_OK);
if (int_result != SQLITE_OK)
return PEP_UNKNOWN_DB_ERROR;
int_result = sqlite3_exec(
session->db,
"alter table identity\n"
" add column pEp_version_major integer default 0;\n"
"alter table identity\n"
" add column pEp_version_minor integer default 0;\n",
NULL,
NULL,
NULL
);
if (status != PEP_STATUS_OK)
return status;
int_result = sqlite3_exec(
session->db,
"update identity\n"
" set pEp_version_major = 2\n"
" where exists (select * from person\n"
" where identity.user_id = person.id\n"
" and identity.is_own = 0\n"
" and person.is_pEp_user = 1);\n",
NULL,
NULL,
NULL
);
if (status != PEP_STATUS_OK)
return status;
static PEP_STATUS _force_upgrade_own_latest_message_version(PEP_SESSION session) {
// N.B. WE DEFINE PEP_VERSION - IF WE'RE AT 9-DIGIT MAJOR OR MINOR VERSIONS, ER, BAD.
char major_buf[10];
char minor_buf[10];
@ -1430,39 +1387,92 @@ static PEP_STATUS _upgrade_DB_to_ver_12(PEP_SESSION session) {
}
*bufptr = '\0';
const char *_ver_12_startstr =
const char *version_upgrade_startstr =
"update identity\n"
" set pEp_version_major = ";
const char *_ver_12_midstr = ",\n"
const char *version_upgrade_midstr = ",\n"
" pEp_version_minor = ";
const char *_ver_12_endstr =
const char *version_upgrade_endstr =
"\n"
" where identity.is_own = 1;\n";
" where identity.is_own = 1;\n"; // FIXME: Group idents?
size_t new_stringlen = strlen(_ver_12_startstr) + major_len +
strlen(_ver_12_midstr) + minor_len +
strlen(_ver_12_endstr);
size_t new_stringlen = strlen(version_upgrade_startstr) + major_len +
strlen(version_upgrade_midstr) + minor_len +
strlen(version_upgrade_endstr);
char *version_upgrade_stmt = calloc(new_stringlen + 1, 1);
snprintf(version_upgrade_stmt, new_stringlen + 1, "%s%s%s%s%s",
version_upgrade_startstr, major_buf, version_upgrade_midstr, minor_buf, version_upgrade_endstr);
int int_result = sqlite3_exec(
session->db,
version_upgrade_stmt,
NULL,
NULL,
NULL
);
free(version_upgrade_stmt);
if (int_result != SQLITE_OK)
return PEP_UNKNOWN_DB_ERROR;
return PEP_STATUS_OK;
}
static PEP_STATUS _upgrade_DB_to_ver_12(PEP_SESSION session) {
int int_result = sqlite3_exec(
session->db,
"create index if not exists identity_userid_addr on identity(address, user_id);\n",
NULL,
NULL,
NULL
);
assert(int_result == SQLITE_OK);
if (int_result != SQLITE_OK)
return PEP_UNKNOWN_DB_ERROR;
char *_ver_12_stmt = calloc(new_stringlen + 1, 1);
snprintf(_ver_12_stmt, new_stringlen + 1, "%s%s%s%s%s",
_ver_12_startstr, major_buf, _ver_12_midstr, minor_buf, _ver_12_endstr);
int_result = sqlite3_exec(
session->db,
_ver_12_stmt,
"alter table identity\n"
" add column pEp_version_major integer default 0;\n"
"alter table identity\n"
" add column pEp_version_minor integer default 0;\n",
NULL,
NULL,
NULL
);
free(_ver_12_stmt);
if (status != PEP_STATUS_OK)
return status;
assert(int_result == SQLITE_OK);
if (int_result != SQLITE_OK)
return PEP_UNKNOWN_DB_ERROR;
int_result = sqlite3_exec(
session->db,
"update identity\n"
" set pEp_version_major = 2,\n"
" pEp_version_minor = 1\n"
" where exists (select * from person\n"
" where identity.user_id = person.id\n"
" and identity.is_own = 0\n"
" and person.is_pEp_user = 1);\n",
NULL,
NULL,
NULL
);
assert(int_result == SQLITE_OK);
if (int_result != SQLITE_OK)
return PEP_UNKNOWN_DB_ERROR;
return PEP_STATUS_OK;
// Superceded by the -to-version-18 upgrade.
// return _force_upgrade_own_latest_message_version(session);
}
static PEP_STATUS _upgrade_DB_to_ver_14(PEP_SESSION session) {
int int_result = sqlite3_exec(
int int_result = sqlite3_exec(
session->db,
"alter table identity\n"
" add column enc_format integer default 0;\n",
@ -1517,7 +1527,32 @@ static PEP_STATUS _upgrade_DB_to_ver_17(PEP_SESSION session) {
return PEP_STATUS_OK;
}
// Version 2.0 and earlier will now no longer be supported with other
// pEp users.
static PEP_STATUS _upgrade_DB_to_ver_18(PEP_SESSION session) {
int int_result = sqlite3_exec(
session->db,
"update identity\n"
" set pEp_version_major = 2,\n"
" pEp_version_minor = 1\n"
" where exists (select * from person\n"
" where identity.user_id = person.id\n"
" and identity.pEp_version_major = 2\n"
" and identity.pEp_version_minor = 0\n"
" and person.is_pEp_user = 1);\n",
NULL,
NULL,
NULL
);
assert(int_result == SQLITE_OK);
if (int_result != SQLITE_OK)
return PEP_UNKNOWN_DB_ERROR;
return _force_upgrade_own_latest_message_version(session);
}
// Honestly, the upgrades should be redone in a transaction IMHO.
static PEP_STATUS _check_and_execute_upgrades(PEP_SESSION session, int version) {
PEP_STATUS status = PEP_STATUS_OK;
@ -1585,6 +1620,10 @@ static PEP_STATUS _check_and_execute_upgrades(PEP_SESSION session, int version)
if (status != PEP_STATUS_OK)
return status;
case 17:
status = _upgrade_DB_to_ver_18(session);
if (status != PEP_STATUS_OK)
return status;
case 18:
break;
default:
return PEP_ILLEGAL_VALUE;
@ -1592,7 +1631,6 @@ static PEP_STATUS _check_and_execute_upgrades(PEP_SESSION session, int version)
return PEP_STATUS_OK;
}
PEP_STATUS pEp_sql_init(PEP_SESSION session) {
bool very_first = false;
PEP_STATUS status = create_tables(session);


Loading…
Cancel
Save