<commit_before>------------------------------
-- Schema 'relation_directory'
------------------------------

CREATE SCHEMA relation_directory;

COMMENT ON SCHEMA relation_directory IS
'Stores directional relations between entities.';

ALTER SCHEMA relation_directory OWNER TO minerva_admin;

GRANT ALL ON SCHEMA relation_directory TO minerva_writer;
GRANT USAGE ON SCHEMA relation_directory TO minerva;

-- Table 'relation_directory.group'

CREATE TABLE relation_directory."group" (
    id integer NOT NULL,
    name character varying NOT NULL
);

ALTER TABLE relation_directory."group" OWNER TO minerva_admin;

ALTER TABLE ONLY relation_directory."group"
    ADD CONSTRAINT group_pkey PRIMARY KEY (id);

GRANT SELECT ON TABLE relation_directory."group" TO minerva;
GRANT INSERT,DELETE,UPDATE ON TABLE relation_directory."group" TO minerva_writer;

CREATE SEQUENCE relation_directory.group_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

ALTER TABLE relation_directory.group_id_seq OWNER TO minerva_admin;

ALTER SEQUENCE relation_directory.group_id_seq OWNED BY relation_directory."group".id;

ALTER TABLE relation_directory."group"
    ALTER COLUMN id
    SET DEFAULT nextval('relation_directory.group_id_seq'::regclass);

GRANT SELECT ON SEQUENCE relation_directory.group_id_seq TO minerva;
GRANT UPDATE ON SEQUENCE relation_directory.group_id_seq TO minerva_writer;

CREATE UNIQUE INDEX ix_group_name ON relation_directory."group" (name);

-- Table 'relation_directory.type'

CREATE TYPE relation_directory.type_cardinality_enum AS ENUM (
    'one-to-one',
    'one-to-many',
    'many-to-one'
);

CREATE TABLE relation_directory."type" (
    id integer NOT NULL,
    name character varying NOT NULL,
    cardinality relation_directory.type_cardinality_enum DEFAULT NULL,
    group_id integer DEFAULT NULL
);

ALTER TABLE relation_directory."type" OWNER TO minerva_admin;

ALTER TABLE ONLY relation_directory."type"
    ADD CONSTRAINT type_pkey PRIMARY KEY (id);

GRANT SELECT ON TABLE relation_directory."type" TO minerva;
GRANT INSERT,DELETE,UPDATE ON TABLE relation_directory."type" TO minerva_writer;

CREATE SEQUENCE relation_directory.type_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

ALTER TABLE relation_directory.type_id_seq OWNER TO minerva_admin;

ALTER SEQUENCE relation_directory.type_id_seq OWNED BY relation_directory."type".id;

ALTER TABLE relation_directory."type"
    ALTER COLUMN id
    SET DEFAULT nextval('relation_directory.type_id_seq'::regclass);

ALTER TABLE ONLY relation_directory."type"
    ADD CONSTRAINT group_id_fkey
    FOREIGN KEY (group_id) REFERENCES relation_directory."group"(id)
    ON DELETE CASCADE;

GRANT SELECT ON SEQUENCE relation_directory.type_id_seq TO minerva;
GRANT UPDATE ON SEQUENCE relation_directory.type_id_seq TO minerva_writer;

CREATE UNIQUE INDEX ix_type_name ON relation_directory."type" (name);

------------------------
-- Schema 'relation_def'
------------------------

CREATE SCHEMA relation_def;
ALTER SCHEMA relation_def OWNER TO minerva_admin;

GRANT ALL ON SCHEMA relation_def TO minerva_admin;
GRANT ALL ON SCHEMA relation_def TO minerva_writer;
GRANT USAGE ON SCHEMA relation_def TO minerva;


------------------------------
-- Schema 'relation'
------------------------------

CREATE SCHEMA relation;

COMMENT ON SCHEMA relation IS
'Stores the actual relations between entities in dynamically created tables.';

ALTER SCHEMA relation OWNER TO minerva_admin;

GRANT ALL ON SCHEMA relation TO minerva_writer;
GRANT USAGE ON SCHEMA relation TO minerva;


-- Table 'relation.all'

CREATE TABLE relation."all" (
    source_id integer NOT NULL,
    target_id integer NOT NULL,
    type_id integer NOT NULL
);

ALTER TABLE relation."all" OWNER TO minerva_admin;

ALTER TABLE ONLY relation."all"
    ADD PRIMARY KEY (source_id, target_id);

ALTER TABLE ONLY relation."all"
    ADD CONSTRAINT source_id_fkey
    FOREIGN KEY (source_id) REFERENCES directory.entity(id)
    ON DELETE CASCADE;

ALTER TABLE ONLY relation."all"
    ADD CONSTRAINT target_id_fkey
    FOREIGN KEY (target_id) REFERENCES directory.entity(id)
    ON DELETE CASCADE;

GRANT SELECT ON TABLE relation."all" TO minerva;
GRANT INSERT,DELETE,UPDATE ON TABLE relation."all" TO minerva_writer;

ALTER TABLE ONLY relation."all"
    ADD CONSTRAINT type_id_fkey
    FOREIGN KEY (type_id) REFERENCES relation_directory."type"(id)
    ON DELETE CASCADE;

CREATE INDEX ON relation."all" USING btree (target_id);
CREATE INDEX ON relation."all" USING btree (type_id);

-- Table 'relation.all_materialized'

CREATE TABLE relation.all_materialized (
    source_id integer NOT NULL,
    target_id integer NOT NULL,
    type_id integer NOT NULL
);

ALTER TABLE relation."all_materialized" OWNER TO minerva_admin;

ALTER TABLE relation."all_materialized"
    ADD PRIMARY KEY (source_id, target_id, type_id);

GRANT SELECT ON TABLE relation."all_materialized" TO minerva;
GRANT INSERT,DELETE,UPDATE ON TABLE relation."all_materialized" TO minerva_writer;

CREATE INDEX ON relation."all_materialized" USING btree (target_id);
CREATE INDEX ON relation."all_materialized" USING btree (type_id);
<commit_msg>Remove relation 'group' concept<commit_after>------------------------------
-- Schema 'relation_directory'
------------------------------

CREATE SCHEMA relation_directory;

COMMENT ON SCHEMA relation_directory IS
'Stores directional relations between entities.';

ALTER SCHEMA relation_directory OWNER TO minerva_admin;

GRANT ALL ON SCHEMA relation_directory TO minerva_writer;
GRANT USAGE ON SCHEMA relation_directory TO minerva;

-- Table 'relation_directory.type'

CREATE TYPE relation_directory.type_cardinality_enum AS ENUM (
    'one-to-one',
    'one-to-many',
    'many-to-one'
);

CREATE TABLE relation_directory."type" (
    id integer NOT NULL,
    name character varying NOT NULL,
    cardinality relation_directory.type_cardinality_enum DEFAULT NULL
);

ALTER TABLE relation_directory."type" OWNER TO minerva_admin;

ALTER TABLE ONLY relation_directory."type"
    ADD CONSTRAINT type_pkey PRIMARY KEY (id);

GRANT SELECT ON TABLE relation_directory."type" TO minerva;
GRANT INSERT,DELETE,UPDATE ON TABLE relation_directory."type" TO minerva_writer;

CREATE SEQUENCE relation_directory.type_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

ALTER TABLE relation_directory.type_id_seq OWNER TO minerva_admin;

ALTER SEQUENCE relation_directory.type_id_seq OWNED BY relation_directory."type".id;

ALTER TABLE relation_directory."type"
    ALTER COLUMN id
    SET DEFAULT nextval('relation_directory.type_id_seq'::regclass);

ALTER TABLE ONLY relation_directory."type"
    ADD CONSTRAINT group_id_fkey
    FOREIGN KEY (group_id) REFERENCES relation_directory."group"(id)
    ON DELETE CASCADE;

GRANT SELECT ON SEQUENCE relation_directory.type_id_seq TO minerva;
GRANT UPDATE ON SEQUENCE relation_directory.type_id_seq TO minerva_writer;

CREATE UNIQUE INDEX ix_type_name ON relation_directory."type" (name);

------------------------
-- Schema 'relation_def'
------------------------

CREATE SCHEMA relation_def;
ALTER SCHEMA relation_def OWNER TO minerva_admin;

GRANT ALL ON SCHEMA relation_def TO minerva_admin;
GRANT ALL ON SCHEMA relation_def TO minerva_writer;
GRANT USAGE ON SCHEMA relation_def TO minerva;


------------------------------
-- Schema 'relation'
------------------------------

CREATE SCHEMA relation;

COMMENT ON SCHEMA relation IS
'Stores the actual relations between entities in dynamically created tables.';

ALTER SCHEMA relation OWNER TO minerva_admin;

GRANT ALL ON SCHEMA relation TO minerva_writer;
GRANT USAGE ON SCHEMA relation TO minerva;


-- Table 'relation.all'

CREATE TABLE relation."all" (
    source_id integer NOT NULL,
    target_id integer NOT NULL,
    type_id integer NOT NULL
);

ALTER TABLE relation."all" OWNER TO minerva_admin;

ALTER TABLE ONLY relation."all"
    ADD PRIMARY KEY (source_id, target_id);

ALTER TABLE ONLY relation."all"
    ADD CONSTRAINT source_id_fkey
    FOREIGN KEY (source_id) REFERENCES directory.entity(id)
    ON DELETE CASCADE;

ALTER TABLE ONLY relation."all"
    ADD CONSTRAINT target_id_fkey
    FOREIGN KEY (target_id) REFERENCES directory.entity(id)
    ON DELETE CASCADE;

GRANT SELECT ON TABLE relation."all" TO minerva;
GRANT INSERT,DELETE,UPDATE ON TABLE relation."all" TO minerva_writer;

ALTER TABLE ONLY relation."all"
    ADD CONSTRAINT type_id_fkey
    FOREIGN KEY (type_id) REFERENCES relation_directory."type"(id)
    ON DELETE CASCADE;

CREATE INDEX ON relation."all" USING btree (target_id);
CREATE INDEX ON relation."all" USING btree (type_id);

-- Table 'relation.all_materialized'

CREATE TABLE relation.all_materialized (
    source_id integer NOT NULL,
    target_id integer NOT NULL,
    type_id integer NOT NULL
);

ALTER TABLE relation."all_materialized" OWNER TO minerva_admin;

ALTER TABLE relation."all_materialized"
    ADD PRIMARY KEY (source_id, target_id, type_id);

GRANT SELECT ON TABLE relation."all_materialized" TO minerva;
GRANT INSERT,DELETE,UPDATE ON TABLE relation."all_materialized" TO minerva_writer;

CREATE INDEX ON relation."all_materialized" USING btree (target_id);
CREATE INDEX ON relation."all_materialized" USING btree (type_id);

{'fraction_non_alphanumeric': 0.09680188881734278, 'fraction_numerical': 0.0009658725048293626, 'mean_word_length': 4.061922868006518, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4926067', 'n_tokens_mistral': 3026, 'n_tokens_neox': 2853, 'n_words': 910}