LP#1901597: Stamp upgrade scripts
authorChris Sharp <csharp@georgialibraries.org>
Fri, 24 Sep 2021 18:50:52 +0000 (14:50 -0400)
committerChris Sharp <csharp@georgialibraries.org>
Fri, 24 Sep 2021 18:50:52 +0000 (14:50 -0400)
Signed-off-by: Chris Sharp <csharp@georgialibraries.org>
Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/upgrade/1299.function.strip_field_multimatch.sql [new file with mode: 0644]
Open-ILS/src/sql/Pg/upgrade/XXXX.function.strip_field_multimatch.sql [deleted file]

index 6339ed5..966a2c6 100644 (file)
@@ -92,7 +92,7 @@ CREATE TRIGGER no_overlapping_deps
     BEFORE INSERT OR UPDATE ON config.db_patch_dependencies
     FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates');
 
-INSERT INTO config.upgrade_log (version, applied_to) VALUES ('1298', :eg_version); -- miker / ehardy / csharp
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('1299', :eg_version); -- miker / rogan / csharp
 
 CREATE TABLE config.bib_source (
        id              SERIAL  PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/upgrade/1299.function.strip_field_multimatch.sql b/Open-ILS/src/sql/Pg/upgrade/1299.function.strip_field_multimatch.sql
new file mode 100644 (file)
index 0000000..61929bc
--- /dev/null
@@ -0,0 +1,72 @@
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('1299', :eg_version);
+
+CREATE OR REPLACE FUNCTION vandelay.strip_field(xml text, field text) RETURNS text AS $f$
+
+    use MARC::Record;
+    use MARC::File::XML (BinaryEncoding => 'UTF-8');
+    use MARC::Charset;
+    use strict;
+
+    MARC::Charset->assume_unicode(1);
+
+    my $xml = shift;
+    my $r = MARC::Record->new_from_xml( $xml );
+
+    return $xml unless ($r);
+
+    my $field_spec = shift;
+    my @field_list = split(',', $field_spec);
+
+    my %fields;
+    for my $f (@field_list) {
+        $f =~ s/^\s*//; $f =~ s/\s*$//;
+        if ($f =~ /^(.{3})(\w*)(?:\[([^]]*)\])?$/) {
+            my $field = $1;
+            $field =~ s/\s+//;
+            my $sf = $2;
+            $sf =~ s/\s+//;
+            my $matches = $3;
+            $matches =~ s/^\s*//; $matches =~ s/\s*$//;
+            $fields{$field} = { sf => [ split('', $sf) ] };
+            if ($matches) {
+                for my $match (split('&&', $matches)) {
+                    $match =~ s/^\s*//; $match =~ s/\s*$//;
+                    my ($msf,$mre) = split('~', $match);
+                    if (length($msf) > 0 and length($mre) > 0) {
+                        $msf =~ s/^\s*//; $msf =~ s/\s*$//;
+                        $mre =~ s/^\s*//; $mre =~ s/\s*$//;
+                        $fields{$field}{match}{$msf} = qr/$mre/;
+                    }
+                }
+            }
+        }
+    }
+
+    for my $f ( keys %fields) {
+        for my $to_field ($r->field( $f )) {
+            if (exists($fields{$f}{match})) {
+                my @match_list = grep { $to_field->subfield($_) =~ $fields{$f}{match}{$_} } keys %{$fields{$f}{match}};
+                next unless (scalar(@match_list) == scalar(keys %{$fields{$f}{match}}));
+            }
+
+            if ( @{$fields{$f}{sf}} ) {
+                $to_field->delete_subfield(code => $fields{$f}{sf});
+            } else {
+                $r->delete_field( $to_field );
+            }
+        }
+    }
+
+    $xml = $r->as_xml_record;
+    $xml =~ s/^<\?.+?\?>$//mo;
+    $xml =~ s/\n//sgo;
+    $xml =~ s/>\s+</></sgo;
+
+    return $xml;
+
+$f$ LANGUAGE plperlu;
+
+COMMIT;
+
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.function.strip_field_multimatch.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.function.strip_field_multimatch.sql
deleted file mode 100644 (file)
index f61ecf2..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-BEGIN;
-
-SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
-
-CREATE OR REPLACE FUNCTION vandelay.strip_field(xml text, field text) RETURNS text AS $f$
-
-    use MARC::Record;
-    use MARC::File::XML (BinaryEncoding => 'UTF-8');
-    use MARC::Charset;
-    use strict;
-
-    MARC::Charset->assume_unicode(1);
-
-    my $xml = shift;
-    my $r = MARC::Record->new_from_xml( $xml );
-
-    return $xml unless ($r);
-
-    my $field_spec = shift;
-    my @field_list = split(',', $field_spec);
-
-    my %fields;
-    for my $f (@field_list) {
-        $f =~ s/^\s*//; $f =~ s/\s*$//;
-        if ($f =~ /^(.{3})(\w*)(?:\[([^]]*)\])?$/) {
-            my $field = $1;
-            $field =~ s/\s+//;
-            my $sf = $2;
-            $sf =~ s/\s+//;
-            my $matches = $3;
-            $matches =~ s/^\s*//; $matches =~ s/\s*$//;
-            $fields{$field} = { sf => [ split('', $sf) ] };
-            if ($matches) {
-                for my $match (split('&&', $matches)) {
-                    $match =~ s/^\s*//; $match =~ s/\s*$//;
-                    my ($msf,$mre) = split('~', $match);
-                    if (length($msf) > 0 and length($mre) > 0) {
-                        $msf =~ s/^\s*//; $msf =~ s/\s*$//;
-                        $mre =~ s/^\s*//; $mre =~ s/\s*$//;
-                        $fields{$field}{match}{$msf} = qr/$mre/;
-                    }
-                }
-            }
-        }
-    }
-
-    for my $f ( keys %fields) {
-        for my $to_field ($r->field( $f )) {
-            if (exists($fields{$f}{match})) {
-                my @match_list = grep { $to_field->subfield($_) =~ $fields{$f}{match}{$_} } keys %{$fields{$f}{match}};
-                next unless (scalar(@match_list) == scalar(keys %{$fields{$f}{match}}));
-            }
-
-            if ( @{$fields{$f}{sf}} ) {
-                $to_field->delete_subfield(code => $fields{$f}{sf});
-            } else {
-                $r->delete_field( $to_field );
-            }
-        }
-    }
-
-    $xml = $r->as_xml_record;
-    $xml =~ s/^<\?.+?\?>$//mo;
-    $xml =~ s/\n//sgo;
-    $xml =~ s/>\s+</></sgo;
-
-    return $xml;
-
-$f$ LANGUAGE plperlu;
-
-COMMIT;
-