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.11,1.12


From: Steve Tonnesen
Subject: [Koha-cvs] CVS: koha/updater updatedatabase,1.11,1.12
Date: Thu, 04 Jul 2002 09:41:08 -0700

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

Modified Files:
        updatedatabase 
Log Message:
Merged changes from rel-1-2.  Abstracted table structure changes by alan.


Index: updatedatabase
===================================================================
RCS file: /cvsroot/koha/koha/updater/updatedatabase,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -r1.11 -r1.12
*** updatedatabase      25 Jun 2002 16:59:27 -0000      1.11
--- updatedatabase      4 Jul 2002 16:41:06 -0000       1.12
***************
*** 1,4 ****
--- 1,6 ----
  #!/usr/bin/perl
  
+ # $Id$
+ 
  # Database Updater
  # This script checks for required updates to the database.  
***************
*** 10,13 ****
--- 12,17 ----
  # - Would also be a good idea to offer to do a backup at this time...
  
+ # NOTE:  If you do something more than once in here, make it table driven.
+ 
  use strict;
  
***************
*** 18,24 ****
  use C4::Database;
  
! my %existingtables;   # tables already in database
! my %types;
! my $table;
  
  #-------------------
--- 22,37 ----
  use C4::Database;
  
! my $debug=0;
! 
! my (
!       $sth, $sti,
!       $query,
!       %existingtables,        # tables already in database
!       %types,
!       $table,
!       $column,
!       $type, $null, $key, $default, $extra,
!       $prefitem,              # preference item in systempreferences table
! );
  
  #-------------------
***************
*** 61,64 ****
--- 74,110 ----
        PRIMARY KEY (websitenumber) )",
  );
+     marcrecorddone=>"( isbn char(40),
+                     issn char(40),
+                     lccn char(40),
+                     controlnumber char(40))",
+     uploadedmarc=>"( id int(11) NOT NULL auto_increment PRIMARY KEY,
+                   marc longblob,
+                   hidden smallint(6) default NULL,
+                   name varchar(255) default NULL)",
+     ethnicity=>"( code varchar(10) NOT NULL default '',
+               name varchar(255) default NULL,
+               PRIMARY KEY  (code)   )",
+ );
+ 
+ my %requirefields=(
+     biblio=>{ 'abstract' => 'text' },
+     deletedbiblio=>{ 'abstract' => 'text' },
+     biblioitems=>{ 'lccn' => 'char(25)',
+               'url' => 'varchar(255)',
+               'marc' => 'text' },
+     deletedbiblioitems=>{ 'lccn' => 'char(25)',
+               'url' => 'varchar(255)',
+               'marc' => 'text' },
+     branchtransfers=>{ 'datearrived' => 'datetime' },
+     statistics=>{'borrowernumber' =>'int(11)'},
+     aqbooksellers=>{'invoicedisc' =>'float(6,4)',
+                    'nocalc' => 'int(11)'},
+ );
+ 
+ # Default system preferences
+ my %defaultprefs=(
+     'autoMemberNum'=> '1',
+     'acquisitions'=> 'simple',
+ );
  
  #-------------------
***************
*** 80,84 ****
  
  # Collect all tables into a list
! my $sth=$dbh->prepare("show tables");
  $sth->execute;
  while (my ($table) = $sth->fetchrow) {
--- 126,130 ----
  
  # Collect all tables into a list
! $sth=$dbh->prepare("show tables");
  $sth->execute;
  while (my ($table) = $sth->fetchrow) {
***************
*** 88,91 ****
--- 134,138 ----
  # Now add any missing tables
  foreach $table ( keys %requiretables ) {
+     print "Checking $table table...\n" if $debug;
      unless ($existingtables{$table} ) {
        print "Adding $table table...\n";
***************
*** 99,103 ****
      } # unless exists
  } # foreach
- exit;
  
  unless ($existingtables{'z3950servers'}) {
--- 146,149 ----
***************
*** 127,154 ****
  # Columns
  
  
! # 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
!     print "Adding lccn field to biblioitems table...\n";
!     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)
!     print "Adding marc field to biblioitems table...\n";
!     my $sti=$dbh->prepare("alter table biblioitems 
!       add column marc text");
!     $sti->execute;
! }
! 
! # Get list of columns from biblioitems table
  my %itemtypes;
  
--- 173,204 ----
  # Columns
  
+ foreach $table ( keys %requirefields ) {
+     print "Check table $table\n" if $debug;
+     $sth=$dbh->prepare("show columns from $table");
+     $sth->execute();
+     undef %types;
+     while ( ($column, $type, $null, $key, $default, $extra) 
+               = $sth->fetchrow) {
+         $types{$column}=$type;
+     } # while 
+     foreach $column ( keys %{ $requirefields{$table} } )  {
+       print "  Check column $column\n" if $debug;
+       if ( ! $types{$column} ) {
+           # column doesn't exist
+           print "Adding $column field to $table table...\n";
+           $query="alter table $table
+               add column $column " . $requirefields{$table}->{$column} ;
+           print "Execute: $query\n" if $debug;
+           my $sti=$dbh->prepare($query);
+           $sti->execute;
+             if ($sti->err) {
+                     print "**Error : $sti->errstr \n";
+                     $sti->finish;
+             } # if error
+       } # if column
+     } # foreach column
+ } # foreach table
  
! # Get list of columns from items table
  my %itemtypes;
  
***************
*** 207,211 ****
  }
  
! 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");
--- 257,261 ----
  }
  
! unless ($branchcategories{'categoryname'} eq 'text') {
      print "Changing branchcode in branchcategories to categoryname text.\n";
      my $sth=$dbh->prepare("alter table branchcategories change branchcode 
categoryname text");
***************
*** 220,223 ****
--- 270,298 ----
  
  
+ # Populate systempreferences if it is empty
+ 
+ foreach $prefitem ( keys %defaultprefs ) {
+     $sth=$dbh->prepare("select value 
+       from systempreferences 
+       where variable=?");
+     $sth->execute($prefitem);
+     unless ($sth->rows) {
+       print "Adding system preference item $prefitem with value " .
+               $defaultprefs{$prefitem} ."\n";
+         $sti=$dbh->prepare("
+         insert into systempreferences (variable, value) 
+         values (?,?)");
+         $sti->execute($prefitem,$defaultprefs{$prefitem});
+     } # unless
+ } # foreach
+ 
+ 
  $sth->finish;
  $dbh->disconnect;
+ 
+ exit;
+ 
+ # $Log$
+ # Revision 1.12  2002/07/04 16:41:06  tonnesen
+ # Merged changes from rel-1-2.  Abstracted table structure changes by alan.
+ #




reply via email to

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