From: Mike Rylander Date: Thu, 19 Feb 2015 13:54:20 +0000 (-0500) Subject: display field / delay creation of FKEY and function until the referenced table exists X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=0cd1ba472561c763026abe0e429cecb0b8c45557;p=working%2FEvergreen.git display field / delay creation of FKEY and function until the referenced table exists Signed-off-by: Mike Rylander --- diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index f8094cd7f8..0fa1b8db78 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -169,16 +169,6 @@ INSERT INTO config.biblio_fingerprint (name, xpath, format, first_word) TRUE ); -CREATE OR REPLACE FUNCTION - config.metabib_representative_field_is_valid(INTEGER, TEXT) RETURNS BOOLEAN AS $$ - SELECT EXISTS (SELECT 1 FROM config.metabib_field WHERE id = $1 AND field_class = $2); -$$ LANGUAGE SQL STRICT IMMUTABLE; - -COMMENT ON FUNCTION config.metabib_representative_field_is_valid(INTEGER, TEXT) IS $$ -Ensure the field_class value on the selected representative field matches -the class name. -$$; - CREATE TABLE config.metabib_class ( name TEXT PRIMARY KEY, label TEXT NOT NULL UNIQUE, @@ -189,7 +179,7 @@ CREATE TABLE config.metabib_class ( b_weight NUMERIC DEFAULT 0.4 NOT NULL, c_weight NUMERIC DEFAULT 0.2 NOT NULL, d_weight NUMERIC DEFAULT 0.1 NOT NULL - representative_field INTEGER REFERENCES config.metabib_field(id), + representative_field INTEGER, CONSTRAINT rep_field_unique UNIQUE(representative_field), CONSTRAINT rep_field_is_valid CHECK ( representative_field IS NULL OR @@ -228,6 +218,17 @@ $$; CREATE UNIQUE INDEX config_metabib_field_class_name_idx ON config.metabib_field (field_class, name); +CREATE OR REPLACE FUNCTION + config.metabib_representative_field_is_valid(INTEGER, TEXT) RETURNS BOOLEAN AS $$ + SELECT EXISTS (SELECT 1 FROM config.metabib_field WHERE id = $1 AND field_class = $2); +$$ LANGUAGE SQL STRICT IMMUTABLE; + +COMMENT ON FUNCTION config.metabib_representative_field_is_valid(INTEGER, TEXT) IS $$ +Ensure the field_class value on the selected representative field matches +the class name. +$$; + + CREATE TABLE config.ts_config_list ( id TEXT PRIMARY KEY, name TEXT NOT NULL diff --git a/Open-ILS/src/sql/Pg/800.fkeys.sql b/Open-ILS/src/sql/Pg/800.fkeys.sql index ee9886d8f4..d092c8060c 100644 --- a/Open-ILS/src/sql/Pg/800.fkeys.sql +++ b/Open-ILS/src/sql/Pg/800.fkeys.sql @@ -26,6 +26,9 @@ CREATE RULE protect_bib_rec_delete AS WHERE OLD.id = biblio.record_entry.id ); +ALTER TABLE config.metabib_class ADD CONSTRAINT config_metabib_class_representative_field_pkey FOREIGN KEY (representative_field) + REFERENCES config.metabib_field (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED; + ALTER TABLE actor.usr ADD CONSTRAINT actor_usr_mailing_address_fkey FOREIGN KEY (mailing_address) REFERENCES actor.usr_address (id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE actor.usr ADD CONSTRAINT actor_usr_billing_address_fkey FOREIGN KEY (billing_address) REFERENCES actor.usr_address (id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE actor.usr ADD CONSTRAINT actor_usr_home_ou_fkey FOREIGN KEY (home_ou) REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED;