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