From c6d91f4009833588cca9b755ec5b8a465bf7d974 Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Wed, 22 Aug 2012 12:20:22 -0400 Subject: [PATCH] 2.2.0 -> 2.2.1 upgrade script never actually went into master or rel_2_2 Signed-off-by: Lebbeous Fogle-Weekley --- .../2.2.0-2.2.1-upgrade-db.sql | 366 ++++++++++++++++++ 1 file changed, 366 insertions(+) create mode 100644 Open-ILS/src/sql/Pg/version-upgrade/2.2.0-2.2.1-upgrade-db.sql diff --git a/Open-ILS/src/sql/Pg/version-upgrade/2.2.0-2.2.1-upgrade-db.sql b/Open-ILS/src/sql/Pg/version-upgrade/2.2.0-2.2.1-upgrade-db.sql new file mode 100644 index 0000000000..c409acea31 --- /dev/null +++ b/Open-ILS/src/sql/Pg/version-upgrade/2.2.0-2.2.1-upgrade-db.sql @@ -0,0 +1,366 @@ +--Upgrade Script for 2.2.0 to 2.2.1 +BEGIN; +INSERT INTO config.upgrade_log (version, applied_to) VALUES ('2.2.1', :eg_version); +-- Evergreen DB patch 0722.schema.acq-po-state-constraint.sql +-- + + +-- check whether patch can be applied +SELECT evergreen.upgrade_deps_block_check('0722', :eg_version); + +ALTER TABLE acq.purchase_order ADD CONSTRAINT valid_po_state + CHECK (state IN ('new','pending','on-order','received','cancelled')); + +-- Evergreen DB patch 0723.schema.function.get_locale_name.sql +-- + + +-- check whether patch can be applied +SELECT evergreen.upgrade_deps_block_check('0723', :eg_version); + +CREATE OR REPLACE FUNCTION evergreen.get_locale_name( + IN locale TEXT, + OUT name TEXT, + OUT description TEXT +) AS $$ +DECLARE + eg_locale TEXT; +BEGIN + eg_locale := LOWER(SUBSTRING(locale FROM 1 FOR 2)) || '-' || UPPER(SUBSTRING(locale FROM 4 FOR 2)); + + SELECT i18nc.string INTO name + FROM config.i18n_locale i18nl + INNER JOIN config.i18n_core i18nc ON i18nl.code = i18nc.translation + WHERE i18nc.identity_value = eg_locale + AND code = eg_locale + AND i18nc.fq_field = 'i18n_l.name'; + + IF name IS NULL THEN + SELECT i18nl.name INTO name + FROM config.i18n_locale i18nl + WHERE code = eg_locale; + END IF; + + SELECT i18nc.string INTO description + FROM config.i18n_locale i18nl + INNER JOIN config.i18n_core i18nc ON i18nl.code = i18nc.translation + WHERE i18nc.identity_value = eg_locale + AND code = eg_locale + AND i18nc.fq_field = 'i18n_l.description'; + + IF description IS NULL THEN + SELECT i18nl.description INTO description + FROM config.i18n_locale i18nl + WHERE code = eg_locale; + END IF; +END; +$$ LANGUAGE PLPGSQL COST 1 STABLE; + + +INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0724', :eg_version); -- denials/gmcharlt + +CREATE OR REPLACE FUNCTION evergreen.maintain_901 () RETURNS TRIGGER AS $func$ +use strict; +use MARC::Record; +use MARC::File::XML (BinaryEncoding => 'UTF-8'); +use MARC::Charset; +use Encode; +use Unicode::Normalize; + +MARC::Charset->assume_unicode(1); + +my $schema = $_TD->{table_schema}; +my $marc = MARC::Record->new_from_xml($_TD->{new}{marc}); + +my @old901s = $marc->field('901'); +$marc->delete_fields(@old901s); + +if ($schema eq 'biblio') { + my $tcn_value = $_TD->{new}{tcn_value}; + + # Set TCN value to record ID? + my $id_as_tcn = spi_exec_query(" + SELECT enabled + FROM config.global_flag + WHERE name = 'cat.bib.use_id_for_tcn' + "); + if (($id_as_tcn->{processed}) && $id_as_tcn->{rows}[0]->{enabled} eq 't') { + $tcn_value = $_TD->{new}{id}; + } + + my $new_901 = MARC::Field->new("901", " ", " ", + "a" => $tcn_value, + "b" => $_TD->{new}{tcn_source}, + "c" => $_TD->{new}{id}, + "t" => $schema + ); + + if ($_TD->{new}{owner}) { + $new_901->add_subfields("o" => $_TD->{new}{owner}); + } + + if ($_TD->{new}{share_depth}) { + $new_901->add_subfields("d" => $_TD->{new}{share_depth}); + } + + $marc->append_fields($new_901); +} elsif ($schema = 'authority') { + $marc->append_fields( + ["901", " ", " ", + "c" => $_TD->{new}{id}, + "t" => $schema, + ] + ); +} elsif ($schema = 'serial') { + my $new_901 = MARC::Field->new("901", " ", " ", + "c" => $_TD->{new}{id}, + "t" => $schema, + "o" => $_TD->{new}{owning_lib}, + ); + + if ($_TD->{new}{record}) { + $new_901->add_subfields("r" => $_TD->{new}{record}); + } + + $marc->append_fields($new_901); +} else { + $marc->append_fields( + ["901", " ", " ", + "c" => $_TD->{new}{id}, + "t" => $schema, + ] + ); +} + +my $xml = $marc->as_xml_record(); +$xml =~ s/\n//sgo; +$xml =~ s/^<\?xml.+\?\s*>//go; +$xml =~ s/>\s+entityize() +# to avoid having to set PERL5LIB for PostgreSQL as well + +# If we are going to convert non-ASCII characters to XML entities, +# we had better be dealing with a UTF8 string to begin with +$xml = decode_utf8($xml); + +$xml = NFC($xml); + +# Convert raw ampersands to entities +$xml =~ s/&(?!\S+;)/&/gso; + +# Convert Unicode characters to entities +$xml =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe; + +$xml =~ s/[\x00-\x1f]//go; +$_TD->{new}{marc} = $xml; + +return "MODIFY"; +$func$ LANGUAGE PLPERLU; + + +INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0725', :eg_version); -- gmcharlt/denials + +CREATE OR REPLACE FUNCTION evergreen.maintain_901 () RETURNS TRIGGER AS $func$ +use strict; +use MARC::Record; +use MARC::File::XML (BinaryEncoding => 'UTF-8'); +use MARC::Charset; +use Encode; +use Unicode::Normalize; + +MARC::Charset->assume_unicode(1); + +my $schema = $_TD->{table_schema}; +my $marc = MARC::Record->new_from_xml($_TD->{new}{marc}); + +my @old901s = $marc->field('901'); +$marc->delete_fields(@old901s); + +if ($schema eq 'biblio') { + my $tcn_value = $_TD->{new}{tcn_value}; + + # Set TCN value to record ID? + my $id_as_tcn = spi_exec_query(" + SELECT enabled + FROM config.global_flag + WHERE name = 'cat.bib.use_id_for_tcn' + "); + if (($id_as_tcn->{processed}) && $id_as_tcn->{rows}[0]->{enabled} eq 't') { + $tcn_value = $_TD->{new}{id}; + } + + my $new_901 = MARC::Field->new("901", " ", " ", + "a" => $tcn_value, + "b" => $_TD->{new}{tcn_source}, + "c" => $_TD->{new}{id}, + "t" => $schema + ); + + if ($_TD->{new}{owner}) { + $new_901->add_subfields("o" => $_TD->{new}{owner}); + } + + if ($_TD->{new}{share_depth}) { + $new_901->add_subfields("d" => $_TD->{new}{share_depth}); + } + + $marc->append_fields($new_901); +} elsif ($schema eq 'authority') { + $marc->append_fields( + ["901", " ", " ", + "c" => $_TD->{new}{id}, + "t" => $schema, + ] + ); +} elsif ($schema eq 'serial') { + my $new_901 = MARC::Field->new("901", " ", " ", + "c" => $_TD->{new}{id}, + "t" => $schema, + "o" => $_TD->{new}{owning_lib}, + ); + + if ($_TD->{new}{record}) { + $new_901->add_subfields("r" => $_TD->{new}{record}); + } + + $marc->append_fields($new_901); +} else { + $marc->append_fields( + ["901", " ", " ", + "c" => $_TD->{new}{id}, + "t" => $schema, + ] + ); +} + +my $xml = $marc->as_xml_record(); +$xml =~ s/\n//sgo; +$xml =~ s/^<\?xml.+\?\s*>//go; +$xml =~ s/>\s+entityize() +# to avoid having to set PERL5LIB for PostgreSQL as well + +# If we are going to convert non-ASCII characters to XML entities, +# we had better be dealing with a UTF8 string to begin with +$xml = decode_utf8($xml); + +$xml = NFC($xml); + +# Convert raw ampersands to entities +$xml =~ s/&(?!\S+;)/&/gso; + +# Convert Unicode characters to entities +$xml =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe; + +$xml =~ s/[\x00-\x1f]//go; +$_TD->{new}{marc} = $xml; + +return "MODIFY"; +$func$ LANGUAGE PLPERLU; + + +INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0726', :eg_version); -- denials + +CREATE OR REPLACE FUNCTION evergreen.maintain_901 () RETURNS TRIGGER AS $func$ +use strict; +use MARC::Record; +use MARC::File::XML (BinaryEncoding => 'UTF-8'); +use MARC::Charset; +use Encode; +use Unicode::Normalize; + +MARC::Charset->assume_unicode(1); + +my $schema = $_TD->{table_schema}; +my $marc = MARC::Record->new_from_xml($_TD->{new}{marc}); + +my @old901s = $marc->field('901'); +$marc->delete_fields(@old901s); + +if ($schema eq 'biblio') { + my $tcn_value = $_TD->{new}{tcn_value}; + + # Set TCN value to record ID? + my $id_as_tcn = spi_exec_query(" + SELECT enabled + FROM config.global_flag + WHERE name = 'cat.bib.use_id_for_tcn' + "); + if (($id_as_tcn->{processed}) && $id_as_tcn->{rows}[0]->{enabled} eq 't') { + $tcn_value = $_TD->{new}{id}; + } + + my $new_901 = MARC::Field->new("901", " ", " ", + "a" => $tcn_value, + "b" => $_TD->{new}{tcn_source}, + "c" => $_TD->{new}{id}, + "t" => $schema + ); + + if ($_TD->{new}{owner}) { + $new_901->add_subfields("o" => $_TD->{new}{owner}); + } + + if ($_TD->{new}{share_depth}) { + $new_901->add_subfields("d" => $_TD->{new}{share_depth}); + } + + $marc->append_fields($new_901); +} elsif ($schema eq 'authority') { + my $new_901 = MARC::Field->new("901", " ", " ", + "c" => $_TD->{new}{id}, + "t" => $schema, + ); + $marc->append_fields($new_901); +} elsif ($schema eq 'serial') { + my $new_901 = MARC::Field->new("901", " ", " ", + "c" => $_TD->{new}{id}, + "t" => $schema, + "o" => $_TD->{new}{owning_lib}, + ); + + if ($_TD->{new}{record}) { + $new_901->add_subfields("r" => $_TD->{new}{record}); + } + + $marc->append_fields($new_901); +} else { + my $new_901 = MARC::Field->new("901", " ", " ", + "c" => $_TD->{new}{id}, + "t" => $schema, + ); + $marc->append_fields($new_901); +} + +my $xml = $marc->as_xml_record(); +$xml =~ s/\n//sgo; +$xml =~ s/^<\?xml.+\?\s*>//go; +$xml =~ s/>\s+entityize() +# to avoid having to set PERL5LIB for PostgreSQL as well + +# If we are going to convert non-ASCII characters to XML entities, +# we had better be dealing with a UTF8 string to begin with +$xml = decode_utf8($xml); + +$xml = NFC($xml); + +# Convert raw ampersands to entities +$xml =~ s/&(?!\S+;)/&/gso; + +# Convert Unicode characters to entities +$xml =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe; + +$xml =~ s/[\x00-\x1f]//go; +$_TD->{new}{marc} = $xml; + +return "MODIFY"; +$func$ LANGUAGE PLPERLU; + +COMMIT; -- 2.43.2