BEGIN; CREATE TABLE IF NOT EXISTS diku_mod_entities_links.authority
(
id uuid not null
primary key,
natural_id character varying default random() not null,
source_file_id uuid
constraint fk_authority_source_file_id
references diku_mod_entities_links.authority_source_file,
source character varying not null,
heading character varying not null,
heading_type character varying not null,
_version integer,
subject_heading_code "char",
sft_headings jsonb,
saft_headings jsonb,
identifiers jsonb,
notes jsonb,
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_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_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; |