@cryptotaxi247 / netdata-1 / commits / ce06ace57

Fix summary field in table (#16050)

fix summary field in table

Emmanuel Vasilakis committed Sep 26, 2023 at 12:52 UTC ce06ace57d195c28d329bd77cfcbd2ab54d82d71
2 files changed +30 -2
database/sqlite/sqlite_db_migration.c
+29 -1
@@ -94,6 +94,16 @@ const char *database_migrate_v11_v12[] = {
94 NULL
95 };
96
97 +const char *database_migrate_v12_v13_detail[] = {
98 + "ALTER TABLE health_log_detail ADD summary TEXT;",
99 + NULL
100 +};
101 +
102 +const char *database_migrate_v12_v13_hash[] = {
103 + "ALTER TABLE alert_hash ADD summary TEXT;",
104 + NULL
105 +};
106 +
107 static int do_migration_v1_v2(sqlite3 *database, const char *name)
108 {
109 UNUSED(name);
@@ -250,7 +260,7 @@ static int do_migration_v8_v9(sqlite3 *database, const char *name)
260 "updated_by_id int, updates_id int, when_key int, duration int, non_clear_duration int, " \
261 "flags int, exec_run_timestamp int, delay_up_to_timestamp int, " \
262 "info text, exec_code int, new_status real, old_status real, delay int, " \
253 - "new_value double, old_value double, last_repeat int, transition_id blob, global_id int, host_id blob);");
263 + "new_value double, old_value double, last_repeat int, transition_id blob, global_id int, summary text, host_id blob);");
264 sqlite3_exec_monitored(database, sql, 0, 0, NULL);
265
266 snprintfz(sql, 2047, "CREATE INDEX IF NOT EXISTS health_log_d_ind_1 ON health_log_detail (unique_id);");
@@ -338,6 +348,23 @@ static int do_migration_v11_v12(sqlite3 *database, const char *name)
348 return rc;
349 }
350
351 +static int do_migration_v12_v13(sqlite3 *database, const char *name)
352 +{
353 + int rc = 0;
354 +
355 + netdata_log_info("Running \"%s\" database migration", name);
356 +
357 + if (table_exists_in_database("health_log_detail") && !column_exists_in_table("health_log_detail", "summary")) {
358 + rc = init_database_batch(database, &database_migrate_v12_v13_detail[0]);
359 + sqlite3_exec_monitored(database, MIGR_11_12_UPD_HEALTH_LOG_DETAIL, 0, 0, NULL);
360 + }
361 +
362 + if (table_exists_in_database("alert_hash") && !column_exists_in_table("alert_hash", "summary"))
363 + rc = init_database_batch(database, &database_migrate_v12_v13_hash[0]);
364 +
365 + return rc;
366 +}
367 +
368 static int do_migration_noop(sqlite3 *database, const char *name)
369 {
370 UNUSED(database);
@@ -393,6 +420,7 @@ DATABASE_FUNC_MIGRATION_LIST migration_action[] = {
420 {.name = "v9 to v10", .func = do_migration_v9_v10},
421 {.name = "v10 to v11", .func = do_migration_v10_v11},
422 {.name = "v11 to v12", .func = do_migration_v11_v12},
423 + {.name = "v12 to v13", .func = do_migration_v12_v13},
424 // the terminator of this array
425 {.name = NULL, .func = NULL}
426 };
database/sqlite/sqlite_functions.c
+1 -1
@@ -4,7 +4,7 @@
4 #include "sqlite3recover.h"
5 #include "sqlite_db_migration.h"
6
7 -#define DB_METADATA_VERSION 12
7 +#define DB_METADATA_VERSION 13
8
9 const char *database_config[] = {
10 "CREATE TABLE IF NOT EXISTS host(host_id BLOB PRIMARY KEY, hostname TEXT NOT NULL, "