koha-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-devel] CVS: koha/updater updatedatabase,NONE,1.1


From: Steve Tonnesen
Subject: [Koha-devel] CVS: koha/updater updatedatabase,NONE,1.1
Date: Mon Nov 19 10:27:04 2001

Update of /cvsroot/koha/koha/updater
In directory usw-pr-cvs1:/tmp/cvs-serv4842

Added Files:
        updatedatabase 
Log Message:
Script that will update existing databases, creating any new tables,
adding, modifying or removing any fields from existing tables.

This is in very early stages.  Need to go through and ascertain which
tables and fields need to be added/modified.  Also need to add a "backup"
before any modifications are made.  Thoughts on this are welcome.


--- NEW FILE ---
#!/usr/bin/perl

# This script will check for required updates to the database.  Would also be a
# good idea to offer to do a backup at this time...


use C4::Database;
use C4::Catalogue;
use DBI;
use C4::Acquisitions;
use C4::Output;
my $dbh=C4Connect;

my %tables;
my %types;

my $sth=$dbh->prepare("show tables");
$sth->execute;
while (my ($table) = $sth->fetchrow) {
    $tables{$table}=1;
    print "Table: $table\n";
}



# Add tables required by Z-3950 scripts

unless ($tables{'z3950queue') {
    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))");
    $sti->execute;
}

unless ($tables{'z3950results'}) {
    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)");
    $sti->execute;
}
unless ($tables{'z3950servers'}) {
    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)");
    $sti->execute;
    $sti=$dbh->prepare("insert into z3950servers values ('z3950.loc.gov', 7090, 
'voyager', '', '', 'Library of Congress', 1, 1, 1)");
    $sti->execute;
}



# Get list of columns from biblioitems table

my $sth=$dbh->prepare("show columns from biblioitems");
$sth->execute;
while (my ($column, $type, $null, $key, $default, $extra) = $sth->fetchrow) {
    $types{$column}=$type;
}
unless ($types{'lccn'}) {
    # Add LCCN field to biblioitems db
    my $sti=$dbh->prepare("alter table biblioitems add column lccn char(25)");
    $sti->execute;
}
unless ($types{'marc'}) {
    # Add MARC field to biblioitems db (not used anymore)
    my $sti=$dbh->prepare("alter table biblioitems add column marc text");
    $sti->execute;
}


$sth->finish;
$dbh->disconnect;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]