Small changes to upgrade script
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 11 Jul 2011 16:25:43 +0000 (12:25 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 11 Jul 2011 16:25:43 +0000 (12:25 -0400)
One DB rule already exists in master, so we want 'create or replace.'

In another case, replacing an existing view complains about renaming
columns unless you put the new column definitions in a different order.

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.authority-control-sets.sql

index 908a371..9703301 100644 (file)
@@ -54,7 +54,7 @@ ALTER TABLE authority.record_entry ADD COLUMN control_set INT REFERENCES authori
 ALTER TABLE authority.rec_descriptor DROP COLUMN char_encoding, ADD COLUMN encoding_level TEXT, ADD COLUMN thesaurus TEXT;
 
 CREATE INDEX authority_full_rec_value_index ON authority.full_rec (value);
-CREATE RULE protect_authority_rec_delete AS ON DELETE TO authority.record_entry DO INSTEAD (UPDATE authority.record_entry SET deleted = TRUE WHERE OLD.id = authority.record_entry.id; DELETE FROM authority.full_rec WHERE record = OLD.id);
+CREATE OR REPLACE RULE protect_authority_rec_delete AS ON DELETE TO authority.record_entry DO INSTEAD (UPDATE authority.record_entry SET deleted = TRUE WHERE OLD.id = authority.record_entry.id; DELETE FROM authority.full_rec WHERE record = OLD.id);
  
 CREATE OR REPLACE FUNCTION authority.normalize_heading( marcxml TEXT, no_thesaurus BOOL ) RETURNS TEXT AS $func$
 DECLARE
@@ -119,14 +119,14 @@ CREATE OR REPLACE VIEW authority.tracing_links AS
             main.id AS main_id,
             main.tag AS main_tag,
             oils_xpath_string('//*[@tag="'||main.tag||'"]/*[local-name()="subfield"]', are.marc) AS main_value,
-            authority.normalize_heading(are.marc) AS normalized_main_value,
             substr(link.value,1,1) AS relationship,
             substr(link.value,2,1) AS use_restriction,
             substr(link.value,3,1) AS deprecation,
             substr(link.value,4,1) AS display_restriction,
             link.id AS link_id,
             link.tag AS link_tag,
-            oils_xpath_string('//*[@tag="'||link.tag||'"]/*[local-name()="subfield"]', are.marc) AS link_value
+            oils_xpath_string('//*[@tag="'||link.tag||'"]/*[local-name()="subfield"]', are.marc) AS link_value,
+            authority.normalize_heading(are.marc) AS normalized_main_value
       FROM  authority.full_rec main
             JOIN authority.record_entry are ON (main.record = are.id)
             JOIN authority.control_set_authority_field main_entry