]> git.evergreen-ils.org Git - Evergreen.git/blob - Evergreen/src/extras/import/drain-batgirl-hold.pl
last minute fixes -- frozen now for all time, as the data is in the DB
[Evergreen.git] / Evergreen / src / extras / import / drain-batgirl-hold.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use DBI;
5
6 my $dbh = DBI->connect('DBI:mysql:database=reports;host=batgirl.gsu.edu','miker','poopie');
7
8 print <<SQL;
9
10 DROP TABLE legacy_hold;
11 CREATE TABLE legacy_hold (available text, status text, notified text, num_of_notices int, cat_key int, call_key int, item_key int, hold_key int, user_key int, hold_date date, hold_range text, pickup_lib text, placing_lib text, owning_lib text, inactive_date text, inactive_reason text, hold_level text);
12 COPY legacy_hold (available, status, notified, num_of_notices, cat_key, call_key, item_key, hold_key, user_key, hold_date, hold_range, pickup_lib, placing_lib, owning_lib, inactive_date, inactive_reason, hold_level) FROM STDIN;
13 SQL
14
15 warn "going for the data...";
16
17 my $sth = $dbh->prepare("select * from HOLD where STATUS = 'ACTIVE'");
18 $sth->execute;
19
20 warn "got it, writing file...";
21
22 while (my $cn = $sth->fetchrow_hashref) {
23         my @data = map { $$cn{uc($_)} } qw/available status notified num_of_notices cat_key call_key item_key hold_key user_key hold_date hold_range pickup_lib placing_lib owning_lib inactive_date inactive_reason hold_level/;
24         for (@data) {
25                 if (defined($_)) {
26                         s/\\/\\\\/go;
27                         s/\t/ /go;
28                 } else {
29                         $_ = '\N';
30                 }
31         }
32         print join("\t", @data) . "\n";
33 }
34
35 print <<SQL
36 \\.
37
38 UPDATE legacy_hold SET notified = null where notified = '0';
39 UPDATE legacy_hold SET inactive_date = null where inactive_date = '0';
40
41 ALTER TABLE legacy_hold ALTER COLUMN notified TYPE DATE USING notified::DATE;
42 ALTER TABLE legacy_hold ALTER COLUMN inactive_date TYPE DATE USING inactive_date::DATE;
43
44 SQL
45
46