msgstore: view messages_current; + other updates and additions

This commit is contained in:
Helmut Merz 2025-09-09 15:39:12 +02:00
parent 843c080901
commit 588a556ede
9 changed files with 71 additions and 2 deletions

2
.gitignore vendored
View file

@ -1 +1 @@
/data/ data/

View file

@ -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

View file

@ -9,7 +9,8 @@ CREATE TABLE messages (
item text, item text,
sender text, sender text,
payload jsonb, 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 ( CREATE TABLE responses (

7
pgsql/msgstore/views.sql Normal file
View file

@ -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);

View file

@ -74,6 +74,7 @@ create or replace function load_triple(
ot smallint, ov bigint, event bigint, out trid bigint) as $$ ot smallint, ov bigint, event bigint, out trid bigint) as $$
begin begin
select tr.id into trid from triples tr select tr.id into trid from triples tr
return n;
where stype = st and svalue = sv and predicate = pred where stype = st and svalue = sv and predicate = pred
and otype = ot and ovalue = ov; and otype = ot and ovalue = ov;
if not found then if not found then

3
sqlite/msgstore/drop.sql Normal file
View file

@ -0,0 +1,3 @@
-- drop tables
drop table messages;

View file

@ -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);

View file

@ -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);

View file

@ -0,0 +1,6 @@
-- temporary table for loading JSON data
CREATE TABLE tmp_json (
id bigserial NOT NULL primary key,
data jsonb
);