Bug 18177: Do not remove columns if at least one value exists

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Jonathan Druart 2020-03-24 16:22:33 +01:00 committed by Martin Renvoize
parent 57788803e0
commit f50fee2546
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
1 changed files with 12 additions and 3 deletions

View File

@ -3,10 +3,19 @@ if( CheckVersion( $DBversion ) ) {
for my $column ( qw(othersupplier booksellerfax booksellerurl bookselleremail currency) ) {
if( column_exists( 'aqbooksellers', $column ) ) {
$dbh->do(qq|
ALTER TABLE aqbooksellers
DROP COLUMN $column
my ($count) = $dbh->selectrow_array(qq|
SELECT COUNT(*)
FROM aqbooksellers
WHERE $column IS NOT NULL AND $column <> ""
|);
if ( $count ) {
warn "Warning - Cannot remove column aqbooksellers.$column. At least one value exists";
} else {
$dbh->do(qq|
ALTER TABLE aqbooksellers
DROP COLUMN $column
|);
}
}
}