From 6a63218f85d80919c8bab87141f9f4c9c3acdfdf Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Thu, 5 Dec 2024 13:33:58 +0100 Subject: rest: add POST oglive/default Remove 'is_default' column from 'lives' database table and add column 'priority' of type INT. This new value can store a priority value but the actual design only stores 1 or 0. Update GET oglive/list to use the new 'priority' database value. Add POST oglive/default. Set the database column 'priority' to 1 if the new default exists in the database. Set the others to priority 0. Modify legacy ogliveinfo.json if the new default coresponds to a live not found in the database. Edit the field 'default' of the file's json. --- src/schema.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/schema.c') diff --git a/src/schema.c b/src/schema.c index 1c2428c..acc5468 100644 --- a/src/schema.c +++ b/src/schema.c @@ -497,6 +497,42 @@ static int og_dbi_schema_v12(struct og_dbi *dbi) return 0; } +static int og_dbi_schema_v13(struct og_dbi *dbi) +{ + const char *msglog; + dbi_result result; + + syslog(LOG_DEBUG, "Updating table oglive\n"); + result = dbi_conn_query(dbi->conn, "ALTER TABLE `oglive` DROP COLUMN `is_default`"); + if (!result) { + dbi_conn_error(dbi->conn, &msglog); + syslog(LOG_INFO, "Error deleting column is_default in oglive table (%s:%d) %s\n", + __func__, __LINE__, msglog); + return -1; + } + dbi_result_free(result); + + result = dbi_conn_query(dbi->conn, "ALTER TABLE `oglive` ADD COLUMN `priority` INT NOT NULL DEFAULT 0"); + if (!result) { + dbi_conn_error(dbi->conn, &msglog); + syslog(LOG_INFO, "Error adding column priority to oglive table (%s:%d) %s\n", + __func__, __LINE__, msglog); + return -1; + } + dbi_result_free(result); + + result = dbi_conn_query(dbi->conn, "UPDATE version SET version = 13"); + if (!result) { + dbi_conn_error(dbi->conn, &msglog); + syslog(LOG_INFO, "Could not update version row (%s:%d) %s\n", + __func__, __LINE__, msglog); + return -1; + } + dbi_result_free(result); + + return 0; +} + static struct og_schema_version { int version; int (*update)(struct og_dbi *dbi); @@ -513,6 +549,7 @@ static struct og_schema_version { { .version = 10, .update = og_dbi_schema_v10,}, { .version = 11, .update = og_dbi_schema_v11,}, { .version = 12, .update = og_dbi_schema_v12,}, + { .version = 13, .update = og_dbi_schema_v13,}, { 0, NULL }, }; -- cgit v1.2.3-18-g5258