3 # WARNING : this script is intended to be run as is only on a sample DB.
4 # in the sample DB downloadable from sourceforge, the aqbookfund table is full of trash data.
5 # this script drops this table and refill it with correct data.
6 # some tables have strange data too, so primary key cannot be created.
8 # if you want to apply this patch on a running DB :
10 # - remove the lines between <FORPRODDEL> and </FORPRODDEL>
11 # - remove the # before the lines between <FORPRODADD> and </FORPRODADD>
12 # this will cause a primary key to be created if possible on your DB
13 # YOU'VE BEEN WARNING !!!!!
17 # Copyright 2000-2002 Katipo Communications
19 # This file is part of Koha.
21 # Koha is free software; you can redistribute it and/or modify it under the
22 # terms of the GNU General Public License as published by the Free Software
23 # Foundation; either version 2 of the License, or (at your option) any later
26 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
27 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
28 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
30 # You should have received a copy of the GNU General Public License along with
31 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
32 # Suite 330, Boston, MA 02111-1307 USA
41 my ($dbh,$tablename)=@_;
42 if ($tables{$tablename}) {
43 print " - $tablename...\n";
44 my $sti=$dbh->prepare("DROP TABLE $tablename");
51 my ($dbh,$sql_cmd)=@_;
52 my $sti=$dbh->prepare($sql_cmd);
55 print "error : ".$sti->errstr." \n tried to execute : $sql_cmd\n";
64 my $sth=$dbh->prepare("show tables");
66 while (my ($table) = $sth->fetchrow) {
70 print "creating thesaurus...\n";
71 dosql($dbh,"CREATE TABLE bibliothesaurus (code BIGINT not null AUTO_INCREMENT, freelib CHAR (255) not null , stdlib CHAR (255) not null , type CHAR (80) not null , PRIMARY KEY (code), INDEX (freelib),index(stdlib),index(type))");
72 my $sti=$dbh->prepare("select subject from bibliosubject");
75 while ($line =$sti->fetchrow_hashref) {
77 print "$i $line->{'subject'}\n";
78 $sti2=$dbh->prepare("select count(*) as t from bibliothesaurus where freelib=".$dbh->quote($line->{'subject'}));
81 print "error : ".$sti2->errstr." \n tried to execute : $sql_cmd\n";
84 $line2=$sti2->fetchrow_hashref;
85 if ($line2->{'t'} ==0) {
86 dosql($dbh,"insert into bibliothesaurus (freelib,stdlib) values (".$dbh->quote($line->{'subject'}).",".$dbh->quote($line->{'subject'}).")");
88 print "pas ecriture pour : $line->{'subject'}\n";
93 #aqbookfund : the sample db is full of trash data. Delete and recreate
95 print "aqbookfund...";
96 dosql($dbh,"delete from aqbookfund");
97 dosql($dbh,"INSERT INTO aqbookfund VALUES( '5', 'Young Adult Fiction', '3')");
98 dosql($dbh,"INSERT INTO aqbookfund VALUES( '4', 'Fiction', '2')");
99 dosql($dbh,"INSERT INTO aqbookfund VALUES( '2', 'Talking books', '4')");
100 dosql($dbh,"INSERT INTO aqbookfund VALUES( '13', 'Newspapers & journals', '4')");
101 dosql($dbh,"INSERT INTO aqbookfund VALUES( '10', 'Te Ao Maori', '1')");
102 dosql($dbh,"INSERT INTO aqbookfund VALUES( '15', 'CDs, CD Roms, Maps, etc', '4')");
103 dosql($dbh,"INSERT INTO aqbookfund VALUES( '9', 'Junior Fiction', '3')");
104 dosql($dbh,"INSERT INTO aqbookfund VALUES( '7', 'Junior Non-Fiction', '3')");
105 dosql($dbh,"INSERT INTO aqbookfund VALUES( '72', 'Creative NZ', '4')");
106 dosql($dbh,"INSERT INTO aqbookfund VALUES( '11', 'Reference', '1')");
107 dosql($dbh,"INSERT INTO aqbookfund VALUES( '12', 'Videos', '4')");
108 dosql($dbh,"INSERT INTO aqbookfund VALUES( '8', 'Junior Paperback', '3')");
109 dosql($dbh,"INSERT INTO aqbookfund VALUES( '73', 'Large Print Link-up', '2')");
110 dosql($dbh,"INSERT INTO aqbookfund VALUES( '3', 'Large Print', '2')");
111 dosql($dbh,"INSERT INTO aqbookfund VALUES( '71', 'Creative NZ NonFiction', '1')");
112 dosql($dbh,"INSERT INTO aqbookfund VALUES( '6', 'Picture Books', '3')");
113 dosql($dbh,"INSERT INTO aqbookfund VALUES( '14', 'Nga pukapuka Maori', '3')");
114 dosql($dbh,"INSERT INTO aqbookfund VALUES( '80', 'Donations, junior books', '5')");
115 dosql($dbh,"INSERT INTO aqbookfund VALUES( '81', 'Donations, adult books', '5')");
116 dosql($dbh,"INSERT INTO aqbookfund VALUES( '82', 'Donations, magazines', '5')");
117 dosql($dbh,"INSERT INTO aqbookfund VALUES( '83', 'Donations, non books', '5')");
118 dosql($dbh,"INSERT INTO aqbookfund VALUES( '91', 'Vertical File', '5')");
119 dosql($dbh,"INSERT INTO aqbookfund VALUES( '100', 'Loans', '6')");
120 dosql($dbh,"INSERT INTO aqbookfund VALUES( '1', 'Test', '1')");
122 dosql($dbh,"ALTER TABLE aqbookfund DROP PRIMARY KEY, ADD PRIMARY KEY(bookfundid);");
123 print "done\n accountlines...";
124 dosql($dbh,"ALTER TABLE accountlines CHANGE itemnumber itemnumber INT (11) not null;");
125 dosql($dbh,"ALTER TABLE accountlines DROP PRIMARY KEY, ADD PRIMARY KEY(borrowernumber,accountno,itemnumber);");
126 # accountoffset not done (not possible ?)
127 #additionalauthor : not possible (no field useable, 1 index OK)
128 print "done\n aqbooksellers...";
129 dosql($dbh,"ALTER TABLE aqbooksellers CHANGE id id INT (11) not null;");
130 dosql($dbh,"ALTER TABLE aqbooksellers DROP PRIMARY KEY, ADD PRIMARY KEY(id);");
131 print "done\n aqbudget...";
132 dosql($dbh,"ALTER TABLE aqbudget DROP PRIMARY KEY, ADD PRIMARY KEY(bookfundid, bookfundid);");
133 print "done\n aqorderbreakdown...";
134 dosql($dbh,"ALTER TABLE aqorderbreakdown CHANGE ordernumber ordernumber INT (11) not null;");
135 dosql($dbh,"ALTER TABLE aqorderbreakdown CHANGE linenumber linenumber INT (11) not null;");
136 dosql($dbh,"ALTER TABLE aqorderbreakdown CHANGE branchcode branchcode CHAR (4) not null;");
138 # ALTER TABLE aqorderbreakdown DROP PRIMARY KEY, ADD PRIMARY KEY(ordernumber,linenumber,branchcode);");
141 print "done\n biblio/borrowers...";
142 dosql($dbh,"ALTER TABLE aqorderdelivery DROP PRIMARY KEY, ADD PRIMARY KEY(ordernumber);");
143 dosql($dbh,"ALTER TABLE aqorders DROP PRIMARY KEY, ADD PRIMARY KEY(ordernumber);");
144 dosql($dbh,"ALTER TABLE biblio DROP PRIMARY KEY, ADD PRIMARY KEY(biblionumber);");
145 dosql($dbh,"ALTER TABLE biblioitems DROP PRIMARY KEY, ADD PRIMARY KEY(biblionumber, biblioitemnumber)");
146 dosql($dbh,"CREATE INDEX SUBTITLE ON bibliosubtitle (subtitle(80))");
147 dosql($dbh,"ALTER TABLE borexp CHANGE borrowernumber borrowernumber INT (11) not null");
148 dosql($dbh,"ALTER TABLE borexp CHANGE newexp newexp DATE not null");
149 dosql($dbh,"ALTER TABLE branches DROP PRIMARY KEY, ADD PRIMARY KEY(branchcode)");
150 dosql($dbh,"ALTER TABLE deletedbiblio DROP PRIMARY KEY, ADD PRIMARY KEY(biblionumber, biblionumber)");
151 dosql($dbh,"ALTER TABLE deletedbiblioitems DROP PRIMARY KEY, ADD PRIMARY KEY(biblioitemnumber)");
152 dosql($dbh,"ALTER TABLE deletedborrowers DROP PRIMARY KEY, ADD PRIMARY KEY(borrowernumber)");
153 dosql($dbh,"ALTER TABLE deleteditems DROP PRIMARY KEY, ADD PRIMARY KEY(itemnumber)");
154 dosql($dbh,"ALTER TABLE issues CHANGE date_due date_due DATE not null");
156 # ALTER TABLE issues DROP PRIMARY KEY, ADD PRIMARY KEY(borrowernumber,itemnumber,date_due)");
158 print "done\n items...";
159 dosql($dbh,"ALTER TABLE items DROP PRIMARY KEY, ADD PRIMARY KEY(itemnumber)");
160 dosql($dbh,"ALTER TABLE itemsprices CHANGE itemnumber itemnumber INT (11) not null");
161 dosql($dbh,"ALTER TABLE itemsprices DROP PRIMARY KEY, ADD PRIMARY KEY(itemnumber)");
162 dosql($dbh,"ALTER TABLE itemtypes DROP PRIMARY KEY, ADD PRIMARY KEY(itemtype)");
163 print "done\n various...";
164 dosql($dbh,"ALTER TABLE categories DROP PRIMARY KEY, ADD PRIMARY KEY(categorycode)");
165 dosql($dbh,"ALTER TABLE categoryitem DROP PRIMARY KEY, ADD PRIMARY KEY(categorycode,itemtype)");
166 dosql($dbh,"ALTER TABLE currency CHANGE currency currency VARCHAR (10) not null");
167 dosql($dbh,"ALTER TABLE currency CHANGE rate rate FLOAT (7,5) not null");
168 dosql($dbh,"ALTER TABLE currency DROP PRIMARY KEY, ADD PRIMARY KEY(currency)");
169 dosql($dbh,"ALTER TABLE printers CHANGE printername printername CHAR (40) not null");
170 dosql($dbh,"ALTER TABLE printers DROP PRIMARY KEY, ADD PRIMARY KEY(printername)");
172 # ALTER TABLE reserves DROP PRIMARY KEY, ADD PRIMARY KEY(borrowernumber,biblionumber,reservedate)
174 dosql($dbh,"ALTER TABLE stopwords CHANGE word word VARCHAR (255) not null");
175 dosql($dbh,"ALTER TABLE stopwords DROP PRIMARY KEY, ADD PRIMARY KEY(word)");
176 dosql($dbh,"ALTER TABLE systempreferences DROP PRIMARY KEY, ADD PRIMARY KEY(variable)");
177 dosql($dbh,"ALTER TABLE users CHANGE usercode usercode VARCHAR (10) not null");
178 dosql($dbh,"ALTER TABLE users DROP PRIMARY KEY, ADD PRIMARY KEY(usercode)");
180 print "dropping tables...\n";
182 $total += droptable($dbh,'branchcategories');
183 $total += droptable($dbh,'classification');
184 $total += droptable($dbh,'multipart');
185 $total += droptable($dbh,'multivolume');
186 $total += droptable($dbh,'newitems');
187 $total += droptable($dbh,'procedures');
188 $total += droptable($dbh,'publisher');
189 $total += droptable($dbh,'searchstats');
190 $total += droptable($dbh,'serialissues');
191 print " $total tables dropped\n";