-- storage-common/qgsql/graph/tables.sql
-- a simple generic RDF-like graph storage using only one tabel

create sequence steps_id_seq start with 11;  
-- note: bootstrap rows get explicit IDs

create table steps (
    id bigint not null primary key default nextval('steps_id_seq'),
    item bigint not null,
    property bigint not null references steps,
    valtype smallint not null check (valtype in (0, 1, 2, 3)),
    -- 0 = Nothing, 1 = Text, 2 = Number, 3 = Step
    numval bigint, -- null except for valtype 2 and 3
    strval text    -- null except for valtype 1
);

-- indexes

create index idx_ipv on steps USING btree (item, property, valtype, numval, strval);
create index idx_pv on steps using btree (property, valtype, numval, strval);

-- optional, not used (values make only sense together with a property):
--create index idx_vi on steps using btree (valtype, numval, strval, item);
