diff options
author | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-12-05 13:33:58 +0100 |
---|---|---|
committer | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-12-10 16:33:49 +0100 |
commit | 6a63218f85d80919c8bab87141f9f4c9c3acdfdf (patch) | |
tree | b0626321308c88a4b024315fcd1e7e99a139b8b6 /src/schema.c | |
parent | e3188191d9da0e49dd156ea70f59b92776216e8c (diff) |
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.
Diffstat (limited to 'src/schema.c')
-rw-r--r-- | src/schema.c | 37 |
1 files changed, 37 insertions, 0 deletions
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 }, }; |