120 lines
3.5 KiB
SQL
120 lines
3.5 KiB
SQL
-- tables
|
|
|
|
CREATE TABLE namespaces (
|
|
id serial NOT NULL primary key,
|
|
iri text NOT NULL,
|
|
prefix text
|
|
);
|
|
|
|
CREATE TABLE datatypes (
|
|
id smallserial NOT NULL primary key,
|
|
dtname text NOT NULL,
|
|
tablename text
|
|
);
|
|
|
|
CREATE TABLE nodes (
|
|
id bigserial NOT NULL primary key,
|
|
namespace bigint,
|
|
name text
|
|
);
|
|
|
|
CREATE TABLE events (
|
|
id bigserial NOT NULL primary key,
|
|
tstamp timestamptz default current_timestamp
|
|
);
|
|
|
|
CREATE TABLE triples (
|
|
id bigserial NOT NULL primary key,
|
|
stype smallint NOT NULL,
|
|
svalue bigint NOT NULL,
|
|
predicate bigint NOT NULL,
|
|
otype smallint NOT NULL,
|
|
ovalue bigint,
|
|
creation bigint NOT NULL,
|
|
deletion bigint
|
|
);
|
|
|
|
CREATE TABLE texts (
|
|
id bigserial NOT NULL primary key,
|
|
language bigint,
|
|
text text NOT NULL
|
|
);
|
|
|
|
ALTER TABLE nodes OWNER TO cco;
|
|
ALTER TABLE datatypes OWNER TO cco;
|
|
ALTER TABLE namespaces OWNER TO cco;
|
|
ALTER TABLE triples OWNER TO cco;
|
|
ALTER TABLE events OWNER TO cco;
|
|
ALTER TABLE texts OWNER TO cco;
|
|
|
|
-- data
|
|
|
|
INSERT INTO events default values;
|
|
|
|
INSERT INTO namespaces (iri, prefix) VALUES
|
|
('http://cyberconcepts.org/cco-common#', 'cco'), -- 1
|
|
('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'rdf'), -- 2
|
|
('http://www.w3.org/2000/01/rdf-schema#', 'rdfs'); -- 3
|
|
|
|
INSERT INTO datatypes (dtname, tablename) VALUES
|
|
('namespace', 'namespaces'), -- 1
|
|
('node', 'nodes'), -- 2
|
|
('datatype', 'datatypes'), -- 3
|
|
('event', 'events'), -- 4
|
|
('triple', 'triples'), -- 5
|
|
('text', 'texts'); -- 6
|
|
INSERT INTO datatypes (dtname) VALUES
|
|
('int'), ('decimal'), ('timestamp'); -- 7, 8, 9
|
|
|
|
INSERT INTO nodes (namespace, name) VALUES
|
|
(2, 'type'), -- 1
|
|
(2, 'Property'), -- 2
|
|
(3, 'Class'); -- 3
|
|
|
|
-- basic triples: type assignments for
|
|
-- type -> Property; Property, Class -> Class
|
|
|
|
INSERT INTO triples (stype, svalue, predicate, otype, ovalue, creation) VALUES
|
|
(2, 1, 1, 2, 2, 1),
|
|
(2, 2, 1, 2, 3, 1),
|
|
(2, 3, 1, 2, 3, 1);
|
|
|
|
-- indexes
|
|
|
|
CREATE INDEX idx_iri ON namespaces USING btree (iri);
|
|
CREATE INDEX idx_prefix ON namespaces USING btree (prefix);
|
|
|
|
CREATE INDEX idx_dtname ON datatypes USING btree (dtname);
|
|
|
|
CREATE INDEX idx_node_name ON nodes USING btree (namespace, name);
|
|
|
|
CREATE INDEX fki_stype ON triples USING btree (stype);
|
|
CREATE INDEX fki_otype ON triples USING btree (otype);
|
|
CREATE INDEX fki_creation ON triples USING btree (creation);
|
|
CREATE INDEX fki_deletion ON triples USING btree (deletion);
|
|
CREATE INDEX idx_spo ON triples USING btree
|
|
(stype, svalue, predicate, otype, ovalue);
|
|
CREATE INDEX idx_po ON triples USING btree (predicate, otype, ovalue);
|
|
CREATE INDEX idx_os ON triples USING btree (otype, ovalue, stype, svalue);
|
|
|
|
CREATE INDEX fki_language ON texts USING btree (language);
|
|
|
|
-- foreign key constraints
|
|
|
|
ALTER TABLE ONLY nodes
|
|
ADD CONSTRAINT namespace FOREIGN KEY (namespace) REFERENCES namespaces(id);
|
|
|
|
ALTER TABLE ONLY triples
|
|
ADD CONSTRAINT stype FOREIGN KEY (stype) REFERENCES datatypes(id);
|
|
ALTER TABLE ONLY triples
|
|
ADD CONSTRAINT predicate FOREIGN KEY (predicate) REFERENCES nodes(id);
|
|
ALTER TABLE ONLY triples
|
|
ADD CONSTRAINT otype FOREIGN KEY (otype) REFERENCES datatypes(id);
|
|
ALTER TABLE ONLY triples
|
|
ADD CONSTRAINT creation FOREIGN KEY (creation) REFERENCES events(id);
|
|
ALTER TABLE ONLY triples
|
|
ADD CONSTRAINT deletion FOREIGN KEY (deletion) REFERENCES events(id);
|
|
|
|
ALTER TABLE ONLY texts
|
|
ADD CONSTRAINT language FOREIGN KEY (language) REFERENCES nodes(id);
|
|
|