Bug 28633: DB update

This adds the field to necessary tables and updates API and columns def
and sets preferred name to firstname

Signed-off-by: Emily Lamancusa <emily.lamancusa@montgomerycountymd.gov>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Nick Clemens 2022-01-03 15:21:52 +00:00 committed by Katrin Fischer
parent 3a296f545c
commit 131ff0f402
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
3 changed files with 69 additions and 0 deletions

View File

@ -19,6 +19,11 @@ properties:
- string
- "null"
description: patron's first name
preferred_name:
type:
- string
- "null"
description: patron's preferred name
middle_name:
type:
- string

View File

@ -0,0 +1,61 @@
use Modern::Perl;
return {
bug_number => "28633",
description => "Add preferred_name to borrowers table",
up => sub {
my ($args) = @_;
my ( $dbh, $out ) = @$args{qw(dbh out)};
if ( !column_exists( 'borrowers', 'preferred_name' ) ) {
$dbh->do(
q{
ALTER TABLE borrowers
ADD COLUMN preferred_name longtext NULL DEFAULT NULL
COMMENT "patron/borrower's preferred name"
AFTER firstname
}
);
say $out "Added column 'borrowers.preferred_name'";
}
if ( !column_exists( 'deletedborrowers', 'preferred_name' ) ) {
$dbh->do(
q{
ALTER TABLE deletedborrowers
ADD COLUMN preferred_name longtext NULL DEFAULT NULL
COMMENT "patron/borrower's preferred name"
AFTER firstname
}
);
say $out "Added column 'deletedborrowers.preferred_name'";
}
if ( !column_exists( 'borrower_modifications', 'preferred_name' ) ) {
$dbh->do(
q{
ALTER TABLE borrower_modifications
ADD COLUMN preferred_name longtext NULL DEFAULT NULL
COMMENT "patron/borrower's preferred name"
AFTER firstname
}
);
say $out "Added column 'borrower_modifications.preferred_name'";
}
my @default_patron_search_fields = split( '\|', C4::Context->preference('DefaultPatronSearchFields') );
unless ( grep /preferred_name/, @default_patron_search_fields ) {
if ( grep /firstname/, @default_patron_search_fields ) {
push @default_patron_search_fields, 'preferred_name';
C4::Context->set_preference( 'DefaultPatronSearchFields', join( '|', @default_patron_search_fields ) );
say $out "Added 'preferred_name' to DefaultPatronSearchFields";
} else {
say $out "Please add 'preferred_name' to DefaultPatronSearchFields if you want it searched by default";
}
}
$dbh->do(
q{
UPDATE borrowers
SET preferred_name = firstname
WHERE preferred_name IS NULL
}
);
say $out "Initially set preferred_name to firstname";
},
}

View File

@ -1407,6 +1407,7 @@ CREATE TABLE `borrower_modifications` (
`cardnumber` varchar(32) DEFAULT NULL,
`surname` longtext DEFAULT NULL,
`firstname` mediumtext DEFAULT NULL,
`preferred_name` longtext DEFAULT NULL COMMENT 'patron/borrower''s preferred name',
`middle_name` longtext DEFAULT NULL COMMENT 'patron/borrower''s middle name',
`title` longtext DEFAULT NULL,
`othernames` longtext DEFAULT NULL,
@ -1528,6 +1529,7 @@ CREATE TABLE `borrowers` (
`cardnumber` varchar(32) DEFAULT NULL COMMENT 'unique key, library assigned ID number for patrons/borrowers',
`surname` longtext DEFAULT NULL COMMENT 'patron/borrower''s last name (surname)',
`firstname` mediumtext DEFAULT NULL COMMENT 'patron/borrower''s first name',
`preferred_name` longtext DEFAULT NULL COMMENT 'patron/borrower''s preferred name',
`middle_name` longtext DEFAULT NULL COMMENT 'patron/borrower''s middle name',
`title` longtext DEFAULT NULL COMMENT 'patron/borrower''s title, for example: Mr. or Mrs.',
`othernames` longtext DEFAULT NULL COMMENT 'any other names associated with the patron/borrower',
@ -2666,6 +2668,7 @@ CREATE TABLE `deletedborrowers` (
`cardnumber` varchar(32) DEFAULT NULL COMMENT 'unique key, library assigned ID number for patrons/borrowers',
`surname` longtext DEFAULT NULL COMMENT 'patron/borrower''s last name (surname)',
`firstname` mediumtext DEFAULT NULL COMMENT 'patron/borrower''s first name',
`preferred_name` longtext DEFAULT NULL COMMENT 'patron/borrower''s preferred name',
`middle_name` longtext DEFAULT NULL COMMENT 'patron/borrower''s middle name',
`title` longtext DEFAULT NULL COMMENT 'patron/borrower''s title, for example: Mr. or Mrs.',
`othernames` longtext DEFAULT NULL COMMENT 'any other names associated with the patron/borrower',