Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Proposed database structure

Image RemovedImage Added

Code Block
languagesql
titleCreation script
collapsetrue
BEGIN;


CREATE TABLE IF NOT EXISTS diku_mod_entities_links.authority
(
    id uuid NOT NULL,
    natural_id character varying NOT NULL DEFAULT random(),
    source_file_id uuid,
    source character varying NOT NULL,
    heading character varying NOT NULL,
    heading_type character varying NOT NULL,
    _version integer,
    subject_heading_code "char",
    PRIMARY KEY (id),
    CONSTRAINT unq_heading UNIQUE (heading, heading_type)
);

CREATE TABLE IF NOT EXISTS diku_mod_entities_links.authority_source_file
(
    id uuid NOT NULL,
    name character varying(250) NOT NULL,
    type character varying(25),
    base_url character varying(250),
    source character varying(25) NOT NULL,
    PRIMARY KEY (id)
);

CREATE TABLE IF NOT EXISTS diku_mod_entities_links.authority_source_file_code
(
    authority_source_file_id uuid NOT NULL,
    code character varying(20) NOT NULL
);

CREATE TABLE IF NOT EXISTS diku_mod_entities_links.authority_source_file_metadata
(
    id uuid NOT NULL,
    authority_source_file_id uuid NOT NULL,
    created_date timestamp without time zone,
    updated_date timestamp without time zone,
    created_by_user_id uuid,
    updated_by_user_id uuid,
    PRIMARY KEY (id)
);

CREATE TABLE IF NOT EXISTS diku_mod_entities_links.authority_metadata
(
    id uuid NOT NULL,
    authority_id uuid NOT NULL,
    created_date timestamp without time zone,
    updated_date timestamp without time zone,
    created_by_user_id uuid,
    updated_by_user_id uuid,
    PRIMARY KEY (id)
);

CREATE TABLE IF NOT EXISTS diku_mod_entities_links.authority_sft_heading
(
    authority_id uuid,
    sft_heading character varying
);

CREATE TABLE IF NOT EXISTS diku_mod_entities_links.authority_saft_heading
(
    authority_id uuid,
    saft_heading character varying
);

CREATE TABLE IF NOT EXISTS diku_mod_entities_links.authority_identifier
(
    authority_id uuid,
    identifier_type_id uuid,
    value character varying
);

CREATE TABLE IF NOT EXISTS diku_mod_entities_links.authority_note
(
    authority_id uuid,
    note_type_id uuid,
    value character varying,
    staff_only boolean
);

CREATE TABLE IF NOT EXISTS diku_mod_entities_links.authority_note_type
(
    id uuid NOT NULL,
    name character varying(250) NOT NULL,
    source character varying(25) NOT NULL,
    PRIMARY KEY (id)
);

CREATE TABLE IF NOT EXISTS diku_mod_entities_links.authority_note_type_metadata
(
    id uuid NOT NULL,
    authority_note_type_id uuid NOT NULL,
    created_date timestamp without time zone,
    updated_date timestamp without time zone,
    created_by_user_id uuid,
    updated_by_user_id uuid,
    PRIMARY KEY (id)
);

ALTER TABLE IF EXISTS diku_mod_entities_links.authority
    ADD CONSTRAINT fk_authority_source_file_id FOREIGN KEY (source_file_id)
    REFERENCES diku_mod_entities_links.authority_source_file (id) MATCH SIMPLE
    ON UPDATE NO ACTION
    ON DELETE NO ACTION
    NOT VALID;


ALTER TABLE IF EXISTS diku_mod_entities_links.authority_source_file_code
    ADD CONSTRAINT fk_authority_source_file_id FOREIGN KEY (authority_source_file_id)
    REFERENCES diku_mod_entities_links.authority_source_file (id) MATCH SIMPLE
    ON UPDATE NO ACTION
    ON DELETE NO ACTION
    NOT VALID;


ALTER TABLE IF EXISTS diku_mod_entities_links.authority_source_file_metadata
    ADD CONSTRAINT fk_authority_source_file_id FOREIGN KEY (authority_source_file_id)
    REFERENCES diku_mod_entities_links.authority_source_file (id) MATCH SIMPLE
    ON UPDATE NO ACTION
    ON DELETE NO ACTION
    NOT VALID;


ALTER TABLE IF EXISTS diku_mod_entities_links.authority_metadata
    ADD CONSTRAINT fk_authority_id FOREIGN KEY (authority_id)
    REFERENCES diku_mod_entities_links.authority (id) MATCH SIMPLE
    ON UPDATE NO ACTION
    ON DELETE NO ACTION
    NOT VALID;


ALTER TABLE IF EXISTS diku_mod_entities_links.authority_sft_heading
    ADD CONSTRAINT fk_authority_id FOREIGN KEY (authority_id)
    REFERENCES diku_mod_entities_links.authority (id) MATCH SIMPLE
    ON UPDATE NO ACTION
    ON DELETE NO ACTION
    NOT VALID;


ALTER TABLE IF EXISTS diku_mod_entities_links.authority_saft_heading
    ADD CONSTRAINT fk_authority_id FOREIGN KEY (authority_id)
    REFERENCES diku_mod_entities_links.authority (id) MATCH SIMPLE
    ON UPDATE NO ACTION
    ON DELETE NO ACTION
    NOT VALID;


ALTER TABLE IF EXISTS diku_mod_entities_links.authority_identifier
    ADD CONSTRAINT fk_authority_id FOREIGN KEY (authority_id)
    REFERENCES diku_mod_entities_links.authority (id) MATCH SIMPLE
    ON UPDATE NO ACTION
    ON DELETE NO ACTION
    NOT VALID;


ALTER TABLE IF EXISTS diku_mod_entities_links.authority_note
    ADD CONSTRAINT fk_authority_id FOREIGN KEY (authority_id)
    REFERENCES diku_mod_entities_links.authority (id) MATCH SIMPLE
    ON UPDATE NO ACTION
    ON DELETE NO ACTION
    NOT VALID;


ALTER TABLE IF EXISTS diku_mod_entities_links.authority_note
    ADD CONSTRAINT fk_authority_note_type_id FOREIGN KEY (note_type_id)
    REFERENCES diku_mod_entities_links.authority_note_type (id) MATCH SIMPLE
    ON UPDATE NO ACTION
    ON DELETE NO ACTION
    NOT VALID;


ALTER TABLE IF EXISTS diku_mod_entities_links.authority_note_type_metadata
    ADD CONSTRAINT fk_authority_note_type_id FOREIGN KEY (authority_note_type_id)
    REFERENCES diku_mod_entities_links.authority_note_type (id) MATCH SIMPLE
    ON UPDATE NO ACTION
    ON DELETE NO ACTION
    NOT VALID;

END;

...