Bug 40337: (QA follow-up) Make database update idempotent
Running this update twice fails before this patch with:
ERROR: {UNKNOWN}: DBI Exception: DBD::mysql::db do failed: Data truncated for column 'checkprevcheckout' at row 3 at /kohadevbox/koha/C4/Installer.pm line 825
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
parent
b32262fa19
commit
8bdbbd74b8
|
|
@ -8,25 +8,82 @@ return {
|
|||
my ($args) = @_;
|
||||
my ( $dbh, $out ) = @$args{qw(dbh out)};
|
||||
|
||||
$dbh->do(
|
||||
my $col_type_borrowers = $dbh->selectrow_array(
|
||||
q{
|
||||
ALTER TABLE borrowers
|
||||
MODIFY COLUMN `checkprevcheckout` enum('yes', 'no', 'inherit') NOT NULL DEFAULT 'inherit' COMMENT 'produce a warning for this patron if this item has previously been checked out to this patron if ''yes'', not if ''no'', defer to category setting if ''inherit''.'
|
||||
}
|
||||
SELECT COLUMN_TYPE
|
||||
FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'borrowers'
|
||||
AND COLUMN_NAME = 'checkprevcheckout'
|
||||
}
|
||||
);
|
||||
|
||||
$dbh->do(
|
||||
q{
|
||||
ALTER TABLE categories
|
||||
MODIFY COLUMN `checkprevcheckout` enum('yes', 'no', 'inherit') NOT NULL DEFAULT 'inherit' COMMENT 'produce a warning for this patron category if this item has previously been checked out to this patron if ''yes'', not if ''no'', defer to syspref setting if ''inherit''.'
|
||||
if ( $col_type_borrowers !~ /^enum/i ) {
|
||||
$dbh->do(
|
||||
q{
|
||||
UPDATE borrowers
|
||||
SET checkprevcheckout = 'inherit'
|
||||
WHERE checkprevcheckout NOT IN ('yes','no','inherit');
|
||||
}
|
||||
);
|
||||
$dbh->do(
|
||||
q{
|
||||
ALTER TABLE borrowers
|
||||
MODIFY COLUMN `checkprevcheckout` enum('yes', 'no', 'inherit') NOT NULL DEFAULT 'inherit' COMMENT 'produce a warning for this patron if this item has previously been checked out to this patron if ''yes'', not if ''no'', defer to category setting if ''inherit''.'
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
my $col_type_categories = $dbh->selectrow_array(
|
||||
q{
|
||||
SELECT COLUMN_TYPE
|
||||
FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'categories'
|
||||
AND COLUMN_NAME = 'checkprevcheckout'
|
||||
}
|
||||
);
|
||||
|
||||
$dbh->do(
|
||||
q{
|
||||
ALTER TABLE deletedborrowers
|
||||
MODIFY COLUMN `checkprevcheckout` enum('yes', 'no', 'inherit') NOT NULL DEFAULT 'inherit' COMMENT 'produce a warning for this patron if this item has previously been checked out to this patron if ''yes'', not if ''no'', defer to category setting if ''inherit''.'
|
||||
if ( $col_type_categories !~ /^enum/i ) {
|
||||
$dbh->do(
|
||||
q{
|
||||
UPDATE categories
|
||||
SET checkprevcheckout = 'inherit'
|
||||
WHERE checkprevcheckout NOT IN ('yes','no','inherit');
|
||||
}
|
||||
);
|
||||
$dbh->do(
|
||||
q{
|
||||
ALTER TABLE categories
|
||||
MODIFY COLUMN `checkprevcheckout` enum('yes', 'no', 'inherit') NOT NULL DEFAULT 'inherit' COMMENT 'produce a warning for this patron category if this item has previously been checked out to this patron if ''yes'', not if ''no'', defer to syspref setting if ''inherit''.'
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
my $col_type_deletedborrowers = $dbh->selectrow_array(
|
||||
q{
|
||||
SELECT COLUMN_TYPE
|
||||
FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'deletedborrowers'
|
||||
AND COLUMN_NAME = 'checkprevcheckout'
|
||||
}
|
||||
);
|
||||
|
||||
if ( $col_type_deletedborrowers !~ /^enum/i ) {
|
||||
$dbh->do(
|
||||
q{
|
||||
UPDATE deletedborrowers
|
||||
SET checkprevcheckout = 'inherit'
|
||||
WHERE checkprevcheckout NOT IN ('yes','no','inherit');
|
||||
}
|
||||
);
|
||||
$dbh->do(
|
||||
q{
|
||||
ALTER TABLE deletedborrowers
|
||||
MODIFY COLUMN `checkprevcheckout` enum('yes', 'no', 'inherit') NOT NULL DEFAULT 'inherit' COMMENT 'produce a warning for this patron if this item has previously been checked out to this patron if ''yes'', not if ''no'', defer to category setting if ''inherit''.'
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue