Koha/installer/data/mysql/db_revs/210600013.pl
Jonathan Druart 934dba4f07 Bug 29605: account_offsets.type is not null
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
2022-02-01 21:39:39 -10:00

42 lines
1.5 KiB
Perl
Executable file

use Modern::Perl;
return {
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'
) NOT NULL
AFTER `debit_id`
}
);
},
}