dnet-applications/libs/dnet-is-common/src/main/resources/sql/schema.sql

95 lines
2.5 KiB
SQL

-- Vocabularies
CREATE TABLE vocabularies (
id text PRIMARY KEY,
name text NOT NULL,
description text
);
CREATE TABLE vocabulary_terms (
vocabulary text NOT NULL REFERENCES vocabularies(id) ON UPDATE CASCADE ON DELETE CASCADE,
code text NOT NULL,
name text NOT NULL,
encoding text DEFAULT 'OPENAIRE',
synonyms jsonb,
PRIMARY KEY (vocabulary, code)
);
CREATE INDEX ON vocabulary_terms (vocabulary);
-- Contexts
CREATE TABLE contexts (
id text PRIMARY KEY,
label text NOT NULL,
type text NOT NULL,
params jsonb
);
CREATE TABLE context_categories (
id text NOT NULL PRIMARY KEY,
parent text NOT NULL REFERENCES contexts(id) ON UPDATE CASCADE ON DELETE CASCADE,
label text NOT NULL,
claim boolean NOT NULL,
params jsonb
);
CREATE TABLE context_cat_concepts_lvl_0 (
id text NOT NULL PRIMARY KEY,
parent text NOT NULL REFERENCES context_categories(id) ON UPDATE CASCADE ON DELETE CASCADE,
label text NOT NULL,
claim boolean NOT NULL,
params jsonb
);
CREATE TABLE context_cat_concepts_lvl_1 (
id text NOT NULL PRIMARY KEY,
parent text NOT NULL REFERENCES context_cat_concepts_lvl_0(id) ON UPDATE CASCADE ON DELETE CASCADE,
label text NOT NULL,
claim boolean NOT NULL,
params jsonb
);
CREATE TABLE context_cat_concepts_lvl_2 (
id text NOT NULL PRIMARY KEY,
parent text NOT NULL REFERENCES context_cat_concepts_lvl_1(id) ON UPDATE CASCADE ON DELETE CASCADE,
label text NOT NULL,
claim boolean NOT NULL,
params jsonb
);
CREATE INDEX ON context_categories (parent);
CREATE INDEX ON context_cat_concepts_lvl_0 (parent);
CREATE INDEX ON context_cat_concepts_lvl_1 (parent);
CREATE INDEX ON context_cat_concepts_lvl_2 (parent);
-- WF History
CREATE TABLE wf_history (
process_id text PRIMARY KEY,
name text NOT NULL,
family text NOT NULL,
status text NOT NULL,
start_date timestamp NOT NULL,
end_date timestamp NOT NULL,
ds_id text,
ds_name text,
ds_api text,
details jsonb
);
-- Other Resources
CREATE TABLE resource_types(type text PRIMARY KEY);
INSERT INTO resource_types(type) VALUES ('transformation_rule'), ('cleaning_rule');
CREATE TABLE resources (
id text PRIMARY KEY,
name text NOT NULL,
description text,
content text NOT NULL,
type text NOT NULL REFERENCES resource_types(type),
creation_date timestamp NOT NULL DEFAULT now(),
modification_date timestamp NOT NULL DEFAULT now()
);