Script that will update existing databases, creating any new tables,
[koha.git] / updater / updatedatabase
1 #!/usr/bin/perl
2
3 # This script will check for required updates to the database.  Would also be a
4 # good idea to offer to do a backup at this time...
5
6
7 use C4::Database;
8 use C4::Catalogue;
9 use DBI;
10 use C4::Acquisitions;
11 use C4::Output;
12 my $dbh=C4Connect;
13
14 my %tables;
15 my %types;
16
17 my $sth=$dbh->prepare("show tables");
18 $sth->execute;
19 while (my ($table) = $sth->fetchrow) {
20     $tables{$table}=1;
21     print "Table: $table\n";
22 }
23
24
25
26 # Add tables required by Z-3950 scripts
27
28 unless ($tables{'z3950queue') {
29     my $sti=$dbh->prepare("create table z3950queue (id int auto_increment primary key, term text, type char(10), startdate int, enddate int, done smallint, results longblob, numercords int, servers text, identifier char(30))");
30     $sti->execute;
31 }
32
33 unless ($tables{'z3950results'}) {
34     my $sti=$dbh->prepare("create table z3950results (id int auto_increment primary key, queryid int, server char(255), startdate int, enddate int, results longblob, numrecords int, numdownloaded int, highestseen int, active smallint)");
35     $sti->execute;
36 }
37 unless ($tables{'z3950servers'}) {
38     my $sti=$dbh->prepare("create table z3950servers (host char(255), port int, db char(255), userid char(255), password char(255), name text, id int, checked smallint, rank int)");
39     $sti->execute;
40     $sti=$dbh->prepare("insert into z3950servers values ('z3950.loc.gov', 7090, 'voyager', '', '', 'Library of Congress', 1, 1, 1)");
41     $sti->execute;
42 }
43
44
45
46 # Get list of columns from biblioitems table
47
48 my $sth=$dbh->prepare("show columns from biblioitems");
49 $sth->execute;
50 while (my ($column, $type, $null, $key, $default, $extra) = $sth->fetchrow) {
51     $types{$column}=$type;
52 }
53 unless ($types{'lccn'}) {
54     # Add LCCN field to biblioitems db
55     my $sti=$dbh->prepare("alter table biblioitems add column lccn char(25)");
56     $sti->execute;
57 }
58 unless ($types{'marc'}) {
59     # Add MARC field to biblioitems db (not used anymore)
60     my $sti=$dbh->prepare("alter table biblioitems add column marc text");
61     $sti->execute;
62 }
63
64
65 $sth->finish;
66 $dbh->disconnect;