CREATE TABLE meta
(
    id    INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    key   VARCHAR NOT NULL,
    value VARCHAR NOT NULL,
    UNIQUE(key)
);

INSERT INTO meta (key, value)
VALUES ('VERSION', '0');

CREATE TABLE data
(
    identity          BLOB PRIMARY KEY NOT NULL,
    entity            BLOB             NOT NULL,
    entity_searchable VARCHAR,
    attribute         VARCHAR          NOT NULL,
    value_str         VARCHAR,
    value_num         NUMERIC,
    immutable         BOOLEAN          NOT NULL,
    provenance        VARCHAR          NOT NULL,
    timestamp         DATETIME         NOT NULL
);

CREATE INDEX data_entity ON data (entity);
CREATE INDEX data_entity_searchable ON data (entity_searchable);
CREATE INDEX data_attribute ON data (attribute);
CREATE INDEX data_value_str ON data (value_str);
CREATE INDEX data_value_num ON data (value_num);
