From 588a556ede112546f2180c1d742864dbea356797 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Tue, 9 Sep 2025 15:39:12 +0200 Subject: [PATCH] msgstore: view messages_current; + other updates and additions --- .gitignore | 2 +- pgsql/msgstore/select_projects_30_40.sql | 9 +++++++ pgsql/msgstore/tcreate.sql | 3 ++- pgsql/msgstore/views.sql | 7 ++++++ pgsql/z-graph/fload.sql | 1 + sqlite/msgstore/drop.sql | 3 +++ sqlite/msgstore/tables.sql | 10 ++++++++ sqlite/msgstore/tcreate.sql | 32 ++++++++++++++++++++++++ sqlite/msgstore/ttmp-json.sql | 6 +++++ 9 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 pgsql/msgstore/select_projects_30_40.sql create mode 100644 pgsql/msgstore/views.sql create mode 100644 sqlite/msgstore/drop.sql create mode 100644 sqlite/msgstore/tables.sql create mode 100644 sqlite/msgstore/tcreate.sql create mode 100644 sqlite/msgstore/ttmp-json.sql diff --git a/.gitignore b/.gitignore index 5fac628..8fce603 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -/data/ \ No newline at end of file +data/ diff --git a/pgsql/msgstore/select_projects_30_40.sql b/pgsql/msgstore/select_projects_30_40.sql new file mode 100644 index 0000000..1f71e5c --- /dev/null +++ b/pgsql/msgstore/select_projects_30_40.sql @@ -0,0 +1,9 @@ +select payload->>'community' Gemeinde, item Projekt, + payload->>'projectState' Status, payload->>'active' Aktiv, + to_char(tstamp, 'DD.MM.YYYY') Datum +from messages_current +where domain='kiss' and class='project' + and (payload->>'projectState')::integer <> 20 + --and payload->>'active' is not null + order by payload->>'community', item +-- \g projects_10_30_40.csv diff --git a/pgsql/msgstore/tcreate.sql b/pgsql/msgstore/tcreate.sql index 6600c80..797025e 100644 --- a/pgsql/msgstore/tcreate.sql +++ b/pgsql/msgstore/tcreate.sql @@ -9,7 +9,8 @@ CREATE TABLE messages ( item text, sender text, payload jsonb, - tstamp timestamptz default current_timestamp + tstamp timestamptz default current_timestamp, + tsread timestamptz -- to be updated upon reading/processing of message ); CREATE TABLE responses ( diff --git a/pgsql/msgstore/views.sql b/pgsql/msgstore/views.sql new file mode 100644 index 0000000..b147f2b --- /dev/null +++ b/pgsql/msgstore/views.sql @@ -0,0 +1,7 @@ + +create or replace view messages_current as + select id, domain, action, class, item, tstamp, payload + from messages m1 + where id = (select max(id) from messages m2 + where m2.domain = m1.domain and m2.action = m1.action + and m2.class = m1.class and m2.item = m1.item); diff --git a/pgsql/z-graph/fload.sql b/pgsql/z-graph/fload.sql index d031b81..7152180 100644 --- a/pgsql/z-graph/fload.sql +++ b/pgsql/z-graph/fload.sql @@ -74,6 +74,7 @@ create or replace function load_triple( ot smallint, ov bigint, event bigint, out trid bigint) as $$ begin select tr.id into trid from triples tr + return n; where stype = st and svalue = sv and predicate = pred and otype = ot and ovalue = ov; if not found then diff --git a/sqlite/msgstore/drop.sql b/sqlite/msgstore/drop.sql new file mode 100644 index 0000000..4fecb94 --- /dev/null +++ b/sqlite/msgstore/drop.sql @@ -0,0 +1,3 @@ +-- drop tables + +drop table messages; diff --git a/sqlite/msgstore/tables.sql b/sqlite/msgstore/tables.sql new file mode 100644 index 0000000..b02a5bd --- /dev/null +++ b/sqlite/msgstore/tables.sql @@ -0,0 +1,10 @@ +create table messages ( + id integer not null primary key, + domain text, + action text, + class text, + item text, + sender text, + payload json, + tstamp timestamp default current_timestamp); + diff --git a/sqlite/msgstore/tcreate.sql b/sqlite/msgstore/tcreate.sql new file mode 100644 index 0000000..797025e --- /dev/null +++ b/sqlite/msgstore/tcreate.sql @@ -0,0 +1,32 @@ + +-- create tables + +CREATE TABLE messages ( + id bigserial NOT NULL primary key, + domain text, + action text, + class text, + item text, + sender text, + payload jsonb, + tstamp timestamptz default current_timestamp, + tsread timestamptz -- to be updated upon reading/processing of message +); + +CREATE TABLE responses ( + id bigserial NOT NULL primary key, + domain text, + action text, + class text, + item text, + payload jsonb, + tstamp timestamptz default current_timestamp +); + +-- indexes + +CREATE INDEX idx_msg ON messages USING btree (domain, action, class, item); +CREATE INDEX idx_msg_item ON messages USING btree (domain, class, item); +--CREATE INDEX idx_msg_action ON messages USING btree (action); -- obsolete + +CREATE INDEX idx_resp_item ON responses USING btree (domain, class, item); diff --git a/sqlite/msgstore/ttmp-json.sql b/sqlite/msgstore/ttmp-json.sql new file mode 100644 index 0000000..eecc6c5 --- /dev/null +++ b/sqlite/msgstore/ttmp-json.sql @@ -0,0 +1,6 @@ +-- temporary table for loading JSON data + +CREATE TABLE tmp_json ( + id bigserial NOT NULL primary key, + data jsonb +);