This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.
gerrit-no-reply at lists.osmocom.org gerrit-no-reply at lists.osmocom.org>From Vadim Yanitskiy <axilirator at gmail.com>: Vadim Yanitskiy has uploaded a new change for review. https://gerrit.osmocom.org/62 Change subject: db.c: implemented incremental migration ...................................................................... db.c: implemented incremental migration In the past, normal migration was possible only if the actual schema version differed from the version used in DB by 1. For example, if DB uses an old version 3 and you need to use it with the code written for version 5, the check_db_revision() will convert it to 4 and DB will still use incompatible schema version during Osmo-NITB running time. After next run it will be converted to version 5. This patch replaces a set of 'else-if' checks by a 'switch' without 'break' statements between 'case' labels (waterfall). It makes you able to migrate from current version to the latest despite any difference between them. Change-Id: Ia9c2aa86f96b88ad8a710d0a23879ce219bc82dc --- M openbsc/src/libmsc/db.c 1 file changed, 35 insertions(+), 18 deletions(-) git pull ssh://gerrit.osmocom.org:29418/openbsc refs/changes/62/62/1 diff --git a/openbsc/src/libmsc/db.c b/openbsc/src/libmsc/db.c index e5017ae..b3235bb 100644 --- a/openbsc/src/libmsc/db.c +++ b/openbsc/src/libmsc/db.c @@ -374,9 +374,13 @@ { dbi_result result; const char *rev_s; + int db_rev = 0; + /* Make a query */ result = dbi_conn_query(conn, - "SELECT value FROM Meta WHERE key='revision'"); + "SELECT value FROM Meta " + "WHERE key = 'revision'"); + if (!result) return -EINVAL; @@ -384,33 +388,46 @@ dbi_result_free(result); return -EINVAL; } + + /* Fetch the DB schema revision */ rev_s = dbi_result_get_string(result, "value"); if (!rev_s) { dbi_result_free(result); return -EINVAL; } - if (!strcmp(rev_s, "2")) { - if (update_db_revision_2()) { - LOGP(DDB, LOGL_FATAL, "Failed to update database from schema revision '%s'.\n", rev_s); - dbi_result_free(result); - return -EINVAL; - } - } else if (!strcmp(rev_s, "3")) { - if (update_db_revision_3()) { - LOGP(DDB, LOGL_FATAL, "Failed to update database from schema revision '%s'.\n", rev_s); - dbi_result_free(result); - return -EINVAL; - } - } else if (!strcmp(rev_s, SCHEMA_REVISION)) { - /* everything is fine */ - } else { - LOGP(DDB, LOGL_FATAL, "Invalid database schema revision '%s'.\n", rev_s); + + if (!strcmp(rev_s, SCHEMA_REVISION)) { + /* Everything is fine */ dbi_result_free(result); + return 0; + } + + db_rev = atoi(rev_s); + dbi_result_free(result); + + /* Incremental migration waterfall */ + switch (db_rev) { + case 2: + if (update_db_revision_2()) + goto error; + case 3: + if (update_db_revision_3()) + goto error; + + /* The end of waterfall */ + break; + default: + LOGP(DDB, LOGL_FATAL, + "Invalid database schema revision '%d'.\n", db_rev); return -EINVAL; } - dbi_result_free(result); return 0; + +error: + LOGP(DDB, LOGL_FATAL, "Failed to update database " + "from schema revision '%d'.\n", db_rev); + return -EINVAL; } static int db_configure(void) -- To view, visit https://gerrit.osmocom.org/62 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia9c2aa86f96b88ad8a710d0a23879ce219bc82dc Gerrit-PatchSet: 1 Gerrit-Project: openbsc Gerrit-Branch: master Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>