Bug 27253: (follow-up) Fix UNIXTIME(0) in db_revs/211200037.pl
[koha.git] / installer / data / mysql / db_revs / 211105001.pl
1 use Modern::Perl;
2
3 return {
4     bug_number => "27253",
5     description => "Fix definition of borrowers.updated_on and deletedborrowers.updated_on",
6     up => sub {
7         my ($args) = @_;
8         my ($dbh, $out) = @$args{qw(dbh out)};
9
10         my $rv = $dbh->do(q{
11             UPDATE borrowers
12             SET updated_on = GREATEST(
13                 COALESCE(date_renewed, FROM_UNIXTIME(1)),
14                 COALESCE(dateenrolled, FROM_UNIXTIME(1)),
15                 COALESCE(lastseen, FROM_UNIXTIME(1))
16             )
17             WHERE updated_on IS NULL
18         });
19         say $out sprintf('Updated all NULL values of borrowers.updated_on to GREATEST(date_renewed, dateenrolled, lastseen): %d rows updated', $rv);
20
21         $rv = $dbh->do(q{
22             UPDATE deletedborrowers
23             SET updated_on = GREATEST(
24                 COALESCE(date_renewed, FROM_UNIXTIME(1)),
25                 COALESCE(dateenrolled, FROM_UNIXTIME(1)),
26                 COALESCE(lastseen, FROM_UNIXTIME(1))
27             )
28             WHERE updated_on IS NULL
29         });
30         say $out sprintf('Updated all NULL values of borrowers.updated_on to GREATEST(date_renewed, dateenrolled, lastseen): %d rows updated', $rv);
31
32         $dbh->do(q{
33             ALTER TABLE borrowers
34             MODIFY updated_on timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
35             COMMENT 'time of last change could be useful for synchronization with external systems (among others)'
36         });
37         say $out 'Fixed definition of borrowers.updated_on';
38
39         $dbh->do(q{
40             ALTER TABLE deletedborrowers
41             MODIFY updated_on timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
42             COMMENT 'time of last change could be useful for synchronization with external systems (among others)'
43         });
44         say $out 'Fixed definition of deletedborrowers.updated_on';
45     },
46 };