koha-cvs
[Top][All Lists]
Advanced

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

[Koha-cvs] CVS: koha/updater updatedatabase,1.4,1.4.2.1


From: Alan Millar
Subject: [Koha-cvs] CVS: koha/updater updatedatabase,1.4,1.4.2.1
Date: Wed, 29 May 2002 08:14:11 -0700

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

Modified Files:
      Tag: rel-1-2
        updatedatabase 
Log Message:
Bring branch up to date with mainline code, move table creation
to hash.


Index: updatedatabase
===================================================================
RCS file: /cvsroot/koha/koha/updater/updatedatabase,v
retrieving revision 1.4
retrieving revision 1.4.2.1
diff -C2 -r1.4 -r1.4.2.1
*** updatedatabase      26 Mar 2002 05:08:52 -0000      1.4
--- updatedatabase      29 May 2002 15:14:09 -0000      1.4.2.1
***************
*** 1,19 ****
  #!/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 $mysqlversion=`mysqld --version`;
  $mysqlversion=~/Ver (\S*) /;
--- 1,66 ----
  #!/usr/bin/perl
  
! # Database Updater
! # This script checks for required updates to the database.  
  
+ # Part of the Koha Library Software www.koha.org
+ # Licensed under the GPL.
  
! # Bugs/ToDo: 
! # - Would also be a good idea to offer to do a backup at this time...
! 
! use strict;
! 
! # CPAN modules
  use DBI;
  
! # Koha modules
! use C4::Database;
! 
! my %existingtables;   # tables already in database
  my %types;
+ my $table;
  
+ #-------------------
+ # Defines
  
+ # Tables to add if they don't exist
+ my %requiretables=(
+     shelfcontents=>"( shelfnumber int not null, 
+       itemnumber int not null, 
+       flags int)",
+     bookshelf=>"( shelfnumber int auto_increment primary key, 
+       shelfname char(255))",
+     z3950queue=>"( id int auto_increment primary key, 
+       term text, 
+       type char(10), 
+       startdate int, 
+       enddate int, 
+       done smallint, 
+       results longblob, 
+       numrecords int, 
+       servers text, 
+       identifier char(30))",
+     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)",
+     branchrelations=>"( branchcode varchar(4), 
+       categorycode varchar(4))",
+ );
+ 
+ #-------------------
+ # Initialize
+ my $dbh=C4Connect;
+ 
+ # Start checking
+ 
+ # Get version of MySQL database engine.
  my $mysqlversion=`mysqld --version`;
  $mysqlversion=~/Ver (\S*) /;
***************
*** 23,67 ****
  }
  
  my $sth=$dbh->prepare("show tables");
  $sth->execute;
  while (my ($table) = $sth->fetchrow) {
!     $tables{$table}=1;
  }
  
  
! # Add tables for virtual bookshelf management
! 
! unless ($tables{'shelfcontents'}) {
!     print "Adding shelfcontents table...\n";
!     my $sti=$dbh->prepare("create table shelfcontents (shelfnumber int not 
null, itemnumber int not null, flags int)");
!     $sti->execute;
! }
! unless ($tables{'bookshelf'}) {
!     print "Adding bookshelf table...\n";
!     my $sti=$dbh->prepare("create table bookshelf (shelfnumber int 
auto_increment primary key, shelfname char(255))");
!     $sti->execute;
! }
! 
! # Add tables required by Z-3950 scripts
! 
! unless ($tables{'z3950queue'}) {
!     print "Adding z3950queue table...\n";
!     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'}) {
!     print "Adding z3950results table...\n";
!     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'}) {
      print "Adding z3950servers table...\n";
!     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;
  }
  
  
  
--- 70,123 ----
  }
  
+ #---------------------------------
+ # Tables
+ 
+ # Collect all tables into a list
  my $sth=$dbh->prepare("show tables");
  $sth->execute;
  while (my ($table) = $sth->fetchrow) {
!     $existingtables{$table}=1;
  }
  
+ # Now add any missing tables
+ foreach $table ( keys %requiretables ) {
+     unless ($existingtables{$table} ) {
+       print "Adding $table table...\n";
+       my $sth=$dbh->prepare(
+               "create table $table $requiretables{$table}" );
+       $sth->execute;
+         if ($sth->err) {
+                 print "Error : $sth->errstr \n";
+                 $sth->finish;
+         } # if error
+     } # unless exists
+ } # foreach
+ exit;
  
! unless ($existingtables{'z3950servers'}) {
      print "Adding z3950servers table...\n";
!     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;
  }
  
+ #---------------------------------
+ # Columns
  
  
***************
*** 76,80 ****
      # Add LCCN field to biblioitems db
      print "Adding lccn field to biblioitems table...\n";
!     my $sti=$dbh->prepare("alter table biblioitems add column lccn char(25)");
      $sti->execute;
  }
--- 132,137 ----
      # Add LCCN field to biblioitems db
      print "Adding lccn field to biblioitems table...\n";
!     my $sti=$dbh->prepare("alter table biblioitems 
!       add column lccn char(25)");
      $sti->execute;
  }
***************
*** 82,86 ****
      # Add MARC field to biblioitems db (not used anymore)
      print "Adding marc field to biblioitems table...\n";
!     my $sti=$dbh->prepare("alter table biblioitems add column marc text");
      $sti->execute;
  }
--- 139,144 ----
      # Add MARC field to biblioitems db (not used anymore)
      print "Adding marc field to biblioitems table...\n";
!     my $sti=$dbh->prepare("alter table biblioitems 
!       add column marc text");
      $sti->execute;
  }
***************
*** 138,157 ****
      print "Setting type of categorycode in branchcategories to varchar(4),\n 
and making the primary key.\n";
      my $sti=$dbh->prepare("alter table branchcategories change categorycode 
categorycode varchar(4) not null");
!     $sti->execute;
!     $sti=$dbh->prepare("alter table branchcategories add primary key 
(categorycode)");
!     $sti->execute;
  }
  
  unless ($branchcategories{'branchcode'} eq 'varchar(4)') {
!     print "Setting type of branchcode in branchcategories to varchar(4).\n";
!     my $sti=$dbh->prepare("alter table branchcategories change branchcode 
branchcode varchar(4)");
!     $sti->execute;
  }
  
  unless ($branchcategories{'codedescription'} eq 'text') {
      print "Replacing branchholding in branchcategories with codedescription 
text.\n";
!     my $sti=$dbh->prepare("alter table branchcategories change branchholding 
codedescription text");
!     $sti->execute;
  }
  
  $sth->finish;
--- 196,216 ----
      print "Setting type of categorycode in branchcategories to varchar(4),\n 
and making the primary key.\n";
      my $sti=$dbh->prepare("alter table branchcategories change categorycode 
categorycode varchar(4) not null");
!     $sth->execute;
!     $sth=$dbh->prepare("alter table branchcategories add primary key 
(categorycode)");
!     $sth->execute;
  }
  
  unless ($branchcategories{'branchcode'} eq 'varchar(4)') {
!     print "Changing branchcode in branchcategories to categoryname text.\n";
!     my $sth=$dbh->prepare("alter table branchcategories change branchcode 
categoryname text");
!     $sth->execute;
  }
  
  unless ($branchcategories{'codedescription'} eq 'text') {
      print "Replacing branchholding in branchcategories with codedescription 
text.\n";
!     my $sth=$dbh->prepare("alter table branchcategories change branchholding 
codedescription text");
!     $sth->execute;
  }
+ 
  
  $sth->finish;




reply via email to

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