msgstore: view messages_current; + other updates and additions
This commit is contained in:
parent
843c080901
commit
588a556ede
9 changed files with 71 additions and 2 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1 +1 @@
|
||||||
/data/
|
data/
|
||||||
|
|
|
||||||
9
pgsql/msgstore/select_projects_30_40.sql
Normal file
9
pgsql/msgstore/select_projects_30_40.sql
Normal 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
|
||||||
|
|
@ -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
7
pgsql/msgstore/views.sql
Normal 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);
|
||||||
|
|
@ -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
3
sqlite/msgstore/drop.sql
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
-- drop tables
|
||||||
|
|
||||||
|
drop table messages;
|
||||||
10
sqlite/msgstore/tables.sql
Normal file
10
sqlite/msgstore/tables.sql
Normal 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);
|
||||||
|
|
||||||
32
sqlite/msgstore/tcreate.sql
Normal file
32
sqlite/msgstore/tcreate.sql
Normal 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);
|
||||||
6
sqlite/msgstore/ttmp-json.sql
Normal file
6
sqlite/msgstore/ttmp-json.sql
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
-- temporary table for loading JSON data
|
||||||
|
|
||||||
|
CREATE TABLE tmp_json (
|
||||||
|
id bigserial NOT NULL primary key,
|
||||||
|
data jsonb
|
||||||
|
);
|
||||||
Loading…
Add table
Reference in a new issue