@cryptotaxi247 / netdata-1 / commits / 3245ee590

Handle agents will wrong alert_hash table definition (#17197)

Redo migration to handle agents will wrong alert_hash table definition

Stelios Fragkakis committed Mar 19, 2024 at 12:41 UTC 3245ee590f0591320cac54d35715b9208d98d17d
2 files changed +20 -1
src/database/sqlite/sqlite_db_migration.c
+19
@@ -161,6 +161,16 @@ const char *database_migrate_v16_v17[] = {
161 NULL
162 };
163
164 +// Note: Same as database_migrate_v16_v17. This is not wrong
165 +// Do additional migration to handle agents that created wrong alert_hash table
166 +const char *database_migrate_v17_v18[] = {
167 + "ALTER TABLE alert_hash ADD time_group_condition INT",
168 + "ALTER TABLE alert_hash ADD time_group_value DOUBLE",
169 + "ALTER TABLE alert_hash ADD dims_group INT",
170 + "ALTER TABLE alert_hash ADD data_source INT",
171 + NULL
172 +};
173 +
174
175 static int do_migration_v1_v2(sqlite3 *database)
176 {
@@ -447,6 +457,14 @@ static int do_migration_v16_v17(sqlite3 *database)
457 return 0;
458 }
459
460 +static int do_migration_v17_v18(sqlite3 *database)
461 +{
462 + if (table_exists_in_database(database, "alert_hash") && !column_exists_in_table(database, "alert_hash", "time_group_condition"))
463 + return init_database_batch(database, &database_migrate_v17_v18[0], "meta_migrate");
464 +
465 + return 0;
466 +}
467 +
468
469 static int do_migration_v12_v13(sqlite3 *database)
470 {
@@ -546,6 +564,7 @@ DATABASE_FUNC_MIGRATION_LIST migration_action[] = {
564 {.name = "v14 to v15", .func = do_migration_v14_v15},
565 {.name = "v15 to v16", .func = do_migration_v15_v16},
566 {.name = "v16 to v17", .func = do_migration_v16_v17},
567 + {.name = "v17 to v18", .func = do_migration_v17_v18},
568 // the terminator of this array
569 {.name = NULL, .func = NULL}
570 };
src/database/sqlite/sqlite_metadata.c
+1 -1
@@ -4,7 +4,7 @@
4 #include "sqlite3recover.h"
5 //#include "sqlite_db_migration.h"
6
7 -#define DB_METADATA_VERSION 17
7 +#define DB_METADATA_VERSION 18
8
9 const char *database_config[] = {
10 "CREATE TABLE IF NOT EXISTS host(host_id BLOB PRIMARY KEY, hostname TEXT NOT NULL, "