From 1f2072c58cf6aa58c597ee2077b5a6d01b6d3cf2 Mon Sep 17 00:00:00 2001 From: kanoi Date: Sat, 26 Jul 2014 12:39:17 +1000 Subject: [PATCH] ckdb - start of v0.4 changes --- sql/ckdb.sql | 3 ++- sql/v0.3-v0.4.sql | 28 ++++++++++++++++++++++++++++ src/ckdb.c | 10 ++++++++-- 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 sql/v0.3-v0.4.sql diff --git a/sql/ckdb.sql b/sql/ckdb.sql index 42f9f5d9..50b2e654 100644 --- a/sql/ckdb.sql +++ b/sql/ckdb.sql @@ -374,6 +374,7 @@ CREATE TABLE userstats ( hashrate5m float NOT NULL, hashrate1hr float NOT NULL, hashrate24hr float NOT NULL, + summarylevel char NOT NULL, createdate timestamp with time zone NOT NULL, createby character varying(64) DEFAULT ''::character varying NOT NULL, createcode character varying(128) DEFAULT ''::character varying NOT NULL, @@ -388,4 +389,4 @@ CREATE TABLE version ( PRIMARY KEY (vlock) ); -insert into version (vlock,version) values (1,'0.3'); +insert into version (vlock,version) values (1,'0.4'); diff --git a/sql/v0.3-v0.4.sql b/sql/v0.3-v0.4.sql new file mode 100644 index 00000000..013e14fa --- /dev/null +++ b/sql/v0.3-v0.4.sql @@ -0,0 +1,28 @@ +SET SESSION AUTHORIZATION 'postgres'; + +BEGIN transaction; + +DO $$ +DECLARE ver TEXT; +BEGIN + + UPDATE version set version='0.4' where vlock=1 and version='0.3'; + + IF found THEN + RETURN; + END IF; + + SELECT version into ver from version + WHERE vlock=1; + + RAISE EXCEPTION 'Wrong DB version - expect "0.3" - found "%"', ver; + +END $$; + +ALTER TABLE ONLY userstats + ADD COLUMN summarylevel char DEFAULT ' ' NOT NULL; + +ALTER TABLE ONLY userstats + ALTER COLUMN summarylevel DROP DEFAULT; + +END transaction; diff --git a/src/ckdb.c b/src/ckdb.c index d46608cf..cce9a8a0 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -41,7 +41,7 @@ // will need to be if threading is added #define DB_VLOCK "1" -#define DB_VERSION "0.3" +#define DB_VERSION "0.4" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ @@ -936,7 +936,7 @@ typedef struct userstats { double hashrate1hr; double hashrate24hr; bool idle; // Non-db field - char summarylevel[TXT_FLAG+1]; // Initially '0' in the DB + char summarylevel[TXT_FLAG+1]; // Initially SUMMARY_NONE SIMPLEDATECONTROLFIELDS; } USERSTATS; @@ -964,6 +964,10 @@ static K_STORE *userstats_eos_store; /* on the allusers page, show any with stats in the last ... */ #define ALLUSERS_LIMIT_S 3600 +#define SUMMARY_NONE '0' +#define SUMMARY_DB '1' +#define SUMMARY_FULL '2' + /* Userstats get stored in the DB for each time band of this * amount from midnight (UTC+00) * Thus we simply put each stats value in the time band of the @@ -4418,6 +4422,8 @@ static bool userstats_add(char *poolinstance, char *elapsed, char *username, TXT_TO_DOUBLE("hashrate1hr", hashrate1hr, row->hashrate1hr); TXT_TO_DOUBLE("hashrate24hr", hashrate24hr, row->hashrate24hr); row->idle = idle; + row->summarylevel[0] = SUMMARY_NONE; + row->summarylevel[1] = '\0'; SIMPLEDATEINIT(row, now, by, code, inet); SIMPLEDATETRANSFER(row);