From af16128a2480035bc94809bfe09ade5f5845ad6d Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Mon, 15 Sep 2025 12:40:21 +0200 Subject: [PATCH] add scopes subdirectory for (cl-, go-, py-) -scopes storage (tracking) formats --- pgsql/scopes/compat_msgstore.sql | 6 ++++++ pgsql/scopes/drop.sql | 4 ++++ pgsql/scopes/tables.sql | 15 +++++++++++++++ pgsql/scopes/views.sql | 9 +++++++++ 4 files changed, 34 insertions(+) create mode 100644 pgsql/scopes/compat_msgstore.sql create mode 100644 pgsql/scopes/drop.sql create mode 100644 pgsql/scopes/tables.sql create mode 100644 pgsql/scopes/views.sql diff --git a/pgsql/scopes/compat_msgstore.sql b/pgsql/scopes/compat_msgstore.sql new file mode 100644 index 0000000..8d85342 --- /dev/null +++ b/pgsql/scopes/compat_msgstore.sql @@ -0,0 +1,6 @@ +-- scopes: compat_msgstore +-- rename columns from go-storage/emsgstore:messages to scopes:messages + +alter table messages rename id to trackid; +alter table messages rename tstamp to timestamp; +alter table messages rename payload to data; diff --git a/pgsql/scopes/drop.sql b/pgsql/scopes/drop.sql new file mode 100644 index 0000000..5f8c887 --- /dev/null +++ b/pgsql/scopes/drop.sql @@ -0,0 +1,4 @@ +-- drop tables + +drop table messages; + diff --git a/pgsql/scopes/tables.sql b/pgsql/scopes/tables.sql new file mode 100644 index 0000000..afc3610 --- /dev/null +++ b/pgsql/scopes/tables.sql @@ -0,0 +1,15 @@ +-- scopes: create tables (and other table-related stuff) + +CREATE TABLE messages ( + trackid bigserial NOT NULL primary key, + domain text, + action text, + class text, + item text, + timestamp timestamptz default current_timestamp, + data jsonb +); + +CREATE INDEX idx_msg ON messages USING btree (domain, action, class, item); +CREATE INDEX idx_msg_item ON messages USING btree (domain, class, item); + diff --git a/pgsql/scopes/views.sql b/pgsql/scopes/views.sql new file mode 100644 index 0000000..1cb9362 --- /dev/null +++ b/pgsql/scopes/views.sql @@ -0,0 +1,9 @@ +-- scopes: create views + +create or replace view messages_current as + select trackid, domain, action, class, item, timestamp, data + from messages m1 + where trackid = (select max(trackid) from messages m2 + where m2.domain = m1.domain and m2.action = m1.action + and m2.class = m1.class and m2.item = m1.item); +