summaryrefslogtreecommitdiffstats
path: root/src/schema.c
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-09-24 13:38:34 +0200
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-09-25 12:09:32 +0200
commitc7bfc370ae8974302cf1e316b3e03d0e6e960e0c (patch)
treeba6c9570f07cf6b76048405c8b6bb8ea3eb90e6a /src/schema.c
parentb74a05cf38c2677029d14d6cc47be20689a09012 (diff)
src: add used_size and free_size to partition data
Extend database table ordenadores_particiones to add new "used_size" and "free_size" fields. FIELD TYPE | tamano | bigint | | uso | tinyint | | used_size | bigint | | free_size | bigint | "tamano" is the field storing the total size of the partition. "uso" is a field storing the integer percentage of use, it is preserved for backwards compatibility with scritps that access the database. "used_size" and "free_size" contain the used and free partition size in bytes. Old response from ogClient for /cache/delete, /cache/fetch and /image/restore: { 'cache': [ {'name': 'windows.img', 'size': 2432370213, checksum: '5d4dcc677bc19f40a647d0002f4ade90'}, {'name': 'linux.img', 'size': 243234534213, checksum: '3eb22f888f88a55ad954f55644e1192e'} ] } New response: { 'cache': { 'used_size': 4520232322423, 'free_size': 48273465287452945, 'images': [ {'name': 'windows.img', 'size': 2432370213, checksum: '5d4dcc677bc19f40a647d0002f4ade90'}, {'name': 'linux.img', 'size': 243234534213, checksum: '3eb22f888f88a55ad954f55644e1192e'} ] } } Parse the new "free_size" and "used_size" fields of each partition data in the response payload of /refresh Parse "free_size" and "used_size" fields of the cache data in the reponse payload of /image/restore, /cache/delete and /cache/fetch Replace "used_size" field of GET /client/setup with the value of the new database field "used_size"
Diffstat (limited to 'src/schema.c')
-rw-r--r--src/schema.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/schema.c b/src/schema.c
index fd1d573..f7fceae 100644
--- a/src/schema.c
+++ b/src/schema.c
@@ -434,6 +434,36 @@ static int og_dbi_schema_v10(struct og_dbi *dbi)
return 0;
}
+static int og_dbi_schema_v11(struct og_dbi *dbi)
+{
+ const char *msglog;
+ dbi_result result;
+
+ syslog(LOG_DEBUG, "Adding free_size and used_size to ordenadores_particiones\n");
+ result = dbi_conn_query(dbi->conn,
+ "ALTER TABLE `ordenadores_particiones` "
+ "ADD `used_size` BIGINT DEFAULT '0' AFTER `cache`, "
+ "ADD `free_size` BIGINT DEFAULT '0' AFTER `used_size`;");
+ if (!result) {
+ dbi_conn_error(dbi->conn, &msglog);
+ syslog(LOG_INFO, "Error when updating ordenadores_particiones table (%s:%d) %s\n",
+ __func__, __LINE__, msglog);
+ return -1;
+ }
+ dbi_result_free(result);
+
+ result = dbi_conn_query(dbi->conn, "UPDATE version SET version = 11");
+ 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);
@@ -448,6 +478,7 @@ static struct og_schema_version {
{ .version = 8, .update = og_dbi_schema_v8, },
{ .version = 9, .update = og_dbi_schema_v9, },
{ .version = 10, .update = og_dbi_schema_v10,},
+ { .version = 11, .update = og_dbi_schema_v11,},
{ 0, NULL },
};