diff options
author | Emmanuel Vasilakis <mrzammler@mm.st> | 2023-06-05 18:16:28 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-05 18:16:28 +0300 |
commit | 81174475a315fdf5a0b6d23bd5edbae82d028cb1 (patch) | |
tree | babac50e663952097bb8db5aacf544ce744984cf /database/sqlite/sqlite_db_migration.c | |
parent | cfc91853eb8ed17572076e9ebc26a40d40391402 (diff) |
Generate, store and transmit a unique alert event_hash_id (#15111)
* generate and store an event_hash_id
* transmit to cloud
* transmit to the cloud
Diffstat (limited to 'database/sqlite/sqlite_db_migration.c')
-rw-r--r-- | database/sqlite/sqlite_db_migration.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/database/sqlite/sqlite_db_migration.c b/database/sqlite/sqlite_db_migration.c index beea37627e..9c7235fdb6 100644 --- a/database/sqlite/sqlite_db_migration.c +++ b/database/sqlite/sqlite_db_migration.c @@ -182,6 +182,38 @@ static int do_migration_v6_v7(sqlite3 *database, const char *name) return 0; } +static int do_migration_v7_v8(sqlite3 *database, const char *name) +{ + UNUSED(name); + info("Running database migration %s", name); + + char sql[256]; + + int rc; + sqlite3_stmt *res = NULL; + snprintfz(sql, 255, "SELECT name FROM sqlite_schema WHERE type ='table' AND name LIKE 'health_log_%%';"); + rc = sqlite3_prepare_v2(database, sql, -1, &res, 0); + if (rc != SQLITE_OK) { + error_report("Failed to prepare statement to alter health_log tables"); + return 1; + } + + while (sqlite3_step_monitored(res) == SQLITE_ROW) { + char *table = strdupz((char *) sqlite3_column_text(res, 0)); + if (!column_exists_in_table(table, "transition_id")) { + snprintfz(sql, 255, "ALTER TABLE %s ADD transition_id blob", table); + sqlite3_exec_monitored(database, sql, 0, 0, NULL); + } + freez(table); + } + + rc = sqlite3_finalize(res); + if (unlikely(rc != SQLITE_OK)) + error_report("Failed to finalize statement when altering health_log tables, rc = %d", rc); + + return 0; +} + static int do_migration_noop(sqlite3 *database, const char *name) { @@ -233,6 +265,7 @@ DATABASE_FUNC_MIGRATION_LIST migration_action[] = { {.name = "v4 to v5", .func = do_migration_v4_v5}, {.name = "v5 to v6", .func = do_migration_v5_v6}, {.name = "v6 to v7", .func = do_migration_v6_v7}, + {.name = "v7 to v8", .func = do_migration_v7_v8}, // the terminator of this array {.name = NULL, .func = NULL} }; |