
-- create tables

CREATE TABLE messages (
    id bigserial NOT NULL primary key,
    domain text,
    action text,
    class text,
    item text,
    sender text,
    payload jsonb,
    state smallint default 0,
    tstamp timestamptz default current_timestamp
);

-- indexes

CREATE INDEX idx_msg ON messages USING btree (domain, action, class, item);
CREATE INDEX idx_msg_action ON messages USING btree (action);
CREATE INDEX idx_msg_state ON messages USING btree (state);
CREATE INDEX idx_msg_tstamp ON messages USING btree (tstamp);
