Koha/installer/data/mysql/db_revs/210600013.pl
Jonathan Druart 64ccbdb8f2 Bug 25078: Move DB revs up to 21.06.00.016
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2021-08-16 11:55:56 +02:00

42 lines
1.5 KiB
Perl

use Modern::Perl;
{
bug_number => "22435",
description => "Update existing offsets",
up => sub {
my ($args) = @_;
my $dbh = $args->{dbh};
# Remove foreign key for offset types
if ( foreign_key_exists( 'account_offsets', 'account_offsets_ibfk_t' ) ) {
$dbh->do( "ALTER TABLE account_offsets DROP FOREIGN KEY account_offsets_ibfk_t" );
}
# Drop account_offset_types table
$dbh->do( "DROP TABLE IF EXISTS account_offset_types" );
# Update offset_types to 'CREATE' where appropriate
$dbh->do( "UPDATE account_offsets SET type = 'CREATE' WHERE type != 'OVERDUE_INCREASE' AND type != 'OVERDUE_DECREASE' AND ( debit_id IS NULL OR credit_id IS NULL)" );
$dbh->do( "UPDATE account_offsets SET amount = ABS(amount) WHERE type = 'CREATE'" );
# Update offset_types to 'APPLY' where appropriate
$dbh->do( "UPDATE account_offsets SET type = 'APPLY' WHERE type != 'OVERDUE_INCREASE' AND type != 'OVERDUE_DECREASE' AND type != 'CREATE' AND type != 'VOID'" );
# Update table to ENUM
$dbh->do(
q{
ALTER TABLE
`account_offsets`
MODIFY COLUMN
`type` enum(
'CREATE',
'APPLY',
'VOID',
'OVERDUE_INCREASE',
'OVERDUE_DECREASE'
)
AFTER `debit_id`
}
);
},
}