Bug 26302: (QA follow-up) Prefix prefs with OPAC
[koha.git] / installer / data / mysql / db_revs / 210600013.pl
1 use Modern::Perl;
2
3 return {
4     bug_number => "22435",
5     description => "Update existing offsets",
6     up => sub {
7         my ($args) = @_;
8         my $dbh = $args->{dbh};
9
10         # Remove foreign key for offset types
11         if ( foreign_key_exists( 'account_offsets', 'account_offsets_ibfk_t' ) ) {
12             $dbh->do( "ALTER TABLE account_offsets DROP FOREIGN KEY account_offsets_ibfk_t" );
13         }
14
15         # Drop account_offset_types table
16         $dbh->do( "DROP TABLE IF EXISTS account_offset_types" );
17
18         # Update offset_types to 'CREATE' where appropriate
19         $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)" );
20         $dbh->do( "UPDATE account_offsets SET amount = ABS(amount) WHERE type = 'CREATE'" );
21
22         # Update offset_types to 'APPLY' where appropriate
23         $dbh->do( "UPDATE account_offsets SET type = 'APPLY' WHERE type != 'OVERDUE_INCREASE' AND type != 'OVERDUE_DECREASE' AND type != 'CREATE' AND type != 'VOID'" );
24
25         # Update table to ENUM
26         $dbh->do(
27             q{
28                 ALTER TABLE
29                     `account_offsets`
30                 MODIFY COLUMN
31                     `type` enum(
32                         'CREATE',
33                         'APPLY',
34                         'VOID',
35                         'OVERDUE_INCREASE',
36                         'OVERDUE_DECREASE'
37                     )
38                 AFTER `debit_id`
39               }
40         );
41     },
42 }