[Koha-cvs] CVS: koha/updater updatedatabase,1.8,1.9

Alan Millar amillar at users.sourceforge.net
Tue May 21 07:47:27 CEST 2002


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

Modified Files:
	updatedatabase 
Log Message:

Modularize table creation, driven by hash instead of redundant code.


Index: updatedatabase
===================================================================
RCS file: /cvsroot/koha/koha/updater/updatedatabase,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** updatedatabase	21 May 2002 05:12:42 -0000	1.8
--- updatedatabase	21 May 2002 05:47:24 -0000	1.9
***************
*** 17,26 ****
  # Koha modules
  use C4::Database;
- #use C4::Catalogue;
- use C4::Acquisitions;
- use C4::Output;
  
! my %tables;
  my %types;
  
  #-------------------
--- 17,58 ----
  # 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))",
+ );
  
  #-------------------
***************
*** 45,104 ****
  $sth->execute;
  while (my ($table) = $sth->fetchrow) {
!     $tables{$table}=1;
  }
  
  # Now add any missing tables
  
! # 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, 
! 	numrecords 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 (
--- 77,99 ----
  $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 (
***************
*** 121,133 ****
  	1, 1, 1)");
      $sti->execute;
- }
- 
- # Create new branchrelations table if it doesnt already exist....
- unless ($tables{'branchrelations'} ) {
-     print "creating branchrelations table\n";
-     my $sth=$dbh->prepare("create table branchrelations (
- 	branchcode varchar(4), 
- 	categorycode varchar(4))");
-     $sth->execute;
  }
  
--- 116,119 ----





More information about the Koha-cvs mailing list