Bug 5356: delivery place and billing place centralised in basket management
[koha.git] / installer / data / mysql / kohastructure.sql
1 -- MySQL dump 10.9
2 --
3 -- Host: localhost    Database: koha30test
4 -- ------------------------------------------------------
5 -- Server version       4.1.22
6
7 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
8 /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
9 /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
10 /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
11 /*!40101 SET NAMES utf8 */;
12 /*!40103 SET TIME_ZONE='+00:00' */;
13 /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
14 /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
15 /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
16 /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
17
18 --
19 -- Table structure for table `auth_header`
20 --
21
22 DROP TABLE IF EXISTS `auth_header`;
23 CREATE TABLE `auth_header` (
24   `authid` bigint(20) unsigned NOT NULL auto_increment,
25   `authtypecode` varchar(10) NOT NULL default '',
26   `datecreated` date default NULL,
27   `datemodified` date default NULL,
28   `origincode` varchar(20) default NULL,
29   `authtrees` mediumtext,
30   `marc` blob,
31   `linkid` bigint(20) default NULL,
32   `marcxml` longtext NOT NULL,
33   PRIMARY KEY  (`authid`),
34   KEY `origincode` (`origincode`)
35 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
36
37 --
38 -- Table structure for table `auth_subfield_structure`
39 --
40
41 DROP TABLE IF EXISTS `auth_subfield_structure`;
42 CREATE TABLE `auth_subfield_structure` (
43   `authtypecode` varchar(10) NOT NULL default '',
44   `tagfield` varchar(3) NOT NULL default '',
45   `tagsubfield` varchar(1) NOT NULL default '',
46   `liblibrarian` varchar(255) NOT NULL default '',
47   `libopac` varchar(255) NOT NULL default '',
48   `repeatable` tinyint(4) NOT NULL default 0,
49   `mandatory` tinyint(4) NOT NULL default 0,
50   `tab` tinyint(1) default NULL,
51   `authorised_value` varchar(10) default NULL,
52   `value_builder` varchar(80) default NULL,
53   `seealso` varchar(255) default NULL,
54   `isurl` tinyint(1) default NULL,
55   `hidden` tinyint(3) NOT NULL default 0,
56   `linkid` tinyint(1) NOT NULL default 0,
57   `kohafield` varchar(45) NULL default '',
58   `frameworkcode` varchar(10) NOT NULL default '',
59   PRIMARY KEY  (`authtypecode`,`tagfield`,`tagsubfield`),
60   KEY `tab` (`authtypecode`,`tab`)
61 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
62
63 --
64 -- Table structure for table `auth_tag_structure`
65 --
66
67 DROP TABLE IF EXISTS `auth_tag_structure`;
68 CREATE TABLE `auth_tag_structure` (
69   `authtypecode` varchar(10) NOT NULL default '',
70   `tagfield` varchar(3) NOT NULL default '',
71   `liblibrarian` varchar(255) NOT NULL default '',
72   `libopac` varchar(255) NOT NULL default '',
73   `repeatable` tinyint(4) NOT NULL default 0,
74   `mandatory` tinyint(4) NOT NULL default 0,
75   `authorised_value` varchar(10) default NULL,
76   PRIMARY KEY  (`authtypecode`,`tagfield`),
77   CONSTRAINT `auth_tag_structure_ibfk_1` FOREIGN KEY (`authtypecode`) REFERENCES `auth_types` (`authtypecode`) ON DELETE CASCADE ON UPDATE CASCADE
78 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
79
80 --
81 -- Table structure for table `auth_types`
82 --
83
84 DROP TABLE IF EXISTS `auth_types`;
85 CREATE TABLE `auth_types` (
86   `authtypecode` varchar(10) NOT NULL default '',
87   `authtypetext` varchar(255) NOT NULL default '',
88   `auth_tag_to_report` varchar(3) NOT NULL default '',
89   `summary` mediumtext NOT NULL,
90   PRIMARY KEY  (`authtypecode`)
91 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
92
93 --
94 -- Table structure for table `authorised_values`
95 --
96
97 DROP TABLE IF EXISTS `authorised_values`;
98 CREATE TABLE `authorised_values` ( -- stores values for authorized values categories and values
99   `id` int(11) NOT NULL auto_increment, -- unique key, used to identify the authorized value
100   `category` varchar(16) NOT NULL default '', -- key used to identify the authorized value category
101   `authorised_value` varchar(80) NOT NULL default '', -- code use to identify the authorized value
102   `lib` varchar(200) default NULL, -- authorized value description as printed in the staff client
103   `lib_opac` varchar(200) default NULL, -- authorized value description as printed in the OPAC
104   `imageurl` varchar(200) default NULL, -- authorized value URL
105   PRIMARY KEY  (`id`),
106   KEY `name` (`category`),
107   KEY `lib` (`lib`),
108   KEY `auth_value_idx` (`authorised_value`)
109 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
110
111 --
112 -- Table structure for table `biblio`
113 --
114
115 DROP TABLE IF EXISTS `biblio`;
116 CREATE TABLE `biblio` ( -- table that stores bibliographic information
117   `biblionumber` int(11) NOT NULL auto_increment, -- unique identifier assigned to each bibliographic record
118   `frameworkcode` varchar(4) NOT NULL default '', -- foriegn key from the biblio_framework table to identify which framework was used in cataloging this record
119   `author` mediumtext, -- statement of responsibility from MARC record (100$a in MARC21)
120   `title` mediumtext, -- title (without the subtitle) from the MARC record (245$a in MARC21)
121   `unititle` mediumtext, -- uniform title (without the subtitle) from the MARC record (240$a in MARC21)
122   `notes` mediumtext, -- values from the general notes field in the MARC record (500$a in MARC21) split by bar (|)
123   `serial` tinyint(1) default NULL, -- foreign key, linking to the subscriptionid in the serial table
124   `seriestitle` mediumtext,
125   `copyrightdate` smallint(6) default NULL, -- publication or copyright date from the MARC record
126   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- date and time this record was last touched
127   `datecreated` DATE NOT NULL, -- the date this record was added to Koha
128   `abstract` mediumtext, -- summary from the MARC record (520$a in MARC21)
129   PRIMARY KEY  (`biblionumber`),
130   KEY `blbnoidx` (`biblionumber`)
131 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
132
133 --
134 -- Table structure for table `biblio_framework`
135 --
136
137 DROP TABLE IF EXISTS `biblio_framework`;
138 CREATE TABLE `biblio_framework` ( -- information about MARC frameworks
139   `frameworkcode` varchar(4) NOT NULL default '', -- the unique code assigned to the framework
140   `frameworktext` varchar(255) NOT NULL default '', -- the description/name given to the framework
141   PRIMARY KEY  (`frameworkcode`)
142 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
143
144 --
145 -- Table structure for table `biblioitems`
146 --
147
148 DROP TABLE IF EXISTS `biblioitems`;
149 CREATE TABLE `biblioitems` ( -- information related to bibliographic records in Koha
150   `biblioitemnumber` int(11) NOT NULL auto_increment, -- primary key, unique identifier assigned by Koha
151   `biblionumber` int(11) NOT NULL default 0, -- foreign key linking this table to the biblio table
152   `volume` mediumtext,
153   `number` mediumtext,
154   `itemtype` varchar(10) default NULL, -- biblio level item type (MARC21 942$c)
155   `isbn` varchar(30) default NULL, -- ISBN (MARC21 020$a)
156   `issn` varchar(9) default NULL, -- ISSN (MARC21 022$a)
157   `ean` varchar(13) default NULL,
158   `publicationyear` text,
159   `publishercode` varchar(255) default NULL, -- publisher (MARC21 260$b)
160   `volumedate` date default NULL,
161   `volumedesc` text, -- volume information (MARC21 362$a)
162   `collectiontitle` mediumtext default NULL,
163   `collectionissn` text default NULL,
164   `collectionvolume` mediumtext default NULL,
165   `editionstatement` text default NULL,
166   `editionresponsibility` text default NULL,
167   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
168   `illus` varchar(255) default NULL, -- illustrations (MARC21 300$b)
169   `pages` varchar(255) default NULL, -- number of pages (MARC21 300$c)
170   `notes` mediumtext,
171   `size` varchar(255) default NULL, -- material size (MARC21 300$c)
172   `place` varchar(255) default NULL, -- publication place (MARC21 260$a)
173   `lccn` varchar(25) default NULL, -- library of congress control number (MARC21 010$a)
174   `marc` longblob, -- full bibliographic MARC record
175   `url` varchar(255) default NULL, -- url (MARC21 856$u)
176   `cn_source` varchar(10) default NULL, -- classification source (MARC21 942$2)
177   `cn_class` varchar(30) default NULL,
178   `cn_item` varchar(10) default NULL,
179   `cn_suffix` varchar(10) default NULL,
180   `cn_sort` varchar(30) default NULL,
181   `agerestriction` varchar(255) default NULL,
182   `totalissues` int(10),
183   `marcxml` longtext NOT NULL, -- full bibliographic MARC record in MARCXML
184   PRIMARY KEY  (`biblioitemnumber`),
185   KEY `bibinoidx` (`biblioitemnumber`),
186   KEY `bibnoidx` (`biblionumber`),
187   KEY `isbn` (`isbn`),
188   KEY `issn` (`issn`),
189   KEY `publishercode` (`publishercode`),
190   CONSTRAINT `biblioitems_ibfk_1` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
191 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
192
193 --
194 -- Table structure for table `borrowers`
195 --
196
197 DROP TABLE IF EXISTS `borrowers`;
198 CREATE TABLE `borrowers` ( -- this table includes information about your patrons/borrowers/members
199   `borrowernumber` int(11) NOT NULL auto_increment, -- primary key, Koha assigned ID number for patrons/borrowers
200   `cardnumber` varchar(16) default NULL, -- unique key, library assigned ID number for patrons/borrowers
201   `surname` mediumtext NOT NULL, -- patron/borrower's last name (surname)
202   `firstname` text, -- patron/borrower's first name
203   `title` mediumtext, -- patron/borrower's title, for example: Mr. or Mrs.
204   `othernames` mediumtext, -- any other names associated with the patron/borrower
205   `initials` text, -- initials for your patron/borrower
206   `streetnumber` varchar(10) default NULL, -- the house number for your patron/borrower's primary address
207   `streettype` varchar(50) default NULL, -- the street type (Rd., Blvd, etc) for your patron/borrower's primary address
208   `address` mediumtext NOT NULL, -- the first address line for your patron/borrower's primary address
209   `address2` text, -- the second address line for your patron/borrower's primary address
210   `city` mediumtext NOT NULL, -- the city or town for your patron/borrower's primary address
211   `state` text default NULL, -- the state or province for your patron/borrower's primary address
212   `zipcode` varchar(25) default NULL, -- the zip or postal code for your patron/borrower's primary address
213   `country` text, -- the country for your patron/borrower's primary address
214   `email` mediumtext, -- the primary email address for your patron/borrower's primary address
215   `phone` text, -- the primary phone number for your patron/borrower's primary address
216   `mobile` varchar(50) default NULL, -- the other phone number for your patron/borrower's primary address
217   `fax` mediumtext, -- the fax number for your patron/borrower's primary address
218   `emailpro` text, -- the secondary email addres for your patron/borrower's primary address
219   `phonepro` text, -- the secondary phone number for your patron/borrower's primary address
220   `B_streetnumber` varchar(10) default NULL, -- the house number for your patron/borrower's alternate address
221   `B_streettype` varchar(50) default NULL, -- the street type (Rd., Blvd, etc) for your patron/borrower's alternate address
222   `B_address` varchar(100) default NULL, -- the first address line for your patron/borrower's alternate address
223   `B_address2` text default NULL, -- the second address line for your patron/borrower's alternate address
224   `B_city` mediumtext, -- the city or town for your patron/borrower's alternate address
225   `B_state` text default NULL, -- the state for your patron/borrower's alternate address
226   `B_zipcode` varchar(25) default NULL, -- the zip or postal code for your patron/borrower's alternate address
227   `B_country` text, -- the country for your patron/borrower's alternate address
228   `B_email` text, -- the patron/borrower's alternate email address
229   `B_phone` mediumtext, -- the patron/borrower's alternate phone number
230   `dateofbirth` date default NULL, -- the patron/borrower's date of birth (YYYY-MM-DD)
231   `branchcode` varchar(10) NOT NULL default '', -- foreign key from the branches table, includes the code of the patron/borrower's home branch
232   `categorycode` varchar(10) NOT NULL default '', -- foreign key from the categories table, includes the code of the patron category
233   `dateenrolled` date default NULL, -- date the patron was added to Koha (YYYY-MM-DD)
234   `dateexpiry` date default NULL, -- date the patron/borrower's card is set to expire (YYYY-MM-DD)
235   `gonenoaddress` tinyint(1) default NULL, -- set to 1 for yes and 0 for no, flag to note that library marked this patron/borrower as having an unconfirmed address
236   `lost` tinyint(1) default NULL, -- set to 1 for yes and 0 for no, flag to note that library marked this patron/borrower as having lost their card
237   `debarred` date default NULL, -- until this date the patron can only check-in (no loans, no holds, etc.), is a fine based on days instead of money (YYY-MM-DD)
238   `debarredcomment` VARCHAR(255) DEFAULT NULL, -- comment on the stop of the patron
239   `contactname` mediumtext, -- used for children and profesionals to include surname or last name of guarentor or organization name
240   `contactfirstname` text, -- used for children to include first name of guarentor
241   `contacttitle` text, -- used for children to include title (Mr., Mrs., etc) of guarentor
242   `guarantorid` int(11) default NULL, -- borrowernumber used for children or professionals to link them to guarentors or organizations
243   `borrowernotes` mediumtext, -- a note on the patron/borroewr's account that is only visible in the staff client
244   `relationship` varchar(100) default NULL, -- used for children to include the relationship to their guarentor
245   `ethnicity` varchar(50) default NULL, -- unused in Koha
246   `ethnotes` varchar(255) default NULL, -- unused in Koha
247   `sex` varchar(1) default NULL, -- patron/borrower's gender
248   `password` varchar(30) default NULL, -- patron/borrower's encrypted password
249   `flags` int(11) default NULL, -- will include a number associated with the staff member's permissions
250   `userid` varchar(75) default NULL, -- patron/borrower's opac and/or staff client log in
251   `opacnote` mediumtext, -- a note on the patron/borrower's account that is visible in the OPAC and staff client
252   `contactnote` varchar(255) default NULL, -- a note related to the patron/borrower's alternate address
253   `sort1` varchar(80) default NULL, -- a field that can be used for any information unique to the library
254   `sort2` varchar(80) default NULL, -- a field that can be used for any information unique to the library
255   `altcontactfirstname` varchar(255) default NULL, -- first name of alternate contact for the patron/borrower
256   `altcontactsurname` varchar(255) default NULL, -- surname or last name of the alternate contact for the patron/borrower
257   `altcontactaddress1` varchar(255) default NULL, -- the first address line for the alternate contact for the patron/borrower
258   `altcontactaddress2` varchar(255) default NULL, -- the second address line for the alternate contact for the patron/borrower
259   `altcontactaddress3` varchar(255) default NULL, -- the third address line for the alternate contact for the patron/borrower
260   `altcontactstate` text default NULL, -- the city and state for the alternate contact for the patron/borrower
261   `altcontactzipcode` varchar(50) default NULL, -- the zipcode for the alternate contact for the patron/borrower
262   `altcontactcountry` text default NULL, -- the country for the alternate contact for the patron/borrower
263   `altcontactphone` varchar(50) default NULL, -- the phone number for the alternate contact for the patron/borrower
264   `smsalertnumber` varchar(50) default NULL, -- the mobile phone number where the patron/borrower would like to receive notices (if SNS turned on)
265   `privacy` integer(11) DEFAULT '1' NOT NULL, -- patron/borrower's privacy settings related to their reading history
266   UNIQUE KEY `cardnumber` (`cardnumber`),
267   PRIMARY KEY `borrowernumber` (`borrowernumber`),
268   KEY `categorycode` (`categorycode`),
269   KEY `branchcode` (`branchcode`),
270   KEY `userid` (`userid`),
271   KEY `guarantorid` (`guarantorid`),
272   CONSTRAINT `borrowers_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`),
273   CONSTRAINT `borrowers_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
274 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
275
276 --
277 -- Table structure for table `borrower_attribute_types`
278 --
279
280 DROP TABLE IF EXISTS `borrower_attribute_types`;
281 CREATE TABLE `borrower_attribute_types` ( -- definitions for custom patron fields known as extended patron attributes
282   `code` varchar(10) NOT NULL, -- unique key used to identify each custom field
283   `description` varchar(255) NOT NULL, -- description for each custom field
284   `repeatable` tinyint(1) NOT NULL default 0, -- defines whether one patron/borrower can have multiple values for this custom field  (1 for yes, 0 for no)
285   `unique_id` tinyint(1) NOT NULL default 0, -- defines if this value needs to be unique (1 for yes, 0 for no)
286   `opac_display` tinyint(1) NOT NULL default 0, -- defines if this field is visible to patrons on their account in the OPAC (1 for yes, 0 for no)
287   `password_allowed` tinyint(1) NOT NULL default 0, -- defines if it is possible to associate a password with this custom field (1 for yes, 0 for no)
288   `staff_searchable` tinyint(1) NOT NULL default 0, -- defines if this field is searchable via the patron search in the staff client (1 for yes, 0 for no)
289   `authorised_value_category` varchar(10) default NULL, -- foreign key from authorised_values that links this custom field to an authorized value category
290   `display_checkout` tinyint(1) NOT NULL default 0,-- defines if this field displays in checkout screens
291   `category_code` VARCHAR(10) NULL DEFAULT NULL,-- defines a category for an attribute_type
292   `class` VARCHAR(255) NOT NULL DEFAULT '',-- defines a class for an attribute_type
293   PRIMARY KEY  (`code`),
294   KEY `auth_val_cat_idx` (`authorised_value_category`)
295 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
296
297 --
298 -- Table structure for table `borrower_attributes`
299 --
300
301 DROP TABLE IF EXISTS `borrower_attributes`;
302 CREATE TABLE `borrower_attributes` ( -- values of custom patron fields known as extended patron attributes linked to patrons/borrowers
303   `borrowernumber` int(11) NOT NULL, -- foreign key from the borrowers table, defines which patron/borrower has this attribute
304   `code` varchar(10) NOT NULL, -- foreign key from the borrower_attribute_types table, defines which custom field this value was entered for
305   `attribute` varchar(255) default NULL, -- custom patron field value
306   `password` varchar(64) default NULL, -- password associated with this field
307   KEY `borrowernumber` (`borrowernumber`),
308   KEY `code_attribute` (`code`, `attribute`),
309   CONSTRAINT `borrower_attributes_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
310     ON DELETE CASCADE ON UPDATE CASCADE,
311   CONSTRAINT `borrower_attributes_ibfk_2` FOREIGN KEY (`code`) REFERENCES `borrower_attribute_types` (`code`)
312     ON DELETE CASCADE ON UPDATE CASCADE
313 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
314
315 --
316 -- Table structure for table `branch_item_rules`
317 --
318
319 DROP TABLE IF EXISTS `branch_item_rules`;
320 CREATE TABLE `branch_item_rules` ( -- information entered in the circulation and fine rules under 'Holds policy by item type'
321   `branchcode` varchar(10) NOT NULL, -- the branch this rule is for (branches.branchcode)
322   `itemtype` varchar(10) NOT NULL, -- the item type this rule applies to (items.itype)
323   `holdallowed` tinyint(1) default NULL, -- the number of holds allowed
324   `returnbranch` varchar(15) default NULL, -- the branch the item returns to (homebranch, holdingbranch, noreturn)
325   PRIMARY KEY  (`itemtype`,`branchcode`),
326   KEY `branch_item_rules_ibfk_2` (`branchcode`),
327   CONSTRAINT `branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`)
328     ON DELETE CASCADE ON UPDATE CASCADE,
329   CONSTRAINT `branch_item_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
330     ON DELETE CASCADE ON UPDATE CASCADE
331 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
332
333 --
334 -- Table structure for table `branchcategories`
335 --
336
337 DROP TABLE IF EXISTS `branchcategories`;
338 CREATE TABLE `branchcategories` ( -- information related to library/branch groups
339   `categorycode` varchar(10) NOT NULL default '', -- unique identifier for the library/branch group
340   `categoryname` varchar(32), -- name of the library/branch group
341   `codedescription` mediumtext, -- longer description of the library/branch group
342   `categorytype` varchar(16), -- says whether this is a search group or a properties group
343   PRIMARY KEY  (`categorycode`)
344 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
345
346 --
347 -- Table structure for table `branches`
348 --
349
350 DROP TABLE IF EXISTS `branches`;
351 CREATE TABLE `branches` ( -- information about your libraries or branches are stored here
352   `branchcode` varchar(10) NOT NULL default '', -- a unique key assigned to each branch
353   `branchname` mediumtext NOT NULL, -- the name of your library or branch
354   `branchaddress1` mediumtext, -- the first address line of for your library or branch
355   `branchaddress2` mediumtext, -- the second address line of for your library or branch
356   `branchaddress3` mediumtext, -- the third address line of for your library or branch
357   `branchzip` varchar(25) default NULL, -- the zip or postal code for your library or branch
358   `branchcity` mediumtext, -- the city or province for your library or branch
359   `branchstate` mediumtext, -- the state for your library or branch
360   `branchcountry` text, -- the county for your library or branch
361   `branchphone` mediumtext, -- the primary phone for your library or branch
362   `branchfax` mediumtext, -- the fax number for your library or branch
363   `branchemail` mediumtext, -- the primary email address for your library or branch
364   `branchurl` mediumtext, -- the URL for your library or branch's website
365   `issuing` tinyint(4) default NULL, -- unused in Koha
366   `branchip` varchar(15) default NULL, -- the IP address for your library or branch
367   `branchprinter` varchar(100) default NULL, -- unused in Koha
368   `branchnotes` mediumtext, -- notes related to your library or branch
369   opac_info text, -- HTML that displays in OPAC
370   PRIMARY KEY (`branchcode`)
371 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
372
373 --
374 -- Table structure for table `branchrelations`
375 --
376
377 DROP TABLE IF EXISTS `branchrelations`;
378 CREATE TABLE `branchrelations` ( -- this table links libraries/branches to groups
379   `branchcode` varchar(10) NOT NULL default '', -- foreign key from the branches table to identify the branch
380   `categorycode` varchar(10) NOT NULL default '', -- foreign key from the branchcategories table to identify the group
381   PRIMARY KEY  (`branchcode`,`categorycode`),
382   KEY `branchcode` (`branchcode`),
383   KEY `categorycode` (`categorycode`),
384   CONSTRAINT `branchrelations_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE,
385   CONSTRAINT `branchrelations_ibfk_2` FOREIGN KEY (`categorycode`) REFERENCES `branchcategories` (`categorycode`) ON DELETE CASCADE ON UPDATE CASCADE
386 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
387
388 --
389 -- Table structure for table `branchtransfers`
390 --
391
392 DROP TABLE IF EXISTS `branchtransfers`;
393 CREATE TABLE `branchtransfers` ( -- information for items that are in transit between branches
394   `itemnumber` int(11) NOT NULL default 0, -- the itemnumber that it is in transit (items.itemnumber)
395   `datesent` datetime default NULL, -- the date the transfer was initialized
396   `frombranch` varchar(10) NOT NULL default '', -- the branch the transfer is coming from
397   `datearrived` datetime default NULL, -- the date the transfer arrived at its destination
398   `tobranch` varchar(10) NOT NULL default '', -- the branch the transfer was going to
399   `comments` mediumtext, -- any comments related to the transfer
400   KEY `frombranch` (`frombranch`),
401   KEY `tobranch` (`tobranch`),
402   KEY `itemnumber` (`itemnumber`),
403   CONSTRAINT `branchtransfers_ibfk_1` FOREIGN KEY (`frombranch`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE,
404   CONSTRAINT `branchtransfers_ibfk_2` FOREIGN KEY (`tobranch`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE,
405   CONSTRAINT `branchtransfers_ibfk_3` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE
406 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
407
408
409 --
410 -- Table structure for table `browser`
411 --
412 DROP TABLE IF EXISTS `browser`;
413 CREATE TABLE `browser` (
414   `level` int(11) NOT NULL,
415   `classification` varchar(20) NOT NULL,
416   `description` varchar(255) NOT NULL,
417   `number` bigint(20) NOT NULL,
418   `endnode` tinyint(4) NOT NULL
419 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
420
421 --
422 -- Table structure for table `categories`
423 --
424
425 DROP TABLE IF EXISTS `categories`;
426 CREATE TABLE `categories` ( -- this table shows information related to Koha patron categories
427   `categorycode` varchar(10) NOT NULL default '', -- unique primary key used to idenfity the patron category
428   `description` mediumtext, -- description of the patron category
429   `enrolmentperiod` smallint(6) default NULL, -- number of months the patron is enrolled for (will be NULL if enrolmentperioddate is set)
430   `enrolmentperioddate` DATE NULL DEFAULT NULL, -- date the patron is enrolled until (will be NULL if enrolmentperiod is set)
431   `upperagelimit` smallint(6) default NULL, -- age limit for the patron
432   `dateofbirthrequired` tinyint(1) default NULL,
433   `finetype` varchar(30) default NULL, -- unused in Koha
434   `bulk` tinyint(1) default NULL,
435   `enrolmentfee` decimal(28,6) default NULL, -- enrollment fee for the patron
436   `overduenoticerequired` tinyint(1) default NULL, -- are overdue notices sent to this patron category (1 for yes, 0 for no)
437   `issuelimit` smallint(6) default NULL, -- unused in Koha
438   `reservefee` decimal(28,6) default NULL, -- cost to place holds
439   `hidelostitems` tinyint(1) NOT NULL default '0', -- are lost items shown to this category (1 for yes, 0 for no)
440   `category_type` varchar(1) NOT NULL default 'A', -- type of Koha patron (Adult, Child, Professional, Organizational, Statistical, Staff)
441   PRIMARY KEY  (`categorycode`),
442   UNIQUE KEY `categorycode` (`categorycode`)
443 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
444
445 --
446 -- Table: collections
447 --
448 DROP TABLE IF EXISTS collections;
449 CREATE TABLE collections (
450   colId integer(11) NOT NULL auto_increment,
451   colTitle varchar(100) NOT NULL DEFAULT '',
452   colDesc text NOT NULL,
453   colBranchcode varchar(4) DEFAULT NULL comment 'branchcode for branch where item should be held.',
454   PRIMARY KEY (colId)
455 ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8;
456
457 --
458 -- Table: collections_tracking
459 --
460 DROP TABLE IF EXISTS collections_tracking;
461 CREATE TABLE collections_tracking (
462   ctId integer(11) NOT NULL auto_increment,
463   colId integer(11) NOT NULL DEFAULT 0 comment 'collections.colId',
464   itemnumber integer(11) NOT NULL DEFAULT 0 comment 'items.itemnumber',
465   PRIMARY KEY (ctId)
466 ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8;
467
468 --
469 -- Table structure for table `borrower_branch_circ_rules`
470 --
471
472 DROP TABLE IF EXISTS `branch_borrower_circ_rules`;
473 CREATE TABLE `branch_borrower_circ_rules` ( -- includes default circulation rules for patron categories found under "Checkout limit by patron category"
474   `branchcode` VARCHAR(10) NOT NULL, -- the branch this rule applies to (branches.branchcode)
475   `categorycode` VARCHAR(10) NOT NULL, -- the patron category this rule applies to (categories.categorycode)
476   `maxissueqty` int(4) default NULL, -- the maximum number of checkouts this patron category can have at this branch
477   PRIMARY KEY (`categorycode`, `branchcode`),
478   CONSTRAINT `branch_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
479     ON DELETE CASCADE ON UPDATE CASCADE,
480   CONSTRAINT `branch_borrower_circ_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
481     ON DELETE CASCADE ON UPDATE CASCADE
482 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
483
484 --
485 -- Table structure for table `default_borrower_circ_rules`
486 --
487
488 DROP TABLE IF EXISTS `default_borrower_circ_rules`;
489 CREATE TABLE `default_borrower_circ_rules` ( -- default checkout rules found under "Default checkout, hold and return policy"
490   `categorycode` VARCHAR(10) NOT NULL, -- patron category this rul
491   `maxissueqty` int(4) default NULL,
492   PRIMARY KEY (`categorycode`),
493   CONSTRAINT `borrower_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
494     ON DELETE CASCADE ON UPDATE CASCADE
495 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
496
497 --
498 -- Table structure for table `default_branch_circ_rules`
499 --
500
501 DROP TABLE IF EXISTS `default_branch_circ_rules`;
502 CREATE TABLE `default_branch_circ_rules` (
503   `branchcode` VARCHAR(10) NOT NULL,
504   `maxissueqty` int(4) default NULL,
505   `holdallowed` tinyint(1) default NULL,
506   `returnbranch` varchar(15) default NULL,
507   PRIMARY KEY (`branchcode`),
508   CONSTRAINT `default_branch_circ_rules_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
509     ON DELETE CASCADE ON UPDATE CASCADE
510 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
511
512 --
513 -- Table structure for table `default_branch_item_rules`
514 --
515 DROP TABLE IF EXISTS `default_branch_item_rules`;
516 CREATE TABLE `default_branch_item_rules` (
517   `itemtype` varchar(10) NOT NULL,
518   `holdallowed` tinyint(1) default NULL,
519   `returnbranch` varchar(15) default NULL,
520   PRIMARY KEY  (`itemtype`),
521   CONSTRAINT `default_branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`)
522     ON DELETE CASCADE ON UPDATE CASCADE
523 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
524
525 --
526 -- Table structure for table `default_circ_rules`
527 --
528
529 DROP TABLE IF EXISTS `default_circ_rules`;
530 CREATE TABLE `default_circ_rules` (
531     `singleton` enum('singleton') NOT NULL default 'singleton',
532     `maxissueqty` int(4) default NULL,
533     `holdallowed` int(1) default NULL,
534     `returnbranch` varchar(15) default NULL,
535     PRIMARY KEY (`singleton`)
536 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
537
538 --
539 -- Table structure for table `cities`
540 --
541
542 DROP TABLE IF EXISTS `cities`;
543 CREATE TABLE `cities` ( -- authorized values for cities/states/countries to choose when adding/editing a patron/borrower
544   `cityid` int(11) NOT NULL auto_increment, -- unique identifier added by Koha
545   `city_name` varchar(100) NOT NULL default '', -- name of the city
546   `city_state` VARCHAR( 100 ) NULL DEFAULT NULL, -- name of the state/province
547   `city_country` VARCHAR( 100 ) NULL DEFAULT NULL, -- name of the country
548   `city_zipcode` varchar(20) default NULL, -- zip or postal code
549   PRIMARY KEY  (`cityid`)
550 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
551
552 --
553 -- Table structure for table `class_sort_rules`
554 --
555
556 DROP TABLE IF EXISTS `class_sort_rules`;
557 CREATE TABLE `class_sort_rules` (
558   `class_sort_rule` varchar(10) NOT NULL default '',
559   `description` mediumtext,
560   `sort_routine` varchar(30) NOT NULL default '',
561   PRIMARY KEY (`class_sort_rule`),
562   UNIQUE KEY `class_sort_rule_idx` (`class_sort_rule`)
563 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
564
565 --
566 -- Table structure for table `class_sources`
567 --
568
569 DROP TABLE IF EXISTS `class_sources`;
570 CREATE TABLE `class_sources` (
571   `cn_source` varchar(10) NOT NULL default '',
572   `description` mediumtext,
573   `used` tinyint(4) NOT NULL default 0,
574   `class_sort_rule` varchar(10) NOT NULL default '',
575   PRIMARY KEY (`cn_source`),
576   UNIQUE KEY `cn_source_idx` (`cn_source`),
577   KEY `used_idx` (`used`),
578   CONSTRAINT `class_source_ibfk_1` FOREIGN KEY (`class_sort_rule`) REFERENCES `class_sort_rules` (`class_sort_rule`)
579 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
580
581 --
582 -- Table structure for table `currency`
583 --
584
585 DROP TABLE IF EXISTS `currency`;
586 CREATE TABLE `currency` (
587   `currency` varchar(10) NOT NULL default '',
588   `symbol` varchar(5) default NULL,
589   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
590   `rate` float(15,5) default NULL,
591   `active` tinyint(1) default NULL,
592   PRIMARY KEY  (`currency`)
593 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
594
595 --
596 -- Table structure for table `deletedbiblio`
597 --
598
599 DROP TABLE IF EXISTS `deletedbiblio`;
600 CREATE TABLE `deletedbiblio` ( -- stores information about bibliographic records that have been deleted
601   `biblionumber` int(11) NOT NULL auto_increment, -- unique identifier assigned to each bibliographic record
602   `frameworkcode` varchar(4) NOT NULL default '', -- foriegn key from the biblio_framework table to identify which framework was used in cataloging this record
603   `author` mediumtext, -- statement of responsibility from MARC record (100$a in MARC21)
604   `title` mediumtext, -- title (without the subtitle) from the MARC record (245$a in MARC21)
605   `unititle` mediumtext, -- uniform title (without the subtitle) from the MARC record (240$a in MARC21)
606   `notes` mediumtext, -- values from the general notes field in the MARC record (500$a in MARC21) split by bar (|)
607   `serial` tinyint(1) default NULL, -- foreign key, linking to the subscriptionid in the serial table
608   `seriestitle` mediumtext,
609   `copyrightdate` smallint(6) default NULL, -- publication or copyright date from the MARC record
610   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- date and time this record was last touched
611   `datecreated` DATE NOT NULL, -- the date this record was added to Koha
612   `abstract` mediumtext, -- summary from the MARC record (520$a in MARC21)
613   PRIMARY KEY  (`biblionumber`),
614   KEY `blbnoidx` (`biblionumber`)
615 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
616
617 --
618 -- Table structure for table `deletedbiblioitems`
619 --
620
621 DROP TABLE IF EXISTS `deletedbiblioitems`;
622 CREATE TABLE `deletedbiblioitems` ( -- information about bibliographic records that have been deleted
623   `biblioitemnumber` int(11) NOT NULL default 0, -- primary key, unique identifier assigned by Koha
624   `biblionumber` int(11) NOT NULL default 0, -- foreign key linking this table to the biblio table
625   `volume` mediumtext,
626   `number` mediumtext,
627   `itemtype` varchar(10) default NULL, -- biblio level item type (MARC21 942$c)
628   `isbn` varchar(30) default NULL, -- ISBN (MARC21 020$a)
629   `issn` varchar(9) default NULL, -- ISSN (MARC21 022$a)
630   `ean` varchar(13) default NULL,
631   `publicationyear` text,
632   `publishercode` varchar(255) default NULL, -- publisher (MARC21 260$b)
633   `volumedate` date default NULL,
634   `volumedesc` text, -- volume information (MARC21 362$a)
635   `collectiontitle` mediumtext default NULL,
636   `collectionissn` text default NULL,
637   `collectionvolume` mediumtext default NULL,
638   `editionstatement` text default NULL,
639   `editionresponsibility` text default NULL,
640   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
641   `illus` varchar(255) default NULL, -- illustrations (MARC21 300$b)
642   `pages` varchar(255) default NULL, -- number of pages (MARC21 300$c)
643   `notes` mediumtext,
644   `size` varchar(255) default NULL, -- material size (MARC21 300$c)
645   `place` varchar(255) default NULL, -- publication place (MARC21 260$a)
646   `lccn` varchar(25) default NULL, -- library of congress control number (MARC21 010$a)
647   `marc` longblob, -- full bibliographic MARC record
648   `url` varchar(255) default NULL, -- url (MARC21 856$u)
649   `cn_source` varchar(10) default NULL, -- classification source (MARC21 942$2)
650   `cn_class` varchar(30) default NULL,
651   `cn_item` varchar(10) default NULL,
652   `cn_suffix` varchar(10) default NULL,
653   `cn_sort` varchar(30) default NULL,
654   `agerestriction` varchar(255) default NULL,
655   `totalissues` int(10),
656   `marcxml` longtext NOT NULL, -- full bibliographic MARC record in MARCXML
657   PRIMARY KEY  (`biblioitemnumber`),
658   KEY `bibinoidx` (`biblioitemnumber`),
659   KEY `bibnoidx` (`biblionumber`),
660   KEY `isbn` (`isbn`),
661   KEY `publishercode` (`publishercode`)
662 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
663
664 --
665 -- Table structure for table `deletedborrowers`
666 --
667
668 DROP TABLE IF EXISTS `deletedborrowers`;
669 CREATE TABLE `deletedborrowers` ( -- stores data related to the patrons/borrowers you have deleted
670   `borrowernumber` int(11) NOT NULL default 0, -- primary key, Koha assigned ID number for patrons/borrowers
671   `cardnumber` varchar(16) default NULL, -- unique key, library assigned ID number for patrons/borrowers
672   `surname` mediumtext NOT NULL, -- patron/borrower's last name (surname)
673   `firstname` text, -- patron/borrower's first name
674   `title` mediumtext, -- patron/borrower's title, for example: Mr. or Mrs.
675   `othernames` mediumtext, -- any other names associated with the patron/borrower
676   `initials` text, -- initials for your patron/borrower
677   `streetnumber` varchar(10) default NULL, -- the house number for your patron/borrower's primary address
678   `streettype` varchar(50) default NULL, -- the street type (Rd., Blvd, etc) for your patron/borrower's primary address
679   `address` mediumtext NOT NULL, -- the first address line for your patron/borrower's primary address
680   `address2` text, -- the second address line for your patron/borrower's primary address
681   `city` mediumtext NOT NULL, -- the city or town for your patron/borrower's primary address
682   `state` text default NULL, -- the state or province for your patron/borrower's primary address
683   `zipcode` varchar(25) default NULL, -- the zip or postal code for your patron/borrower's primary address
684   `country` text, -- the country for your patron/borrower's primary address
685   `email` mediumtext, -- the primary email address for your patron/borrower's primary address
686   `phone` text, -- the primary phone number for your patron/borrower's primary address
687   `mobile` varchar(50) default NULL, -- the other phone number for your patron/borrower's primary address
688   `fax` mediumtext, -- the fax number for your patron/borrower's primary address
689   `emailpro` text, -- the secondary email addres for your patron/borrower's primary address
690   `phonepro` text, -- the secondary phone number for your patron/borrower's primary address
691   `B_streetnumber` varchar(10) default NULL, -- the house number for your patron/borrower's alternate address
692   `B_streettype` varchar(50) default NULL, -- the street type (Rd., Blvd, etc) for your patron/borrower's alternate address
693   `B_address` varchar(100) default NULL, -- the first address line for your patron/borrower's alternate address
694   `B_address2` text default NULL, -- the second address line for your patron/borrower's alternate address
695   `B_city` mediumtext, -- the city or town for your patron/borrower's alternate address
696   `B_state` text default NULL, -- the state for your patron/borrower's alternate address
697   `B_zipcode` varchar(25) default NULL, -- the zip or postal code for your patron/borrower's alternate address
698   `B_country` text, -- the country for your patron/borrower's alternate address
699   `B_email` text, -- the patron/borrower's alternate email address
700   `B_phone` mediumtext, -- the patron/borrower's alternate phone number
701   `dateofbirth` date default NULL, -- the patron/borrower's date of birth (YYYY-MM-DD)
702   `branchcode` varchar(10) NOT NULL default '', -- foreign key from the branches table, includes the code of the patron/borrower's home branch
703   `categorycode` varchar(10) NOT NULL default '', -- foreign key from the categories table, includes the code of the patron category
704   `dateenrolled` date default NULL, -- date the patron was added to Koha (YYYY-MM-DD)
705   `dateexpiry` date default NULL, -- date the patron/borrower's card is set to expire (YYYY-MM-DD)
706   `gonenoaddress` tinyint(1) default NULL, -- set to 1 for yes and 0 for no, flag to note that library marked this patron/borrower as having an unconfirmed address
707   `lost` tinyint(1) default NULL, -- set to 1 for yes and 0 for no, flag to note that library marked this patron/borrower as having lost their card
708   `debarred` date default NULL, -- until this date the patron can only check-in (no loans, no holds, etc.), is a fine based on days instead of money (YYY-MM-DD)
709   `debarredcomment` VARCHAR(255) DEFAULT NULL, -- comment on the stop of patron
710   `contactname` mediumtext, -- used for children and profesionals to include surname or last name of guarentor or organization name
711   `contactfirstname` text, -- used for children to include first name of guarentor
712   `contacttitle` text, -- used for children to include title (Mr., Mrs., etc) of guarentor
713   `guarantorid` int(11) default NULL, -- borrowernumber used for children or professionals to link them to guarentors or organizations
714   `borrowernotes` mediumtext, -- a note on the patron/borroewr's account that is only visible in the staff client
715   `relationship` varchar(100) default NULL, -- used for children to include the relationship to their guarentor
716   `ethnicity` varchar(50) default NULL, -- unused in Koha
717   `ethnotes` varchar(255) default NULL, -- unused in Koha
718   `sex` varchar(1) default NULL, -- patron/borrower's gender
719   `password` varchar(30) default NULL, -- patron/borrower's encrypted password
720   `flags` int(11) default NULL, -- will include a number associated with the staff member's permissions
721   `userid` varchar(30) default NULL, -- patron/borrower's opac and/or staff client log in
722   `opacnote` mediumtext, -- a note on the patron/borrower's account that is visible in the OPAC and staff client
723   `contactnote` varchar(255) default NULL, -- a note related to the patron/borrower's alternate address
724   `sort1` varchar(80) default NULL, -- a field that can be used for any information unique to the library
725   `sort2` varchar(80) default NULL, -- a field that can be used for any information unique to the library
726   `altcontactfirstname` varchar(255) default NULL, -- first name of alternate contact for the patron/borrower
727   `altcontactsurname` varchar(255) default NULL, -- surname or last name of the alternate contact for the patron/borrower
728   `altcontactaddress1` varchar(255) default NULL, -- the first address line for the alternate contact for the patron/borrower
729   `altcontactaddress2` varchar(255) default NULL, -- the second address line for the alternate contact for the patron/borrower
730   `altcontactaddress3` varchar(255) default NULL, -- the third address line for the alternate contact for the patron/borrower
731   `altcontactstate` text default NULL, -- the city and state for the alternate contact for the patron/borrower
732   `altcontactzipcode` varchar(50) default NULL, -- the zipcode for the alternate contact for the patron/borrower
733   `altcontactcountry` text default NULL, -- the country for the alternate contact for the patron/borrower
734   `altcontactphone` varchar(50) default NULL, -- the phone number for the alternate contact for the patron/borrower
735   `smsalertnumber` varchar(50) default NULL, -- the mobile phone number where the patron/borrower would like to receive notices (if SNS turned on)
736   `privacy` integer(11) DEFAULT '1' NOT NULL, -- patron/borrower's privacy settings related to their reading history  KEY `borrowernumber` (`borrowernumber`),
737   KEY borrowernumber (borrowernumber),
738   KEY `cardnumber` (`cardnumber`)
739 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
740
741 --
742 -- Table structure for table `deleteditems`
743 --
744
745 DROP TABLE IF EXISTS `deleteditems`;
746 CREATE TABLE `deleteditems` (
747   `itemnumber` int(11) NOT NULL default 0, -- primary key and unique identifier added by Koha
748   `biblionumber` int(11) NOT NULL default 0, -- foreign key from biblio table used to link this item to the right bib record
749   `biblioitemnumber` int(11) NOT NULL default 0, -- foreign key from the biblioitems table to link to item to additional information
750   `barcode` varchar(20) default NULL, -- item barcode (MARC21 952$p)
751   `dateaccessioned` date default NULL, -- date the item was acquired or added to Koha (MARC21 952$d)
752   `booksellerid` mediumtext default NULL, -- where the item was purchased (MARC21 952$e)
753   `homebranch` varchar(10) default NULL, -- foreign key from the branches table for the library that owns this item (MARC21 952$a)
754   `price` decimal(8,2) default NULL, -- purchase price (MARC21 952$g)
755   `replacementprice` decimal(8,2) default NULL, -- cost the library charges to replace the item if it has been marked lost (MARC21 952$v)
756   `replacementpricedate` date default NULL, -- the date the price is effective from (MARC21 952$w)
757   `datelastborrowed` date default NULL, -- the date the item was last checked out
758   `datelastseen` date default NULL, -- the date the item was last see (usually the last time the barcode was scanned or inventory was done)
759   `stack` tinyint(1) default NULL,
760   `notforloan` tinyint(1) NOT NULL default 0, -- authorized value defining why this item is not for loan (MARC21 952$7)
761   `damaged` tinyint(1) NOT NULL default 0, -- authorized value defining this item as damaged (MARC21 952$4)
762   `itemlost` tinyint(1) NOT NULL default 0, -- authorized value defining this item as lost (MARC21 952$1)
763   `wthdrawn` tinyint(1) NOT NULL default 0, -- authorized value defining this item as withdrawn (MARC21 952$0)
764   `itemcallnumber` varchar(255) default NULL, -- call number for this item (MARC21 952$o)
765   `issues` smallint(6) default NULL, -- number of times this item has been checked out
766   `renewals` smallint(6) default NULL, -- number of times this item has been renewed
767   `reserves` smallint(6) default NULL, -- number of times this item has been placed on hold/reserved
768   `restricted` tinyint(1) default NULL, -- authorized value defining use restrictions for this item (MARC21 952$5)
769   `itemnotes` mediumtext, -- public notes on this item (MARC21 952$x)
770   `holdingbranch` varchar(10) default NULL, -- foreign key from the branches table for the library that is currently in possession item (MARC21 952$b)
771   `paidfor` mediumtext,
772   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- date and time this item was last altered
773   `location` varchar(80) default NULL, -- authorized value for the shelving location for this item (MARC21 952$c)
774   `permanent_location` varchar(80) default NULL, -- linked to the CART and PROC temporary locations feature, stores the permanent shelving location
775   `onloan` date default NULL, -- defines if item is checked out (NULL for not checked out, and checkout date for checked out)
776   `cn_source` varchar(10) default NULL, -- classification source used on this item (MARC21 952$2)
777   `cn_sort` varchar(30) default NULL, -- normalized form of the call number (MARC21 952$o) used for sorting
778   `ccode` varchar(10) default NULL, -- authorized value for the collection code associated with this item (MARC21 952$8)
779   `materials` varchar(10) default NULL, -- materials specified (MARC21 952$3)
780   `uri` varchar(255) default NULL, -- URL for the item (MARC21 952$u)
781   `itype` varchar(10) default NULL, -- foreign key from the itemtypes table defining the type for this item (MARC21 952$y)
782   `more_subfields_xml` longtext default NULL, -- additional 952 subfields in XML format
783   `enumchron` text default NULL, -- serial enumeration/chronology for the item (MARC21 952$h)
784   `copynumber` varchar(32) default NULL, -- copy number (MARC21 952$t)
785   `stocknumber` varchar(32) default NULL, -- inventory number (MARC21 952$i)
786   `marc` longblob, -- unused in Koha
787   PRIMARY KEY  (`itemnumber`),
788   KEY `delitembarcodeidx` (`barcode`),
789   KEY `delitemstocknumberidx` (`stocknumber`),
790   KEY `delitembinoidx` (`biblioitemnumber`),
791   KEY `delitembibnoidx` (`biblionumber`),
792   KEY `delhomebranch` (`homebranch`),
793   KEY `delholdingbranch` (`holdingbranch`)
794 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
795
796 --
797 -- Table structure for table `ethnicity`
798 --
799
800 DROP TABLE IF EXISTS `ethnicity`;
801 CREATE TABLE `ethnicity` (
802   `code` varchar(10) NOT NULL default '',
803   `name` varchar(255) default NULL,
804   PRIMARY KEY  (`code`)
805 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
806
807 --
808 -- Table structure for table `export_format`
809 --
810
811 DROP TABLE IF EXISTS `export_format`;
812 CREATE TABLE `export_format` (
813   `export_format_id` int(11) NOT NULL auto_increment,
814   `profile` varchar(255) NOT NULL,
815   `description` mediumtext NOT NULL,
816   `marcfields` mediumtext NOT NULL,
817   `csv_separator` varchar(2) NOT NULL,
818   `field_separator` varchar(2) NOT NULL,
819   `subfield_separator` varchar(2) NOT NULL,
820   `encoding` varchar(255) NOT NULL,
821   PRIMARY KEY  (`export_format_id`)
822 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Used for CSV export';
823
824
825 --
826 -- Table structure for table `hold_fill_targets`
827 --
828
829 DROP TABLE IF EXISTS `hold_fill_targets`;
830 CREATE TABLE hold_fill_targets (
831   `borrowernumber` int(11) NOT NULL,
832   `biblionumber` int(11) NOT NULL,
833   `itemnumber` int(11) NOT NULL,
834   `source_branchcode`  varchar(10) default NULL,
835   `item_level_request` tinyint(4) NOT NULL default 0,
836   PRIMARY KEY `itemnumber` (`itemnumber`),
837   KEY `bib_branch` (`biblionumber`, `source_branchcode`),
838   CONSTRAINT `hold_fill_targets_ibfk_1` FOREIGN KEY (`borrowernumber`)
839     REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
840   CONSTRAINT `hold_fill_targets_ibfk_2` FOREIGN KEY (`biblionumber`)
841     REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE,
842   CONSTRAINT `hold_fill_targets_ibfk_3` FOREIGN KEY (`itemnumber`)
843     REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
844   CONSTRAINT `hold_fill_targets_ibfk_4` FOREIGN KEY (`source_branchcode`)
845     REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
846 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
847
848 --
849 -- Table structure for table `import_batches`
850 --
851
852 DROP TABLE IF EXISTS `import_batches`;
853 CREATE TABLE `import_batches` ( -- information about batches of marc records that have been imported
854   `import_batch_id` int(11) NOT NULL auto_increment, -- unique identifier and primary key
855   `matcher_id` int(11) default NULL, -- the id of the match rule used (matchpoints.matcher_id)
856   `template_id` int(11) default NULL,
857   `branchcode` varchar(10) default NULL,
858   `num_records` int(11) NOT NULL default 0, -- number of records in the file
859   `num_items` int(11) NOT NULL default 0, -- number of items in the file
860   `upload_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP, -- date and time the file was uploaded
861   `overlay_action` enum('replace', 'create_new', 'use_template', 'ignore') NOT NULL default 'create_new', -- how to handle duplicate records
862   `nomatch_action` enum('create_new', 'ignore') NOT NULL default 'create_new', -- how to handle records where no match is found
863   `item_action` enum('always_add', 'add_only_for_matches', 'add_only_for_new', 'ignore') NOT NULL default 'always_add', -- what to do with item records
864   `import_status` enum('staging', 'staged', 'importing', 'imported', 'reverting', 'reverted', 'cleaned') NOT NULL default 'staging', -- the status of the imported file
865   `batch_type` enum('batch', 'z3950', 'webservice') NOT NULL default 'batch', -- where this batch has come from
866   `record_type` enum('biblio', 'auth', 'holdings') NOT NULL default 'biblio', -- type of record in the batch
867   `file_name` varchar(100), -- the name of the file uploaded
868   `comments` mediumtext, -- any comments added when the file was uploaded
869   PRIMARY KEY (`import_batch_id`),
870   KEY `branchcode` (`branchcode`)
871 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
872
873 --
874 -- Table structure for table `import_records`
875 --
876
877 DROP TABLE IF EXISTS `import_records`;
878 CREATE TABLE `import_records` (
879   `import_record_id` int(11) NOT NULL auto_increment,
880   `import_batch_id` int(11) NOT NULL,
881   `branchcode` varchar(10) default NULL,
882   `record_sequence` int(11) NOT NULL default 0,
883   `upload_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
884   `import_date` DATE default NULL,
885   `marc` longblob NOT NULL,
886   `marcxml` longtext NOT NULL,
887   `marcxml_old` longtext NOT NULL,
888   `record_type` enum('biblio', 'auth', 'holdings') NOT NULL default 'biblio',
889   `overlay_status` enum('no_match', 'auto_match', 'manual_match', 'match_applied') NOT NULL default 'no_match',
890   `status` enum('error', 'staged', 'imported', 'reverted', 'items_reverted', 'ignored') NOT NULL default 'staged',
891   `import_error` mediumtext,
892   `encoding` varchar(40) NOT NULL default '',
893   `z3950random` varchar(40) default NULL,
894   PRIMARY KEY (`import_record_id`),
895   CONSTRAINT `import_records_ifbk_1` FOREIGN KEY (`import_batch_id`)
896              REFERENCES `import_batches` (`import_batch_id`) ON DELETE CASCADE ON UPDATE CASCADE,
897   KEY `branchcode` (`branchcode`),
898   KEY `batch_sequence` (`import_batch_id`, `record_sequence`)
899 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
900
901 --
902 -- Table structure for `import_record_matches`
903 --
904 DROP TABLE IF EXISTS `import_record_matches`;
905 CREATE TABLE `import_record_matches` ( -- matches found when importing a batch of records
906   `import_record_id` int(11) NOT NULL, -- the id given to the imported bib record (import_records.import_record_id)
907   `candidate_match_id` int(11) NOT NULL, -- the biblio the imported record matches (biblio.biblionumber)
908   `score` int(11) NOT NULL default 0, -- the match score
909   CONSTRAINT `import_record_matches_ibfk_1` FOREIGN KEY (`import_record_id`)
910              REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
911   KEY `record_score` (`import_record_id`, `score`)
912 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
913
914 --
915 -- Table structure for table `import_auths`
916 --
917
918 DROP TABLE IF EXISTS `import_auths`;
919 CREATE TABLE `import_auths` (
920   `import_record_id` int(11) NOT NULL,
921   `matched_authid` int(11) default NULL,
922   `control_number` varchar(25) default NULL,
923   `authorized_heading` varchar(128) default NULL,
924   `original_source` varchar(25) default NULL,
925   CONSTRAINT `import_auths_ibfk_1` FOREIGN KEY (`import_record_id`)
926              REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
927   KEY `matched_authid` (`matched_authid`)
928 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
929
930 --
931 -- Table structure for table `import_biblios`
932 --
933
934 DROP TABLE IF EXISTS `import_biblios`;
935 CREATE TABLE `import_biblios` (
936   `import_record_id` int(11) NOT NULL,
937   `matched_biblionumber` int(11) default NULL,
938   `control_number` varchar(25) default NULL,
939   `original_source` varchar(25) default NULL,
940   `title` varchar(128) default NULL,
941   `author` varchar(80) default NULL,
942   `isbn` varchar(30) default NULL,
943   `issn` varchar(9) default NULL,
944   `has_items` tinyint(1) NOT NULL default 0,
945   CONSTRAINT `import_biblios_ibfk_1` FOREIGN KEY (`import_record_id`)
946              REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
947   KEY `matched_biblionumber` (`matched_biblionumber`),
948   KEY `title` (`title`),
949   KEY `isbn` (`isbn`)
950 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
951
952 --
953 -- Table structure for table `import_items`
954 --
955
956 DROP TABLE IF EXISTS `import_items`;
957 CREATE TABLE `import_items` (
958   `import_items_id` int(11) NOT NULL auto_increment,
959   `import_record_id` int(11) NOT NULL,
960   `itemnumber` int(11) default NULL,
961   `branchcode` varchar(10) default NULL,
962   `status` enum('error', 'staged', 'imported', 'reverted', 'ignored') NOT NULL default 'staged',
963   `marcxml` longtext NOT NULL,
964   `import_error` mediumtext,
965   PRIMARY KEY (`import_items_id`),
966   CONSTRAINT `import_items_ibfk_1` FOREIGN KEY (`import_record_id`)
967              REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
968   KEY `itemnumber` (`itemnumber`),
969   KEY `branchcode` (`branchcode`)
970 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
971
972 --
973 -- Table structure for table `issues`
974 --
975
976 DROP TABLE IF EXISTS `issues`;
977 CREATE TABLE `issues` ( -- information related to check outs or issues
978   `borrowernumber` int(11), -- foreign key, linking this to the borrowers table for the patron this item was checked out to
979   `itemnumber` int(11), -- foreign key, linking this to the items table for the item that was checked out
980   `date_due` datetime default NULL, -- datetime the item is due (yyyy-mm-dd hh:mm::ss)
981   `branchcode` varchar(10) default NULL, -- foreign key, linking to the branches table for the location the item was checked out
982   `issuingbranch` varchar(18) default NULL,
983   `returndate` datetime default NULL, -- date the item was returned, will be NULL until moved to old_issues
984   `lastreneweddate` datetime default NULL, -- date the item was last renewed
985   `return` varchar(4) default NULL,
986   `renewals` tinyint(4) default NULL, -- lists the number of times the item was renewed
987   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- the date and time this record was last touched
988   `issuedate` datetime default NULL, -- date the item was checked out or issued
989   KEY `issuesborridx` (`borrowernumber`),
990   KEY `bordate` (`borrowernumber`,`timestamp`),
991   CONSTRAINT `issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE RESTRICT ON UPDATE CASCADE,
992   CONSTRAINT `issues_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE RESTRICT ON UPDATE CASCADE
993 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
994
995 --
996 -- Table structure for table `issuingrules`
997 --
998
999 DROP TABLE IF EXISTS `issuingrules`;
1000 CREATE TABLE `issuingrules` ( -- circulation and fine rules
1001   `categorycode` varchar(10) NOT NULL default '', -- patron category this rule is for (categories.categorycode)
1002   `itemtype` varchar(10) NOT NULL default '', -- item type this rule is for (itemtypes.itemtype)
1003   `restrictedtype` tinyint(1) default NULL, -- not used? always NULL
1004   `rentaldiscount` decimal(28,6) default NULL, -- percent discount on the rental charge for this item
1005   `reservecharge` decimal(28,6) default NULL,
1006   `fine` decimal(28,6) default NULL, -- fine amount
1007   `finedays` int(11) default NULL, -- suspension in days
1008   `firstremind` int(11) default NULL, -- fine grace period
1009   `chargeperiod` int(11) default NULL, -- how often the fine amount is charged
1010   `accountsent` int(11) default NULL, -- not used? always NULL
1011   `chargename` varchar(100) default NULL, -- not used? always NULL
1012   `maxissueqty` int(4) default NULL, -- total number of checkouts allowed
1013   `issuelength` int(4) default NULL, -- length of checkout in the unit set in issuingrules.lengthunit
1014   `lengthunit` varchar(10) default 'days', -- unit of checkout length (days, hours)
1015   `hardduedate` date default NULL, -- hard due date
1016   `hardduedatecompare` tinyint NOT NULL default "0", -- type of hard due date (1 = after, 0 = on, -1 = before)
1017   `renewalsallowed` smallint(6) NOT NULL default "0", -- how many renewals are allowed
1018   `reservesallowed` smallint(6) NOT NULL default "0", -- how many holds are allowed
1019   `branchcode` varchar(10) NOT NULL default '', -- the branch this rule is for (branches.branchcode)
1020   overduefinescap decimal default NULL, -- the maximum amount of an overdue fine
1021   PRIMARY KEY  (`branchcode`,`categorycode`,`itemtype`),
1022   KEY `categorycode` (`categorycode`),
1023   KEY `itemtype` (`itemtype`)
1024 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1025
1026 --
1027 -- Table structure for table `items`
1028 --
1029
1030 DROP TABLE IF EXISTS `items`;
1031 CREATE TABLE `items` ( -- holdings/item information 
1032   `itemnumber` int(11) NOT NULL auto_increment, -- primary key and unique identifier added by Koha
1033   `biblionumber` int(11) NOT NULL default 0, -- foreign key from biblio table used to link this item to the right bib record
1034   `biblioitemnumber` int(11) NOT NULL default 0, -- foreign key from the biblioitems table to link to item to additional information
1035   `barcode` varchar(20) default NULL, -- item barcode (MARC21 952$p)
1036   `dateaccessioned` date default NULL, -- date the item was acquired or added to Koha (MARC21 952$d)
1037   `booksellerid` mediumtext default NULL, -- where the item was purchased (MARC21 952$e)
1038   `homebranch` varchar(10) default NULL, -- foreign key from the branches table for the library that owns this item (MARC21 952$a)
1039   `price` decimal(8,2) default NULL, -- purchase price (MARC21 952$g)
1040   `replacementprice` decimal(8,2) default NULL, -- cost the library charges to replace the item if it has been marked lost (MARC21 952$v)
1041   `replacementpricedate` date default NULL, -- the date the price is effective from (MARC21 952$w)
1042   `datelastborrowed` date default NULL, -- the date the item was last checked out/issued
1043   `datelastseen` date default NULL, -- the date the item was last see (usually the last time the barcode was scanned or inventory was done)
1044   `stack` tinyint(1) default NULL,
1045   `notforloan` tinyint(1) NOT NULL default 0, -- authorized value defining why this item is not for loan (MARC21 952$7)
1046   `damaged` tinyint(1) NOT NULL default 0, -- authorized value defining this item as damaged (MARC21 952$4)
1047   `itemlost` tinyint(1) NOT NULL default 0, -- authorized value defining this item as lost (MARC21 952$1)
1048   `wthdrawn` tinyint(1) NOT NULL default 0, -- authorized value defining this item as withdrawn (MARC21 952$0)
1049   `itemcallnumber` varchar(255) default NULL, -- call number for this item (MARC21 952$o)
1050   `issues` smallint(6) default NULL, -- number of times this item has been checked out/issued
1051   `renewals` smallint(6) default NULL, -- number of times this item has been renewed
1052   `reserves` smallint(6) default NULL, -- number of times this item has been placed on hold/reserved
1053   `restricted` tinyint(1) default NULL, -- authorized value defining use restrictions for this item (MARC21 952$5)
1054   `itemnotes` mediumtext, -- public notes on this item (MARC21 952$x)
1055   `holdingbranch` varchar(10) default NULL, -- foreign key from the branches table for the library that is currently in possession item (MARC21 952$b)
1056   `paidfor` mediumtext,
1057   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- date and time this item was last altered
1058   `location` varchar(80) default NULL, -- authorized value for the shelving location for this item (MARC21 952$c)
1059   `permanent_location` varchar(80) default NULL, -- linked to the CART and PROC temporary locations feature, stores the permanent shelving location
1060   `onloan` date default NULL, -- defines if item is checked out (NULL for not checked out, and checkout date for checked out)
1061   `cn_source` varchar(10) default NULL, -- classification source used on this item (MARC21 952$2)
1062   `cn_sort` varchar(30) default NULL,  -- normalized form of the call number (MARC21 952$o) used for sorting
1063   `ccode` varchar(10) default NULL, -- authorized value for the collection code associated with this item (MARC21 952$8)
1064   `materials` text default NULL, -- materials specified (MARC21 952$3)
1065   `uri` varchar(255) default NULL, -- URL for the item (MARC21 952$u)
1066   `itype` varchar(10) default NULL, -- foreign key from the itemtypes table defining the type for this item (MARC21 952$y)
1067   `more_subfields_xml` longtext default NULL, -- additional 952 subfields in XML format
1068   `enumchron` text default NULL, -- serial enumeration/chronology for the item (MARC21 952$h)
1069   `copynumber` varchar(32) default NULL, -- copy number (MARC21 952$t)
1070   `stocknumber` varchar(32) default NULL, -- inventory number (MARC21 952$i)
1071   PRIMARY KEY  (`itemnumber`),
1072   UNIQUE KEY `itembarcodeidx` (`barcode`),
1073   KEY `itemstocknumberidx` (`stocknumber`),
1074   KEY `itembinoidx` (`biblioitemnumber`),
1075   KEY `itembibnoidx` (`biblionumber`),
1076   KEY `homebranch` (`homebranch`),
1077   KEY `holdingbranch` (`holdingbranch`),
1078   KEY `itemcallnumber` (`itemcallnumber`),
1079   KEY `items_location` (`location`),
1080   KEY `items_ccode` (`ccode`),
1081   CONSTRAINT `items_ibfk_1` FOREIGN KEY (`biblioitemnumber`) REFERENCES `biblioitems` (`biblioitemnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1082   CONSTRAINT `items_ibfk_2` FOREIGN KEY (`homebranch`) REFERENCES `branches` (`branchcode`) ON UPDATE CASCADE,
1083   CONSTRAINT `items_ibfk_3` FOREIGN KEY (`holdingbranch`) REFERENCES `branches` (`branchcode`) ON UPDATE CASCADE
1084 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1085
1086 --
1087 -- Table structure for table `itemtypes`
1088 --
1089
1090 DROP TABLE IF EXISTS `itemtypes`;
1091 CREATE TABLE `itemtypes` ( -- defines the item types
1092   `itemtype` varchar(10) NOT NULL default '', -- unique key, a code associated with the item type
1093   `description` mediumtext, -- a plain text explanation of the item type
1094   `rentalcharge` double(16,4) default NULL, -- the amount charged when this item is checked out/issued
1095   `notforloan` smallint(6) default NULL, -- 1 if the item is not for loan, 0 if the item is available for loan
1096   `imageurl` varchar(200) default NULL, -- URL for the item type icon
1097   `summary` text, -- information from the summary field, may include HTML
1098   PRIMARY KEY  (`itemtype`),
1099   UNIQUE KEY `itemtype` (`itemtype`)
1100 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1101
1102 --
1103 -- Table structure for table `creator_batches`
1104 --
1105
1106 DROP TABLE IF EXISTS `creator_batches`;
1107 SET @saved_cs_client     = @@character_set_client;
1108 SET character_set_client = utf8;
1109 CREATE TABLE `creator_batches` (
1110   `label_id` int(11) NOT NULL AUTO_INCREMENT,
1111   `batch_id` int(10) NOT NULL DEFAULT '1',
1112   `item_number` int(11) DEFAULT NULL,
1113   `borrower_number` int(11) DEFAULT NULL,
1114   `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
1115   `branch_code` varchar(10) NOT NULL DEFAULT 'NB',
1116   `creator` char(15) NOT NULL DEFAULT 'Labels',
1117   PRIMARY KEY (`label_id`),
1118   KEY `branch_fk_constraint` (`branch_code`),
1119   KEY `item_fk_constraint` (`item_number`),
1120   KEY `borrower_fk_constraint` (`borrower_number`),
1121   CONSTRAINT `creator_batches_ibfk_1` FOREIGN KEY (`borrower_number`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1122   CONSTRAINT `creator_batches_ibfk_2` FOREIGN KEY (`branch_code`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE,
1123   CONSTRAINT `creator_batches_ibfk_3` FOREIGN KEY (`item_number`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE
1124 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1125
1126 --
1127 -- Table structure for table `creator_images`
1128 --
1129
1130 DROP TABLE IF EXISTS `creator_images`;
1131 SET @saved_cs_client     = @@character_set_client;
1132 SET character_set_client = utf8;
1133 CREATE TABLE `creator_images` (
1134   `image_id` int(4) NOT NULL AUTO_INCREMENT,
1135   `imagefile` mediumblob,
1136   `image_name` char(20) NOT NULL DEFAULT 'DEFAULT',
1137   PRIMARY KEY (`image_id`),
1138   UNIQUE KEY `image_name_index` (`image_name`)
1139 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1140
1141 --
1142 -- Table structure for table `creator_layouts`
1143 --
1144
1145 DROP TABLE IF EXISTS `creator_layouts`;
1146 SET @saved_cs_client     = @@character_set_client;
1147 SET character_set_client = utf8;
1148 CREATE TABLE `creator_layouts` (
1149   `layout_id` int(4) NOT NULL AUTO_INCREMENT,
1150   `barcode_type` char(100) NOT NULL DEFAULT 'CODE39',
1151   `start_label` int(2) NOT NULL DEFAULT '1',
1152   `printing_type` char(32) NOT NULL DEFAULT 'BAR',
1153   `layout_name` char(20) NOT NULL DEFAULT 'DEFAULT',
1154   `guidebox` int(1) DEFAULT '0',
1155   `font` char(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'TR',
1156   `font_size` int(4) NOT NULL DEFAULT '10',
1157   `units` char(20) NOT NULL DEFAULT 'POINT',
1158   `callnum_split` int(1) DEFAULT '0',
1159   `text_justify` char(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'L',
1160   `format_string` varchar(210) NOT NULL DEFAULT 'barcode',
1161   `layout_xml` text NOT NULL,
1162   `creator` char(15) NOT NULL DEFAULT 'Labels',
1163   PRIMARY KEY (`layout_id`)
1164 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1165
1166 --
1167 -- Table structure for table `creator_templates`
1168 --
1169
1170 DROP TABLE IF EXISTS `creator_templates`;
1171 SET @saved_cs_client     = @@character_set_client;
1172 SET character_set_client = utf8;
1173 CREATE TABLE `creator_templates` (
1174   `template_id` int(4) NOT NULL AUTO_INCREMENT,
1175   `profile_id` int(4) DEFAULT NULL,
1176   `template_code` char(100) NOT NULL DEFAULT 'DEFAULT TEMPLATE',
1177   `template_desc` char(100) NOT NULL DEFAULT 'Default description',
1178   `page_width` float NOT NULL DEFAULT '0',
1179   `page_height` float NOT NULL DEFAULT '0',
1180   `label_width` float NOT NULL DEFAULT '0',
1181   `label_height` float NOT NULL DEFAULT '0',
1182   `top_text_margin` float NOT NULL DEFAULT '0',
1183   `left_text_margin` float NOT NULL DEFAULT '0',
1184   `top_margin` float NOT NULL DEFAULT '0',
1185   `left_margin` float NOT NULL DEFAULT '0',
1186   `cols` int(2) NOT NULL DEFAULT '0',
1187   `rows` int(2) NOT NULL DEFAULT '0',
1188   `col_gap` float NOT NULL DEFAULT '0',
1189   `row_gap` float NOT NULL DEFAULT '0',
1190   `units` char(20) NOT NULL DEFAULT 'POINT',
1191   `creator` char(15) NOT NULL DEFAULT 'Labels',
1192   PRIMARY KEY (`template_id`),
1193   KEY `template_profile_fk_constraint` (`profile_id`)
1194 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1195
1196 --
1197 -- Table structure for table `letter`
1198 --
1199
1200 DROP TABLE IF EXISTS `letter`;
1201 CREATE TABLE `letter` ( -- table for all notice templates in Koha
1202   `module` varchar(20) NOT NULL default '', -- Koha module that triggers this notice or slip
1203   `code` varchar(20) NOT NULL default '', -- unique identifier for this notice or slip
1204   `branchcode` varchar(10) default NULL, -- the branch this notice or slip is used at (branches.branchcode)
1205   `name` varchar(100) NOT NULL default '', -- plain text name for this notice or slip
1206   `is_html` tinyint(1) default 0, -- does this notice or slip use HTML (1 for yes, 0 for no)
1207   `title` varchar(200) NOT NULL default '', -- subject line of the notice
1208   `content` text, -- body text for the notice or slip
1209   PRIMARY KEY  (`module`,`code`, `branchcode`)
1210 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1211
1212 --
1213 -- Table structure for table `marc_subfield_structure`
1214 --
1215
1216 DROP TABLE IF EXISTS `marc_subfield_structure`;
1217 CREATE TABLE `marc_subfield_structure` (
1218   `tagfield` varchar(3) NOT NULL default '',
1219   `tagsubfield` varchar(1) NOT NULL default '' COLLATE utf8_bin,
1220   `liblibrarian` varchar(255) NOT NULL default '',
1221   `libopac` varchar(255) NOT NULL default '',
1222   `repeatable` tinyint(4) NOT NULL default 0,
1223   `mandatory` tinyint(4) NOT NULL default 0,
1224   `kohafield` varchar(40) default NULL,
1225   `tab` tinyint(1) default NULL,
1226   `authorised_value` varchar(20) default NULL,
1227   `authtypecode` varchar(20) default NULL,
1228   `value_builder` varchar(80) default NULL,
1229   `isurl` tinyint(1) default NULL,
1230   `hidden` tinyint(1) default NULL,
1231   `frameworkcode` varchar(4) NOT NULL default '',
1232   `seealso` varchar(1100) default NULL,
1233   `link` varchar(80) default NULL,
1234   `defaultvalue` text default NULL,
1235   `maxlength` int(4) NOT NULL DEFAULT '9999',
1236   PRIMARY KEY  (`frameworkcode`,`tagfield`,`tagsubfield`),
1237   KEY `kohafield_2` (`kohafield`),
1238   KEY `tab` (`frameworkcode`,`tab`),
1239   KEY `kohafield` (`frameworkcode`,`kohafield`)
1240 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1241
1242 --
1243 -- Table structure for table `marc_tag_structure`
1244 --
1245
1246 DROP TABLE IF EXISTS `marc_tag_structure`;
1247 CREATE TABLE `marc_tag_structure` (
1248   `tagfield` varchar(3) NOT NULL default '',
1249   `liblibrarian` varchar(255) NOT NULL default '',
1250   `libopac` varchar(255) NOT NULL default '',
1251   `repeatable` tinyint(4) NOT NULL default 0,
1252   `mandatory` tinyint(4) NOT NULL default 0,
1253   `authorised_value` varchar(10) default NULL,
1254   `frameworkcode` varchar(4) NOT NULL default '',
1255   PRIMARY KEY  (`frameworkcode`,`tagfield`)
1256 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1257
1258 --
1259 -- Table structure for table `marc_matchers`
1260 --
1261
1262 DROP TABLE IF EXISTS `marc_matchers`;
1263 CREATE TABLE `marc_matchers` (
1264   `matcher_id` int(11) NOT NULL auto_increment,
1265   `code` varchar(10) NOT NULL default '',
1266   `description` varchar(255) NOT NULL default '',
1267   `record_type` varchar(10) NOT NULL default 'biblio',
1268   `threshold` int(11) NOT NULL default 0,
1269   PRIMARY KEY (`matcher_id`),
1270   KEY `code` (`code`),
1271   KEY `record_type` (`record_type`)
1272 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1273
1274 --
1275 -- Table structure for table `matchpoints`
1276 --
1277 DROP TABLE IF EXISTS `matchpoints`;
1278 CREATE TABLE `matchpoints` (
1279   `matcher_id` int(11) NOT NULL,
1280   `matchpoint_id` int(11) NOT NULL auto_increment,
1281   `search_index` varchar(30) NOT NULL default '',
1282   `score` int(11) NOT NULL default 0,
1283   PRIMARY KEY (`matchpoint_id`),
1284   CONSTRAINT `matchpoints_ifbk_1` FOREIGN KEY (`matcher_id`)
1285   REFERENCES `marc_matchers` (`matcher_id`) ON DELETE CASCADE ON UPDATE CASCADE
1286 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1287
1288
1289 --
1290 -- Table structure for table `matchpoint_components`
1291 --
1292 DROP TABLE IF EXISTS `matchpoint_components`;
1293 CREATE TABLE `matchpoint_components` (
1294   `matchpoint_id` int(11) NOT NULL,
1295   `matchpoint_component_id` int(11) NOT NULL auto_increment,
1296   sequence int(11) NOT NULL default 0,
1297   tag varchar(3) NOT NULL default '',
1298   subfields varchar(40) NOT NULL default '',
1299   offset int(4) NOT NULL default 0,
1300   length int(4) NOT NULL default 0,
1301   PRIMARY KEY (`matchpoint_component_id`),
1302   KEY `by_sequence` (`matchpoint_id`, `sequence`),
1303   CONSTRAINT `matchpoint_components_ifbk_1` FOREIGN KEY (`matchpoint_id`)
1304   REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE
1305 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1306
1307 --
1308 -- Table structure for table `matcher_component_norms`
1309 --
1310 DROP TABLE IF EXISTS `matchpoint_component_norms`;
1311 CREATE TABLE `matchpoint_component_norms` (
1312   `matchpoint_component_id` int(11) NOT NULL,
1313   `sequence`  int(11) NOT NULL default 0,
1314   `norm_routine` varchar(50) NOT NULL default '',
1315   KEY `matchpoint_component_norms` (`matchpoint_component_id`, `sequence`),
1316   CONSTRAINT `matchpoint_component_norms_ifbk_1` FOREIGN KEY (`matchpoint_component_id`)
1317   REFERENCES `matchpoint_components` (`matchpoint_component_id`) ON DELETE CASCADE ON UPDATE CASCADE
1318 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1319
1320 --
1321 -- Table structure for table `matcher_matchpoints`
1322 --
1323 DROP TABLE IF EXISTS `matcher_matchpoints`;
1324 CREATE TABLE `matcher_matchpoints` (
1325   `matcher_id` int(11) NOT NULL,
1326   `matchpoint_id` int(11) NOT NULL,
1327   CONSTRAINT `matcher_matchpoints_ifbk_1` FOREIGN KEY (`matcher_id`)
1328   REFERENCES `marc_matchers` (`matcher_id`) ON DELETE CASCADE ON UPDATE CASCADE,
1329   CONSTRAINT `matcher_matchpoints_ifbk_2` FOREIGN KEY (`matchpoint_id`)
1330   REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE
1331 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1332
1333 --
1334 -- Table structure for table `matchchecks`
1335 --
1336 DROP TABLE IF EXISTS `matchchecks`;
1337 CREATE TABLE `matchchecks` (
1338   `matcher_id` int(11) NOT NULL,
1339   `matchcheck_id` int(11) NOT NULL auto_increment,
1340   `source_matchpoint_id` int(11) NOT NULL,
1341   `target_matchpoint_id` int(11) NOT NULL,
1342   PRIMARY KEY (`matchcheck_id`),
1343   CONSTRAINT `matcher_matchchecks_ifbk_1` FOREIGN KEY (`matcher_id`)
1344   REFERENCES `marc_matchers` (`matcher_id`) ON DELETE CASCADE ON UPDATE CASCADE,
1345   CONSTRAINT `matcher_matchchecks_ifbk_2` FOREIGN KEY (`source_matchpoint_id`)
1346   REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE,
1347   CONSTRAINT `matcher_matchchecks_ifbk_3` FOREIGN KEY (`target_matchpoint_id`)
1348   REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE
1349 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1350
1351 --
1352 -- Table structure for table `need_merge_authorities`
1353 --
1354
1355 DROP TABLE IF EXISTS `need_merge_authorities`;
1356 CREATE TABLE `need_merge_authorities` ( -- keeping track of authority records still to be merged by merge_authority cron job (used only if pref dontmerge is ON)
1357   `id` int NOT NULL auto_increment PRIMARY KEY, -- unique id
1358   `authid` bigint NOT NULL, -- reference to authority record
1359   `done` tinyint DEFAULT 0  -- indication whether merge has been executed (0=not done, 1= done, 2= in progress)
1360 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1361
1362 --
1363 -- Table structure for table `notifys`
1364 --
1365
1366 DROP TABLE IF EXISTS `notifys`;
1367 CREATE TABLE `notifys` (
1368   `notify_id` int(11) NOT NULL default 0,
1369   `borrowernumber` int(11) NOT NULL default 0,
1370   `itemnumber` int(11) NOT NULL default 0,
1371   `notify_date` date default NULL,
1372   `notify_send_date` date default NULL,
1373   `notify_level` int(1) NOT NULL default 0,
1374   `method` varchar(20) NOT NULL default ''
1375 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1376
1377 --
1378 -- Table structure for table `nozebra`
1379 --
1380
1381 DROP TABLE IF EXISTS `nozebra`;
1382 CREATE TABLE `nozebra` (
1383   `server` varchar(20)     NOT NULL,
1384   `indexname` varchar(40)  NOT NULL,
1385   `value` varchar(250)     NOT NULL,
1386   `biblionumbers` longtext NOT NULL,
1387   KEY `indexname` (`server`,`indexname`),
1388   KEY `value` (`server`,`value`))
1389   ENGINE=InnoDB DEFAULT CHARSET=utf8;
1390
1391 --
1392 -- Table structure for table `oai_sets`
1393 --
1394
1395 DROP TABLE IF EXISTS `oai_sets`;
1396 CREATE TABLE `oai_sets` (
1397   `id` int(11) NOT NULL auto_increment,
1398   `spec` varchar(80) NOT NULL UNIQUE,
1399   `name` varchar(80) NOT NULL,
1400   PRIMARY KEY (`id`)
1401 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1402
1403 --
1404 -- Table structure for table `oai_sets_descriptions`
1405 --
1406
1407 DROP TABLE IF EXISTS `oai_sets_descriptions`;
1408 CREATE TABLE `oai_sets_descriptions` (
1409   `set_id` int(11) NOT NULL,
1410   `description` varchar(255) NOT NULL,
1411   CONSTRAINT `oai_sets_descriptions_ibfk_1` FOREIGN KEY (`set_id`) REFERENCES `oai_sets` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1412 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1413
1414 --
1415 -- Table structure for table `oai_sets_mappings`
1416 --
1417
1418 DROP TABLE IF EXISTS `oai_sets_mappings`;
1419 CREATE TABLE `oai_sets_mappings` (
1420   `set_id` int(11) NOT NULL,
1421   `marcfield` char(3) NOT NULL,
1422   `marcsubfield` char(1) NOT NULL,
1423   `marcvalue` varchar(80) NOT NULL,
1424   CONSTRAINT `oai_sets_mappings_ibfk_1` FOREIGN KEY (`set_id`) REFERENCES `oai_sets` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1425 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1426
1427 --
1428 -- Table structure for table `oai_sets_biblios`
1429 --
1430
1431 DROP TABLE IF EXISTS `oai_sets_biblios`;
1432 CREATE TABLE `oai_sets_biblios` (
1433   `biblionumber` int(11) NOT NULL,
1434   `set_id` int(11) NOT NULL,
1435   PRIMARY KEY (`biblionumber`, `set_id`),
1436   CONSTRAINT `oai_sets_biblios_ibfk_1` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1437   CONSTRAINT `oai_sets_biblios_ibfk_2` FOREIGN KEY (`set_id`) REFERENCES `oai_sets` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1438 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1439
1440 --
1441 -- Table structure for table `old_issues`
1442 --
1443
1444 DROP TABLE IF EXISTS `old_issues`;
1445 CREATE TABLE `old_issues` ( -- lists items that were checked out and have been returned
1446   `borrowernumber` int(11) default NULL, -- foreign key, linking this to the borrowers table for the patron this item was checked out to
1447   `itemnumber` int(11) default NULL, -- foreign key, linking this to the items table for the item that was checked out
1448   `date_due` datetime default NULL, -- date the item is due (yyyy-mm-dd)
1449   `branchcode` varchar(10) default NULL, -- foreign key, linking to the branches table for the location the item was checked out
1450   `issuingbranch` varchar(18) default NULL,
1451   `returndate` datetime default NULL, -- date the item was returned
1452   `lastreneweddate` datetime default NULL, -- date the item was last renewed
1453   `return` varchar(4) default NULL,
1454   `renewals` tinyint(4) default NULL, -- lists the number of times the item was renewed
1455   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- the date and time this record was last touched
1456   `issuedate` datetime default NULL, -- date the item was checked out or issued
1457   KEY `old_issuesborridx` (`borrowernumber`),
1458   KEY `old_issuesitemidx` (`itemnumber`),
1459   KEY `old_bordate` (`borrowernumber`,`timestamp`),
1460   CONSTRAINT `old_issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1461     ON DELETE SET NULL ON UPDATE SET NULL,
1462   CONSTRAINT `old_issues_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`)
1463     ON DELETE SET NULL ON UPDATE SET NULL
1464 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1465
1466 --
1467 -- Table structure for table `old_reserves`
1468 --
1469 DROP TABLE IF EXISTS `old_reserves`;
1470 CREATE TABLE `old_reserves` ( -- this table holds all holds/reserves that have been completed (either filled or cancelled)
1471   `reserve_id` int(11) NOT NULL, -- primary key
1472   `borrowernumber` int(11) default NULL, -- foreign key from the borrowers table defining which patron this hold is for
1473   `reservedate` date default NULL, -- the date the hold was places
1474   `biblionumber` int(11) default NULL, -- foreign key from the biblio table defining which bib record this hold is on
1475   `constrainttype` varchar(1) default NULL,
1476   `branchcode` varchar(10) default NULL, -- foreign key from the branches table defining which branch the patron wishes to pick this hold up at
1477   `notificationdate` date default NULL, -- currently unused
1478   `reminderdate` date default NULL, -- currently unused
1479   `cancellationdate` date default NULL, -- the date this hold was cancelled
1480   `reservenotes` mediumtext, -- notes related to this hold
1481   `priority` smallint(6) default NULL, -- where in the queue the patron sits
1482   `found` varchar(1) default NULL, -- a one letter code defining what the status is of the hold is after it has been confirmed
1483   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- the date and time this hold was last updated
1484   `itemnumber` int(11) default NULL, -- foreign key from the items table defining the specific item the patron has placed on hold or the item this hold was filled with
1485   `waitingdate` date default NULL, -- the date the item was marked as waiting for the patron at the library
1486   `expirationdate` DATE DEFAULT NULL, -- the date the hold expires (usually the date entered by the patron to say they don't need the hold after a certain date)
1487   `lowestPriority` tinyint(1) NOT NULL, -- has this hold been pinned to the lowest priority in the holds queue (1 for yes, 0 for no)
1488   `suspend` BOOLEAN NOT NULL DEFAULT 0, -- in this hold suspended (1 for yes, 0 for no)
1489   `suspend_until` DATETIME NULL DEFAULT NULL, -- the date this hold is suspended until (NULL for infinitely)
1490   PRIMARY KEY (`reserve_id`),
1491   KEY `old_reserves_borrowernumber` (`borrowernumber`),
1492   KEY `old_reserves_biblionumber` (`biblionumber`),
1493   KEY `old_reserves_itemnumber` (`itemnumber`),
1494   KEY `old_reserves_branchcode` (`branchcode`),
1495   CONSTRAINT `old_reserves_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1496     ON DELETE SET NULL ON UPDATE SET NULL,
1497   CONSTRAINT `old_reserves_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`)
1498     ON DELETE SET NULL ON UPDATE SET NULL,
1499   CONSTRAINT `old_reserves_ibfk_3` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`)
1500     ON DELETE SET NULL ON UPDATE SET NULL
1501 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1502
1503 --
1504 -- Table structure for table `opac_news`
1505 --
1506
1507 DROP TABLE IF EXISTS `opac_news`;
1508 CREATE TABLE `opac_news` ( -- data from the news tool
1509   `idnew` int(10) unsigned NOT NULL auto_increment, -- unique identifier for the news article
1510   `title` varchar(250) NOT NULL default '', -- title of the news article
1511   `new` text NOT NULL, -- the body of your news article
1512   `lang` varchar(25) NOT NULL default '', -- location for the article (koha is the staff client, slip is the circulation receipt and language codes are for the opac)
1513   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP, -- pulibcation date and time
1514   `expirationdate` date default NULL, -- date the article is set to expire or no longer be visible
1515   `number` int(11) default NULL, -- the order in which this article appears in that specific location
1516   PRIMARY KEY  (`idnew`)
1517 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1518
1519 --
1520 -- Table structure for table `overduerules`
1521 --
1522
1523 DROP TABLE IF EXISTS `overduerules`;
1524 CREATE TABLE `overduerules` ( -- overdue notice status and triggers
1525   `branchcode` varchar(10) NOT NULL default '', -- foreign key from the branches table to define which branch this rule is for (if blank it's all libraries)
1526   `categorycode` varchar(10) NOT NULL default '', -- foreign key from the categories table to define which patron category this rule is for
1527   `delay1` int(4) default NULL, -- number of days after the item is overdue that the first notice is sent
1528   `letter1` varchar(20) default NULL, -- foreign key from the letter table to define which notice should be sent as the first notice
1529   `debarred1` varchar(1) default 0, -- is the patron restricted when the first notice is sent (1 for yes, 0 for no)
1530   `delay2` int(4) default NULL, -- number of days after the item is overdue that the second notice is sent
1531   `debarred2` varchar(1) default 0, -- is the patron restricted when the second notice is sent (1 for yes, 0 for no)
1532   `letter2` varchar(20) default NULL, -- foreign key from the letter table to define which notice should be sent as the second notice
1533   `delay3` int(4) default NULL, -- number of days after the item is overdue that the third notice is sent
1534   `letter3` varchar(20) default NULL, -- foreign key from the letter table to define which notice should be sent as the third notice
1535   `debarred3` int(1) default 0, -- is the patron restricted when the third notice is sent (1 for yes, 0 for no)
1536   PRIMARY KEY  (`branchcode`,`categorycode`)
1537 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1538
1539 --
1540 -- Table structure for table `patroncards`
1541 --
1542
1543 DROP TABLE IF EXISTS `patroncards`;
1544 CREATE TABLE `patroncards` (
1545   `cardid` int(11) NOT NULL auto_increment,
1546   `batch_id` varchar(10) NOT NULL default '1',
1547   `borrowernumber` int(11) NOT NULL,
1548   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
1549    PRIMARY KEY  (`cardid`),
1550    KEY `patroncards_ibfk_1` (`borrowernumber`),
1551    CONSTRAINT `patroncards_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
1552 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1553
1554 --
1555 -- Table structure for table `patronimage`
1556 --
1557
1558 DROP TABLE IF EXISTS `patronimage`;
1559 CREATE TABLE `patronimage` ( -- information related to patron images
1560   `cardnumber` varchar(16) NOT NULL, -- the cardnumber of the patron this image is attached to (borrowers.cardnumber)
1561   `mimetype` varchar(15) NOT NULL, -- the format of the image (png, jpg, etc)
1562   `imagefile` mediumblob NOT NULL, -- the image
1563   PRIMARY KEY  (`cardnumber`),
1564   CONSTRAINT `patronimage_fk1` FOREIGN KEY (`cardnumber`) REFERENCES `borrowers` (`cardnumber`) ON DELETE CASCADE ON UPDATE CASCADE
1565 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1566
1567 -- Table structure for table `pending_offline_operations`
1568 --
1569 -- this table is MyISAM, InnoDB tables are growing only and this table is filled/emptied/filled/emptied...
1570 -- so MyISAM is better in this case
1571
1572 DROP TABLE IF EXISTS `pending_offline_operations`;
1573 CREATE TABLE `pending_offline_operations` (
1574   `operationid` int(11) NOT NULL AUTO_INCREMENT,
1575   `userid` varchar(30) NOT NULL,
1576   `branchcode` varchar(10) NOT NULL,
1577   `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
1578   `action` varchar(10) NOT NULL,
1579   `barcode` varchar(20) NOT NULL,
1580   `cardnumber` varchar(16) DEFAULT NULL,
1581   PRIMARY KEY (`operationid`)
1582 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
1583
1584
1585
1586 --
1587 -- Table structure for table `printers`
1588 --
1589
1590 DROP TABLE IF EXISTS `printers`;
1591 CREATE TABLE `printers` (
1592   `printername` varchar(40) NOT NULL default '',
1593   `printqueue` varchar(20) default NULL,
1594   `printtype` varchar(20) default NULL,
1595   PRIMARY KEY  (`printername`)
1596 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1597
1598 --
1599 -- Table structure for table `printers_profile`
1600 --
1601
1602 DROP TABLE IF EXISTS `printers_profile`;
1603 CREATE TABLE `printers_profile` (
1604   `profile_id` int(4) NOT NULL auto_increment,
1605   `printer_name` varchar(40) NOT NULL default 'Default Printer',
1606   `template_id` int(4) NOT NULL default '0',
1607   `paper_bin` varchar(20) NOT NULL default 'Bypass',
1608   `offset_horz` float NOT NULL default '0',
1609   `offset_vert` float NOT NULL default '0',
1610   `creep_horz` float NOT NULL default '0',
1611   `creep_vert` float NOT NULL default '0',
1612   `units` char(20) NOT NULL default 'POINT',
1613   `creator` char(15) NOT NULL DEFAULT 'Labels',
1614   PRIMARY KEY  (`profile_id`),
1615   UNIQUE KEY `printername` (`printer_name`,`template_id`,`paper_bin`,`creator`)
1616 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1617
1618 --
1619 -- Table structure for table `repeatable_holidays`
1620 --
1621
1622 DROP TABLE IF EXISTS `repeatable_holidays`;
1623 CREATE TABLE `repeatable_holidays` ( -- information for the days the library is closed
1624   `id` int(11) NOT NULL auto_increment, -- unique identifier assigned by Koha
1625   `branchcode` varchar(10) NOT NULL default '', -- foreign key from the branches table, defines which branch this closing is for
1626   `weekday` smallint(6) default NULL, -- day of the week (0=Sunday, 1=Monday, etc) this closing is repeated on
1627   `day` smallint(6) default NULL, -- day of the month this closing is on
1628   `month` smallint(6) default NULL, -- month this closing is in
1629   `title` varchar(50) NOT NULL default '', -- title of this closing
1630   `description` text NOT NULL, -- description for this closing
1631   PRIMARY KEY  (`id`)
1632 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1633
1634 --
1635 -- Table structure for table `reports_dictionary`
1636 --
1637
1638 DROP TABLE IF EXISTS `reports_dictionary`;
1639 CREATE TABLE reports_dictionary ( -- definitions (or snippets of SQL) stored for use in reports
1640    `id` int(11) NOT NULL auto_increment, -- unique identifier assigned by Koha
1641    `name` varchar(255) default NULL, -- name for this definition
1642    `description` text, -- description for this definition
1643    `date_created` datetime default NULL, -- date and time this definition was created
1644    `date_modified` datetime default NULL, -- date and time this definition was last modified
1645    `saved_sql` text, -- SQL snippet for us in reports
1646    report_area varchar(6) DEFAULT NULL, -- Koha module this definition is for Circulation, Catalog, Patrons, Acquistions, Accounts)
1647    PRIMARY KEY  (id),
1648    KEY dictionary_area_idx (report_area)
1649 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1650
1651 --
1652 -- Table structure for table `reserveconstraints`
1653 --
1654
1655 DROP TABLE IF EXISTS `reserveconstraints`;
1656 CREATE TABLE `reserveconstraints` (
1657   `borrowernumber` int(11) NOT NULL default 0,
1658   `reservedate` date default NULL,
1659   `biblionumber` int(11) NOT NULL default 0,
1660   `biblioitemnumber` int(11) default NULL,
1661   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP
1662 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1663
1664 --
1665 -- Table structure for table `reserves`
1666 --
1667
1668 DROP TABLE IF EXISTS `reserves`;
1669 CREATE TABLE `reserves` ( -- information related to holds/reserves in Koha
1670   `reserve_id` int(11) NOT NULL auto_increment, -- primary key
1671   `borrowernumber` int(11) NOT NULL default 0, -- foreign key from the borrowers table defining which patron this hold is for
1672   `reservedate` date default NULL, -- the date the hold was places
1673   `biblionumber` int(11) NOT NULL default 0, -- foreign key from the biblio table defining which bib record this hold is on
1674   `constrainttype` varchar(1) default NULL,
1675   `branchcode` varchar(10) default NULL, -- foreign key from the branches table defining which branch the patron wishes to pick this hold up at
1676   `notificationdate` date default NULL, -- currently unused
1677   `reminderdate` date default NULL, -- currently unused
1678   `cancellationdate` date default NULL, -- the date this hold was cancelled
1679   `reservenotes` mediumtext, -- notes related to this hold
1680   `priority` smallint(6) default NULL, -- where in the queue the patron sits
1681   `found` varchar(1) default NULL, -- a one letter code defining what the status is of the hold is after it has been confirmed
1682   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- the date and time this hold was last updated
1683   `itemnumber` int(11) default NULL, -- foreign key from the items table defining the specific item the patron has placed on hold or the item this hold was filled with
1684   `waitingdate` date default NULL, -- the date the item was marked as waiting for the patron at the library
1685   `expirationdate` DATE DEFAULT NULL, -- the date the hold expires (usually the date entered by the patron to say they don't need the hold after a certain date)
1686   `lowestPriority` tinyint(1) NOT NULL,
1687   `suspend` BOOLEAN NOT NULL DEFAULT 0,
1688   `suspend_until` DATETIME NULL DEFAULT NULL,
1689   PRIMARY KEY (`reserve_id`),
1690   KEY priorityfoundidx (priority,found),
1691   KEY `borrowernumber` (`borrowernumber`),
1692   KEY `biblionumber` (`biblionumber`),
1693   KEY `itemnumber` (`itemnumber`),
1694   KEY `branchcode` (`branchcode`),
1695   CONSTRAINT `reserves_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1696   CONSTRAINT `reserves_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1697   CONSTRAINT `reserves_ibfk_3` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1698   CONSTRAINT `reserves_ibfk_4` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
1699 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1700
1701 --
1702 -- Table structure for table `reviews`
1703 --
1704
1705 DROP TABLE IF EXISTS `reviews`;
1706 CREATE TABLE `reviews` ( -- patron opac comments
1707   `reviewid` int(11) NOT NULL auto_increment, -- unique identifier for this comment
1708   `borrowernumber` int(11) default NULL, -- foreign key from the borrowers table defining which patron left this comment
1709   `biblionumber` int(11) default NULL, -- foreign key from the biblio table defining which bibliographic record this comment is for
1710   `review` text, -- the body of the comment
1711   `approved` tinyint(4) default NULL, -- whether this comment has been approved by a librarian (1 for yes, 0 for no)
1712   `datereviewed` datetime default NULL, -- the date the comment was left
1713   PRIMARY KEY  (`reviewid`),
1714   CONSTRAINT `reviews_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
1715   CONSTRAINT `reviews_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
1716 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1717
1718 --
1719 -- Table structure for table `roadtype`
1720 --
1721
1722 DROP TABLE IF EXISTS `roadtype`;
1723 CREATE TABLE `roadtype` ( -- road types defined in administration and used in patron management
1724   `roadtypeid` int(11) NOT NULL auto_increment, -- unique identifier assigned by Koha for each road type
1725   `road_type` varchar(100) NOT NULL default '', -- text for road type
1726   PRIMARY KEY  (`roadtypeid`)
1727 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1728
1729 --
1730 -- Table structure for table `saved_sql`
1731 --
1732
1733 DROP TABLE IF EXISTS `saved_sql`;
1734 CREATE TABLE saved_sql ( -- saved sql reports
1735    `id` int(11) NOT NULL auto_increment, -- unique id and primary key assigned by Koha
1736    `borrowernumber` int(11) default NULL, -- the staff member who created this report (borrowers.borrowernumber)
1737    `date_created` datetime default NULL, -- the date this report was created
1738    `last_modified` datetime default NULL, -- the date this report was last edited
1739    `savedsql` text, -- the SQL for this report
1740    `last_run` datetime default NULL,
1741    `report_name` varchar(255) default NULL, -- the name of this report
1742    `type` varchar(255) default NULL, -- always 1 for tabular
1743    `notes` text, -- the notes or description given to this report
1744    `cache_expiry` int NOT NULL default 300,
1745    `public` boolean NOT NULL default FALSE,
1746     report_area varchar(6) default NULL,
1747     report_group varchar(80) default NULL,
1748     report_subgroup varchar(80) default NULL,
1749    PRIMARY KEY  (`id`),
1750    KEY sql_area_group_idx (report_group, report_subgroup),
1751    KEY boridx (`borrowernumber`)
1752 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1753
1754
1755 --
1756 -- Table structure for `saved_reports`
1757 --
1758
1759 DROP TABLE IF EXISTS `saved_reports`;
1760 CREATE TABLE saved_reports (
1761    `id` int(11) NOT NULL auto_increment,
1762    `report_id` int(11) default NULL,
1763    `report` longtext,
1764    `date_run` datetime default NULL,
1765    PRIMARY KEY  (`id`)
1766 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1767
1768
1769 --
1770 -- Table structure for table `search_history`
1771 --
1772
1773 DROP TABLE IF EXISTS `search_history`;
1774 CREATE TABLE IF NOT EXISTS `search_history` ( -- patron's opac search history
1775   `userid` int(11) NOT NULL, -- the patron who performed the search (borrowers.borrowernumber)
1776   `sessionid` varchar(32) NOT NULL, -- a system generated session id
1777   `query_desc` varchar(255) NOT NULL, -- the search that was performed
1778   `query_cgi` text NOT NULL, -- the string to append to the search url to rerun the search
1779   `total` int(11) NOT NULL, -- the total of results found
1780   `time` timestamp NOT NULL default CURRENT_TIMESTAMP, -- the date and time the search was run
1781   KEY `userid` (`userid`),
1782   KEY `sessionid` (`sessionid`)
1783 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Opac search history results';
1784
1785
1786 --
1787 -- Table structure for table `serial`
1788 --
1789
1790 DROP TABLE IF EXISTS `serial`;
1791 CREATE TABLE `serial` (
1792   `serialid` int(11) NOT NULL auto_increment,
1793   `biblionumber` varchar(100) NOT NULL default '',
1794   `subscriptionid` varchar(100) NOT NULL default '',
1795   `serialseq` varchar(100) NOT NULL default '',
1796   `status` tinyint(4) NOT NULL default 0,
1797   `planneddate` date default NULL,
1798   `notes` text,
1799   `publisheddate` date default NULL,
1800   `itemnumber` text default NULL,
1801   `claimdate` date default NULL,
1802   `routingnotes` text,
1803   PRIMARY KEY  (`serialid`)
1804 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1805
1806 --
1807 -- Table structure for table `sessions`
1808 --
1809
1810 DROP TABLE IF EXISTS sessions;
1811 CREATE TABLE sessions (
1812   `id` varchar(32) NOT NULL,
1813   `a_session` text NOT NULL,
1814   PRIMARY KEY (`id`)
1815 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1816
1817 --
1818 -- Table structure for table `special_holidays`
1819 --
1820
1821 DROP TABLE IF EXISTS `special_holidays`;
1822 CREATE TABLE `special_holidays` ( -- non repeatable holidays/library closings
1823   `id` int(11) NOT NULL auto_increment, -- unique identifier assigned by Koha
1824   `branchcode` varchar(10) NOT NULL default '', -- foreign key from the branches table, defines which branch this closing is for
1825   `day` smallint(6) NOT NULL default 0, -- day of the month this closing is on
1826   `month` smallint(6) NOT NULL default 0, -- month this closing is in
1827   `year` smallint(6) NOT NULL default 0, -- year this closing is in
1828   `isexception` smallint(1) NOT NULL default 1, -- is this a holiday exception to a repeatable holiday (1 for yes, 0 for no)
1829   `title` varchar(50) NOT NULL default '', -- title for this closing
1830   `description` text NOT NULL, -- description of this closing
1831   PRIMARY KEY  (`id`)
1832 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1833
1834 --
1835 -- Table structure for table `statistics`
1836 --
1837
1838 DROP TABLE IF EXISTS `statistics`;
1839 CREATE TABLE `statistics` ( -- information related to transactions (circulation and fines) in Koha
1840   `datetime` datetime default NULL, -- date and time of the transaction
1841   `branch` varchar(10) default NULL, -- foreign key, branch where the transaction occurred
1842   `proccode` varchar(4) default NULL, -- proceedure code 
1843   `value` double(16,4) default NULL, -- monetary value associated with the transaction
1844   `type` varchar(16) default NULL, -- transaction type (locause, issue, return, renew, writeoff, payment, Credit*)
1845   `other` mediumtext,
1846   `usercode` varchar(10) default NULL,
1847   `itemnumber` int(11) default NULL, -- foreign key from the items table, links transaction to a specific item
1848   `itemtype` varchar(10) default NULL, -- foreign key from the itemtypes table, links transaction to a specific item type
1849   `borrowernumber` int(11) default NULL, -- foreign key from the borrowers table, links transaction to a specific borrower
1850   `associatedborrower` int(11) default NULL,
1851   KEY `timeidx` (`datetime`)
1852 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1853
1854 --
1855 -- Table structure for table `stopwords`
1856 --
1857
1858 DROP TABLE IF EXISTS `stopwords`;
1859   CREATE TABLE `stopwords` (
1860   `word` varchar(255) default NULL
1861 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1862
1863 --
1864 -- Table structure for table `subscription`
1865 --
1866
1867 DROP TABLE IF EXISTS `subscription`;
1868 CREATE TABLE `subscription` (
1869   `biblionumber` int(11) NOT NULL default 0,
1870   `subscriptionid` int(11) NOT NULL auto_increment,
1871   `librarian` varchar(100) default '',
1872   `startdate` date default NULL,
1873   `aqbooksellerid` int(11) default 0,
1874   `cost` int(11) default 0,
1875   `aqbudgetid` int(11) default 0,
1876   `weeklength` int(11) default 0,
1877   `monthlength` int(11) default 0,
1878   `numberlength` int(11) default 0,
1879   `periodicity` tinyint(4) default 0,
1880   `dow` varchar(100) default '',
1881   `numberingmethod` varchar(100) default '',
1882   `notes` mediumtext,
1883   `status` varchar(100) NOT NULL default '',
1884   `add1` int(11) default 0,
1885   `every1` int(11) default 0,
1886   `whenmorethan1` int(11) default 0,
1887   `setto1` int(11) default NULL,
1888   `lastvalue1` int(11) default NULL,
1889   `add2` int(11) default 0,
1890   `every2` int(11) default 0,
1891   `whenmorethan2` int(11) default 0,
1892   `setto2` int(11) default NULL,
1893   `lastvalue2` int(11) default NULL,
1894   `add3` int(11) default 0,
1895   `every3` int(11) default 0,
1896   `innerloop1` int(11) default 0,
1897   `innerloop2` int(11) default 0,
1898   `innerloop3` int(11) default 0,
1899   `whenmorethan3` int(11) default 0,
1900   `setto3` int(11) default NULL,
1901   `lastvalue3` int(11) default NULL,
1902   `issuesatonce` tinyint(3) NOT NULL default 1,
1903   `firstacquidate` date default NULL,
1904   `manualhistory` tinyint(1) NOT NULL default 0,
1905   `irregularity` text,
1906   `letter` varchar(20) default NULL,
1907   `numberpattern` tinyint(3) default 0,
1908   `distributedto` text,
1909   `internalnotes` longtext,
1910   `callnumber` text,
1911   `location` varchar(80) NULL default '',
1912   `branchcode` varchar(10) NOT NULL default '',
1913   `hemisphere` tinyint(3) default 0,
1914   `lastbranch` varchar(10),
1915   `serialsadditems` tinyint(1) NOT NULL default '0',
1916   `staffdisplaycount` VARCHAR(10) NULL,
1917   `opacdisplaycount` VARCHAR(10) NULL,
1918   `graceperiod` int(11) NOT NULL default '0',
1919   `enddate` date default NULL,
1920   PRIMARY KEY  (`subscriptionid`)
1921 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1922
1923 --
1924 -- Table structure for table `subscriptionhistory`
1925 --
1926
1927 DROP TABLE IF EXISTS `subscriptionhistory`;
1928 CREATE TABLE `subscriptionhistory` (
1929   `biblionumber` int(11) NOT NULL default 0,
1930   `subscriptionid` int(11) NOT NULL default 0,
1931   `histstartdate` date default NULL,
1932   `histenddate` date default NULL,
1933   `missinglist` longtext NOT NULL,
1934   `recievedlist` longtext NOT NULL,
1935   `opacnote` varchar(150) NOT NULL default '',
1936   `librariannote` varchar(150) NOT NULL default '',
1937   PRIMARY KEY  (`subscriptionid`),
1938   KEY `biblionumber` (`biblionumber`)
1939 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1940
1941 --
1942 -- Table structure for table `subscriptionroutinglist`
1943 --
1944
1945 DROP TABLE IF EXISTS `subscriptionroutinglist`;
1946 CREATE TABLE `subscriptionroutinglist` ( -- information related to the routing lists attached to subscriptions
1947   `routingid` int(11) NOT NULL auto_increment, -- unique identifier assigned by Koha
1948   `borrowernumber` int(11) NOT NULL, -- foreign key from the borrowers table, defines with patron is on the routing list
1949   `ranking` int(11) default NULL, -- where the patron stands in line to receive the serial
1950   `subscriptionid` int(11) NOT NULL, -- foreign key from the subscription table, defines which subscription this routing list is for
1951   PRIMARY KEY  (`routingid`),
1952   UNIQUE (`subscriptionid`, `borrowernumber`),
1953   CONSTRAINT `subscriptionroutinglist_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1954     ON DELETE CASCADE ON UPDATE CASCADE,
1955   CONSTRAINT `subscriptionroutinglist_ibfk_2` FOREIGN KEY (`subscriptionid`) REFERENCES `subscription` (`subscriptionid`)
1956     ON DELETE CASCADE ON UPDATE CASCADE
1957 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1958
1959 --
1960 -- Table structure for table `suggestions`
1961 --
1962
1963 DROP TABLE IF EXISTS `suggestions`;
1964 CREATE TABLE `suggestions` ( -- purchase suggestions
1965   `suggestionid` int(8) NOT NULL auto_increment, -- unique identifier assigned automatically by Koha
1966   `suggestedby` int(11) NOT NULL default 0, -- borrowernumber for the person making the suggestion, foreign key linking to the borrowers table
1967   `suggesteddate` date NOT NULL default 0, -- date the suggestion was submitted
1968   `managedby` int(11) default NULL, -- borrowernumber for the librarian managing the suggestion, foreign key linking to the borrowers table
1969   `manageddate` date default NULL, -- date the suggestion was updated
1970    acceptedby INT(11) default NULL, -- borrowernumber for the librarian who accepted the suggestion, foreign key linking to the borrowers table
1971    accepteddate date default NULL, -- date the suggestion was marked as accepted
1972    rejectedby INT(11) default NULL, -- borrowernumber for the librarian who rejected the suggestion, foreign key linking to the borrowers table
1973    rejecteddate date default NULL, -- date the suggestion was marked as rejected
1974   `STATUS` varchar(10) NOT NULL default '', -- suggestion status (ASKED, CHECKED, ACCEPTED, or REJECTED)
1975   `note` mediumtext, -- note entered on the suggestion
1976   `author` varchar(80) default NULL, -- author of the suggested item
1977   `title` varchar(80) default NULL, -- title of the suggested item
1978   `copyrightdate` smallint(6) default NULL, -- copyright date of the suggested item
1979   `publishercode` varchar(255) default NULL, -- publisher of the suggested item
1980   `date` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,  -- date and time the suggestion was updated
1981   `volumedesc` varchar(255) default NULL,
1982   `publicationyear` smallint(6) default 0,
1983   `place` varchar(255) default NULL, -- publication place of the suggested item
1984   `isbn` varchar(30) default NULL, -- isbn of the suggested item
1985   `mailoverseeing` smallint(1) default 0,
1986   `biblionumber` int(11) default NULL, -- foreign key linking the suggestion to the biblio table after the suggestion has been ordered
1987   `reason` text, -- reason for accepting or rejecting the suggestion
1988   `patronreason` text, -- reason for making the suggestion
1989    budgetid INT(11), -- foreign key linking the suggested budget to the aqbudgets table
1990    branchcode VARCHAR(10) default NULL, -- foreign key linking the suggested branch to the branches table
1991    collectiontitle text default NULL, -- collection name for the suggested item
1992    itemtype VARCHAR(30) default NULL, -- suggested item type 
1993         quantity SMALLINT(6) default NULL, -- suggested quantity to be purchased
1994         currency VARCHAR(3) default NULL, -- suggested currency for the suggested price
1995         price DECIMAL(28,6) default NULL, -- suggested price
1996         total DECIMAL(28,6) default NULL, -- suggested total cost (price*quantity updated for currency)
1997   PRIMARY KEY  (`suggestionid`),
1998   KEY `suggestedby` (`suggestedby`),
1999   KEY `managedby` (`managedby`)
2000 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2001
2002 --
2003 -- Table structure for table `systempreferences`
2004 --
2005
2006 DROP TABLE IF EXISTS `systempreferences`;
2007 CREATE TABLE `systempreferences` ( -- global system preferences
2008   `variable` varchar(50) NOT NULL default '', -- system preference name
2009   `value` text, -- system preference values
2010   `options` mediumtext, -- options for multiple choice system preferences
2011   `explanation` text, -- descriptive text for the system preference
2012   `type` varchar(20) default NULL, -- type of question this preference asks (multiple choice, plain text, yes or no, etc)
2013   PRIMARY KEY  (`variable`)
2014 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2015
2016 --
2017 -- Table structure for table `tags`
2018 --
2019
2020 DROP TABLE IF EXISTS `tags`;
2021 CREATE TABLE `tags` (
2022   `entry` varchar(255) NOT NULL default '',
2023   `weight` bigint(20) NOT NULL default 0,
2024   PRIMARY KEY  (`entry`)
2025 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2026
2027 --
2028 -- Table structure for table `tags_all`
2029 --
2030
2031 DROP TABLE IF EXISTS `tags_all`;
2032 CREATE TABLE `tags_all` ( -- all of the tags
2033   `tag_id`         int(11) NOT NULL auto_increment, -- unique id and primary key
2034   `borrowernumber` int(11) NOT NULL, -- the patron who added the tag (borrowers.borrowernumber)
2035   `biblionumber`   int(11) NOT NULL, -- the bib record this tag was left on (biblio.biblionumber)
2036   `term`      varchar(255) NOT NULL, -- the tag
2037   `language`       int(4) default NULL, -- the language the tag was left in
2038   `date_created` datetime  NOT NULL, -- the date the tag was added
2039   PRIMARY KEY  (`tag_id`),
2040   KEY `tags_borrowers_fk_1` (`borrowernumber`),
2041   KEY `tags_biblionumber_fk_1` (`biblionumber`),
2042   CONSTRAINT `tags_borrowers_fk_1` FOREIGN KEY (`borrowernumber`)
2043         REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2044   CONSTRAINT `tags_biblionumber_fk_1` FOREIGN KEY (`biblionumber`)
2045         REFERENCES `biblio`     (`biblionumber`)  ON DELETE CASCADE ON UPDATE CASCADE
2046 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2047
2048 --
2049 -- Table structure for table `tags_approval`
2050 --
2051
2052 DROP TABLE IF EXISTS `tags_approval`;
2053 CREATE TABLE `tags_approval` ( -- approved tags
2054   `term`   varchar(255) NOT NULL, -- the tag
2055   `approved`     int(1) NOT NULL default '0', -- whether the tag is approved or not (1=yes, 0=pending, -1=rejected)
2056   `date_approved` datetime       default NULL, -- the date this tag was approved
2057   `approved_by` int(11)          default NULL, -- the librarian who approved the tag (borrowers.borrowernumber)
2058   `weight_total` int(9) NOT NULL default '1', -- the total number of times this tag was used
2059   PRIMARY KEY  (`term`),
2060   KEY `tags_approval_borrowers_fk_1` (`approved_by`),
2061   CONSTRAINT `tags_approval_borrowers_fk_1` FOREIGN KEY (`approved_by`)
2062         REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
2063 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2064
2065 --
2066 -- Table structure for table `tags_index`
2067 --
2068
2069 DROP TABLE IF EXISTS `tags_index`;
2070 CREATE TABLE `tags_index` ( -- a weighted list of all tags and where they are used
2071   `term`    varchar(255) NOT NULL, -- the tag
2072   `biblionumber` int(11) NOT NULL, -- the bib record this tag was used on (biblio.biblionumber)
2073   `weight`        int(9) NOT NULL default '1', -- the number of times this term was used on this bib record
2074   PRIMARY KEY  (`term`,`biblionumber`),
2075   KEY `tags_index_biblionumber_fk_1` (`biblionumber`),
2076   CONSTRAINT `tags_index_term_fk_1` FOREIGN KEY (`term`)
2077         REFERENCES `tags_approval` (`term`)  ON DELETE CASCADE ON UPDATE CASCADE,
2078   CONSTRAINT `tags_index_biblionumber_fk_1` FOREIGN KEY (`biblionumber`)
2079         REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
2080 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2081
2082 --
2083 -- Table structure for table `userflags`
2084 --
2085
2086 DROP TABLE IF EXISTS `userflags`;
2087 CREATE TABLE `userflags` (
2088   `bit` int(11) NOT NULL default 0,
2089   `flag` varchar(30) default NULL,
2090   `flagdesc` varchar(255) default NULL,
2091   `defaulton` int(11) default NULL,
2092   PRIMARY KEY  (`bit`)
2093 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2094
2095 --
2096 -- Table structure for table `virtualshelves`
2097 --
2098
2099 DROP TABLE IF EXISTS `virtualshelves`;
2100 CREATE TABLE `virtualshelves` ( -- information about lists (or virtual shelves) 
2101   `shelfnumber` int(11) NOT NULL auto_increment, -- unique identifier assigned by Koha
2102   `shelfname` varchar(255) default NULL, -- name of the list
2103   `owner` int default NULL, -- foreign key linking to the borrowers table (using borrowernumber) for the creator of this list (changed from varchar(80) to int)
2104   `category` varchar(1) default NULL, -- type of list (private [1], public [2])
2105   `sortfield` varchar(16) default NULL, -- the field this list is sorted on
2106   `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- date and time the list was last modified
2107   `allow_add` tinyint(1) default 0, -- permission for adding entries to list
2108   `allow_delete_own` tinyint(1) default 1, -- permission for deleting entries frm list that you added yourself
2109   `allow_delete_other` tinyint(1) default 0, -- permission for deleting entries from list that another person added
2110   PRIMARY KEY  (`shelfnumber`),
2111   CONSTRAINT `virtualshelves_ibfk_1` FOREIGN KEY (`owner`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE SET NULL -- no cascaded delete, please see HandleDelBorrower in VirtualShelves.pm
2112 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2113
2114 --
2115 -- Table structure for table `virtualshelfcontents`
2116 --
2117
2118 DROP TABLE IF EXISTS `virtualshelfcontents`;
2119 CREATE TABLE `virtualshelfcontents` ( -- information about the titles in a list (or virtual shelf)
2120   `shelfnumber` int(11) NOT NULL default 0, -- foreign key linking to the virtualshelves table, defines the list that this record has been added to
2121   `biblionumber` int(11) NOT NULL default 0, -- foreign key linking to the biblio table, defines the bib record that has been added to the list
2122   `flags` int(11) default NULL,
2123   `dateadded` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, -- date and time this bib record was added to the list
2124   `borrowernumber` int, -- borrower number that created this list entry (only the first one is saved: no need for use in/as key)
2125   KEY `shelfnumber` (`shelfnumber`),
2126   KEY `biblionumber` (`biblionumber`),
2127   CONSTRAINT `virtualshelfcontents_ibfk_1` FOREIGN KEY (`shelfnumber`) REFERENCES `virtualshelves` (`shelfnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2128   CONSTRAINT `shelfcontents_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2129   CONSTRAINT `shelfcontents_ibfk_3` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE SET NULL -- no cascaded delete, please see HandleDelBorrower in VirtualShelves.pm
2130 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2131
2132 --
2133 -- Table structure for table `virtualshelfshares`
2134 --
2135
2136 DROP TABLE IF EXISTS `virtualshelfshares`;
2137 CREATE TABLE `virtualshelfshares` ( -- shared private lists
2138   `id` int AUTO_INCREMENT PRIMARY KEY,  -- unique key
2139   `shelfnumber` int NOT NULL,  -- foreign key for virtualshelves
2140   `borrowernumber` int,  -- borrower that accepted access to this list
2141   `invitekey` varchar(10), -- temporary string used in accepting the invitation to access thist list; not-empty means that the invitation has not been accepted yet
2142   `sharedate` datetime,  -- date of invitation or acceptance of invitation
2143   CONSTRAINT `virtualshelfshares_ibfk_1` FOREIGN KEY (`shelfnumber`) REFERENCES `virtualshelves` (`shelfnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2144   CONSTRAINT `virtualshelfshares_ibfk_2` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE SET NULL -- no cascaded delete, please see HandleDelBorrower in VirtualShelves.pm
2145 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2146
2147 --
2148 -- Table structure for table `z3950servers`
2149 --
2150
2151 DROP TABLE IF EXISTS `z3950servers`;
2152 CREATE TABLE `z3950servers` ( -- connection information for the Z39.50 targets used in cataloging
2153   `host` varchar(255) default NULL, -- target's host name
2154   `port` int(11) default NULL, -- port number used to connect to target
2155   `db` varchar(255) default NULL, -- target's database name
2156   `userid` varchar(255) default NULL, -- username needed to log in to target
2157   `password` varchar(255) default NULL, -- password needed to log in to target
2158   `name` mediumtext, -- name given to the target by the library
2159   `id` int(11) NOT NULL auto_increment, -- unique identifier assigned by Koha
2160   `checked` smallint(6) default NULL, -- whether this target is checked by default  (1 for yes, 0 for no)
2161   `rank` int(11) default NULL, -- where this target appears in the list of targets
2162   `syntax` varchar(80) default NULL, -- marc format provided by this target
2163   `timeout` int(11) NOT NULL DEFAULT '0', -- number of seconds before Koha stops trying to access this server
2164   `icon` text, -- unused in Koha
2165   `position` enum('primary','secondary','') NOT NULL default 'primary',
2166   `type` enum('zed','opensearch') NOT NULL default 'zed',
2167   `encoding` text default NULL, -- characters encoding provided by this target
2168   `description` text NOT NULL, -- unused in Koha
2169   PRIMARY KEY  (`id`)
2170 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2171
2172 --
2173 -- Table structure for table `zebraqueue`
2174 --
2175
2176 DROP TABLE IF EXISTS `zebraqueue`;
2177 CREATE TABLE `zebraqueue` (
2178   `id` int(11) NOT NULL auto_increment,
2179   `biblio_auth_number` bigint(20) unsigned NOT NULL default '0',
2180   `operation` char(20) NOT NULL default '',
2181   `server` char(20) NOT NULL default '',
2182   `done` int(11) NOT NULL default '0',
2183   `time` timestamp NOT NULL default CURRENT_TIMESTAMP,
2184   PRIMARY KEY  (`id`),
2185   KEY `zebraqueue_lookup` (`server`, `biblio_auth_number`, `operation`, `done`)
2186 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2187
2188 --
2189 -- Table structure for table `services_throttle`
2190 --
2191
2192 DROP TABLE IF EXISTS `services_throttle`;
2193 CREATE TABLE `services_throttle` (
2194   `service_type` varchar(10) NOT NULL default '',
2195   `service_count` varchar(45) default NULL,
2196   PRIMARY KEY  (`service_type`)
2197 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2198
2199 --
2200 -- Table structure for table `language_subtag_registry`
2201 -- http://www.w3.org/International/articles/language-tags/
2202 -- RFC4646
2203 --
2204
2205 DROP TABLE IF EXISTS language_subtag_registry;
2206 CREATE TABLE language_subtag_registry (
2207         subtag varchar(25),
2208         type varchar(25), -- language-script-region-variant-extension-privateuse
2209         description varchar(25), -- only one of the possible descriptions for ease of reference, see language_descriptions for the complete list
2210         added date,
2211         id int(11) NOT NULL auto_increment,
2212         PRIMARY KEY  (`id`),
2213         KEY `subtag` (`subtag`)
2214 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2215
2216 --
2217 -- Table structure for table `language_rfc4646_to_iso639`
2218 -- TODO: add suppress_scripts
2219 -- this maps three letter codes defined in iso639.2 back to their
2220 -- two letter equivilents in rfc4646 (LOC maintains iso639+)
2221 --
2222
2223 DROP TABLE IF EXISTS language_rfc4646_to_iso639;
2224 CREATE TABLE language_rfc4646_to_iso639 (
2225         rfc4646_subtag varchar(25),
2226         iso639_2_code varchar(25),
2227         id int(11) NOT NULL auto_increment,
2228         PRIMARY KEY  (`id`),
2229         KEY `rfc4646_subtag` (`rfc4646_subtag`)
2230 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2231
2232 --
2233 -- Table structure for table `language_descriptions`
2234 --
2235
2236 DROP TABLE IF EXISTS language_descriptions;
2237 CREATE TABLE language_descriptions (
2238         subtag varchar(25),
2239         type varchar(25),
2240         lang varchar(25),
2241         description varchar(255),
2242         id int(11) NOT NULL auto_increment,
2243         PRIMARY KEY  (`id`),
2244         KEY `lang` (`lang`),
2245         KEY `subtag_type_lang` (`subtag`, `type`, `lang`)
2246 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2247
2248 --
2249 -- Table structure for table `language_script_bidi`
2250 -- bi-directional support, keyed by script subcode
2251 --
2252
2253 DROP TABLE IF EXISTS language_script_bidi;
2254 CREATE TABLE language_script_bidi (
2255         rfc4646_subtag varchar(25), -- script subtag, Arab, Hebr, etc.
2256         bidi varchar(3), -- rtl ltr
2257         KEY `rfc4646_subtag` (`rfc4646_subtag`)
2258 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2259
2260 --
2261 -- Table structure for table `language_script_mapping`
2262 -- TODO: need to map language subtags to script subtags for detection
2263 -- of bidi when script is not specified (like ar, he)
2264 --
2265
2266 DROP TABLE IF EXISTS language_script_mapping;
2267 CREATE TABLE language_script_mapping (
2268         language_subtag varchar(25),
2269         script_subtag varchar(25),
2270         KEY `language_subtag` (`language_subtag`)
2271 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2272
2273 --
2274 -- Table structure for table `permissions`
2275 --
2276
2277 DROP TABLE IF EXISTS `permissions`;
2278 CREATE TABLE `permissions` (
2279   `module_bit` int(11) NOT NULL DEFAULT 0,
2280   `code` varchar(64) DEFAULT NULL,
2281   `description` varchar(255) DEFAULT NULL,
2282   PRIMARY KEY  (`module_bit`, `code`),
2283   CONSTRAINT `permissions_ibfk_1` FOREIGN KEY (`module_bit`) REFERENCES `userflags` (`bit`)
2284     ON DELETE CASCADE ON UPDATE CASCADE
2285 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2286
2287 --
2288 -- Table structure for table `serialitems`
2289 --
2290
2291 DROP TABLE IF EXISTS `serialitems`;
2292 CREATE TABLE `serialitems` (
2293         `itemnumber` int(11) NOT NULL,
2294         `serialid` int(11) NOT NULL,
2295         UNIQUE KEY `serialitemsidx` (`itemnumber`),
2296         KEY `serialitems_sfk_1` (`serialid`),
2297         CONSTRAINT `serialitems_sfk_1` FOREIGN KEY (`serialid`) REFERENCES `serial` (`serialid`) ON DELETE CASCADE ON UPDATE CASCADE,
2298         CONSTRAINT `serialitems_sfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE
2299 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2300
2301 --
2302 -- Table structure for table `user_permissions`
2303 --
2304
2305 DROP TABLE IF EXISTS `user_permissions`;
2306 CREATE TABLE `user_permissions` (
2307   `borrowernumber` int(11) NOT NULL DEFAULT 0,
2308   `module_bit` int(11) NOT NULL DEFAULT 0,
2309   `code` varchar(64) DEFAULT NULL,
2310   CONSTRAINT `user_permissions_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
2311     ON DELETE CASCADE ON UPDATE CASCADE,
2312   CONSTRAINT `user_permissions_ibfk_2` FOREIGN KEY (`module_bit`, `code`) REFERENCES `permissions` (`module_bit`, `code`)
2313     ON DELETE CASCADE ON UPDATE CASCADE
2314 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2315
2316 --
2317 -- Table structure for table `tmp_holdsqueue`
2318 --
2319
2320 DROP TABLE IF EXISTS `tmp_holdsqueue`;
2321 CREATE TABLE `tmp_holdsqueue` (
2322   `biblionumber` int(11) default NULL,
2323   `itemnumber` int(11) default NULL,
2324   `barcode` varchar(20) default NULL,
2325   `surname` mediumtext NOT NULL,
2326   `firstname` text,
2327   `phone` text,
2328   `borrowernumber` int(11) NOT NULL,
2329   `cardnumber` varchar(16) default NULL,
2330   `reservedate` date default NULL,
2331   `title` mediumtext,
2332   `itemcallnumber` varchar(255) default NULL,
2333   `holdingbranch` varchar(10) default NULL,
2334   `pickbranch` varchar(10) default NULL,
2335   `notes` text,
2336   `item_level_request` tinyint(4) NOT NULL default 0
2337 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2338
2339 --
2340 -- Table structure for table `message_queue`
2341 --
2342
2343 DROP TABLE IF EXISTS `message_queue`;
2344 CREATE TABLE `message_queue` (
2345   `message_id` int(11) NOT NULL auto_increment,
2346   `borrowernumber` int(11) default NULL,
2347   `subject` text,
2348   `content` text,
2349   `metadata` text DEFAULT NULL,
2350   `letter_code` varchar(64) DEFAULT NULL,
2351   `message_transport_type` varchar(20) NOT NULL,
2352   `status` enum('sent','pending','failed','deleted') NOT NULL default 'pending',
2353   `time_queued` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
2354   `to_address` mediumtext,
2355   `from_address` mediumtext,
2356   `content_type` text,
2357   KEY `message_id` (`message_id`),
2358   KEY `borrowernumber` (`borrowernumber`),
2359   KEY `message_transport_type` (`message_transport_type`),
2360   CONSTRAINT `messageq_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2361   CONSTRAINT `messageq_ibfk_2` FOREIGN KEY (`message_transport_type`) REFERENCES `message_transport_types` (`message_transport_type`) ON DELETE RESTRICT ON UPDATE CASCADE
2362 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2363
2364 --
2365 -- Table structure for table `message_transport_types`
2366 --
2367
2368 DROP TABLE IF EXISTS `message_transport_types`;
2369 CREATE TABLE `message_transport_types` (
2370   `message_transport_type` varchar(20) NOT NULL,
2371   PRIMARY KEY  (`message_transport_type`)
2372 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2373
2374 --
2375 -- Table structure for table `message_attributes`
2376 --
2377
2378 DROP TABLE IF EXISTS `message_attributes`;
2379 CREATE TABLE `message_attributes` (
2380   `message_attribute_id` int(11) NOT NULL auto_increment,
2381   `message_name` varchar(40) NOT NULL default '',
2382   `takes_days` tinyint(1) NOT NULL default '0',
2383   PRIMARY KEY  (`message_attribute_id`),
2384   UNIQUE KEY `message_name` (`message_name`)
2385 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2386
2387 --
2388 -- Table structure for table `message_transports`
2389 --
2390
2391 DROP TABLE IF EXISTS `message_transports`;
2392 CREATE TABLE `message_transports` (
2393   `message_attribute_id` int(11) NOT NULL,
2394   `message_transport_type` varchar(20) NOT NULL,
2395   `is_digest` tinyint(1) NOT NULL default '0',
2396   `letter_module` varchar(20) NOT NULL default '',
2397   `letter_code` varchar(20) NOT NULL default '',
2398   `branchcode` varchar(10) NOT NULL default '',
2399   PRIMARY KEY  (`message_attribute_id`,`message_transport_type`,`is_digest`),
2400   KEY `message_transport_type` (`message_transport_type`),
2401   KEY `letter_module` (`letter_module`,`letter_code`),
2402   CONSTRAINT `message_transports_ibfk_1` FOREIGN KEY (`message_attribute_id`) REFERENCES `message_attributes` (`message_attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE,
2403   CONSTRAINT `message_transports_ibfk_2` FOREIGN KEY (`message_transport_type`) REFERENCES `message_transport_types` (`message_transport_type`) ON DELETE CASCADE ON UPDATE CASCADE,
2404   CONSTRAINT `message_transports_ibfk_3` FOREIGN KEY (`letter_module`, `letter_code`, `branchcode`) REFERENCES `letter` (`module`, `code`, `branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
2405 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2406
2407 --
2408 -- Table structure for table `borrower_message_preferences`
2409 --
2410
2411 DROP TABLE IF EXISTS `borrower_message_preferences`;
2412 CREATE TABLE `borrower_message_preferences` (
2413   `borrower_message_preference_id` int(11) NOT NULL auto_increment,
2414   `borrowernumber` int(11) default NULL,
2415   `categorycode` varchar(10) default NULL,
2416   `message_attribute_id` int(11) default '0',
2417   `days_in_advance` int(11) default '0',
2418   `wants_digest` tinyint(1) NOT NULL default '0',
2419   PRIMARY KEY  (`borrower_message_preference_id`),
2420   KEY `borrowernumber` (`borrowernumber`),
2421   KEY `categorycode` (`categorycode`),
2422   KEY `message_attribute_id` (`message_attribute_id`),
2423   CONSTRAINT `borrower_message_preferences_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2424   CONSTRAINT `borrower_message_preferences_ibfk_2` FOREIGN KEY (`message_attribute_id`) REFERENCES `message_attributes` (`message_attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE,
2425   CONSTRAINT `borrower_message_preferences_ibfk_3` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) ON DELETE CASCADE ON UPDATE CASCADE
2426 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2427
2428 --
2429 -- Table structure for table `borrower_message_transport_preferences`
2430 --
2431
2432 DROP TABLE IF EXISTS `borrower_message_transport_preferences`;
2433 CREATE TABLE `borrower_message_transport_preferences` (
2434   `borrower_message_preference_id` int(11) NOT NULL default '0',
2435   `message_transport_type` varchar(20) NOT NULL default '0',
2436   PRIMARY KEY  (`borrower_message_preference_id`,`message_transport_type`),
2437   KEY `message_transport_type` (`message_transport_type`),
2438   CONSTRAINT `borrower_message_transport_preferences_ibfk_1` FOREIGN KEY (`borrower_message_preference_id`) REFERENCES `borrower_message_preferences` (`borrower_message_preference_id`) ON DELETE CASCADE ON UPDATE CASCADE,
2439   CONSTRAINT `borrower_message_transport_preferences_ibfk_2` FOREIGN KEY (`message_transport_type`) REFERENCES `message_transport_types` (`message_transport_type`) ON DELETE CASCADE ON UPDATE CASCADE
2440 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2441
2442 --
2443 -- Table structure for the table branch_transfer_limits
2444 --
2445
2446 DROP TABLE IF EXISTS `branch_transfer_limits`;
2447 CREATE TABLE branch_transfer_limits (
2448     limitId int(8) NOT NULL auto_increment,
2449     toBranch varchar(10) NOT NULL,
2450     fromBranch varchar(10) NOT NULL,
2451     itemtype varchar(10) NULL,
2452     ccode varchar(10) NULL,
2453     PRIMARY KEY  (limitId)
2454 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2455
2456 --
2457 -- Table structure for table `item_circulation_alert_preferences`
2458 --
2459
2460 DROP TABLE IF EXISTS `item_circulation_alert_preferences`;
2461 CREATE TABLE `item_circulation_alert_preferences` (
2462   `id` int(11) NOT NULL auto_increment,
2463   `branchcode` varchar(10) NOT NULL,
2464   `categorycode` varchar(10) NOT NULL,
2465   `item_type` varchar(10) NOT NULL,
2466   `notification` varchar(16) NOT NULL,
2467   PRIMARY KEY  (`id`),
2468   KEY `branchcode` (`branchcode`,`categorycode`,`item_type`, `notification`)
2469 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2470
2471 --
2472 -- Table structure for table `messages`
2473 --
2474 DROP TABLE IF EXISTS `messages`;
2475 CREATE TABLE `messages` ( -- circulation messages left via the patron's check out screen
2476   `message_id` int(11) NOT NULL auto_increment, -- unique identifier assigned by Koha
2477   `borrowernumber` int(11) NOT NULL, -- foreign key linking this message to the borrowers table
2478   `branchcode` varchar(10) default NULL, -- foreign key linking the message to the branches table
2479   `message_type` varchar(1) NOT NULL, -- whether the message is for the librarians (L) or the patron (B)
2480   `message` text NOT NULL, -- the text of the message
2481   `message_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- the date and time the message was written
2482   PRIMARY KEY (`message_id`)
2483 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2484
2485 --
2486 -- Table structure for table `accountlines`
2487 --
2488
2489 DROP TABLE IF EXISTS `accountlines`;
2490 CREATE TABLE `accountlines` (
2491   `accountlines_id` int(11) NOT NULL AUTO_INCREMENT,
2492   `borrowernumber` int(11) NOT NULL default 0,
2493   `accountno` smallint(6) NOT NULL default 0,
2494   `itemnumber` int(11) default NULL,
2495   `date` date default NULL,
2496   `amount` decimal(28,6) default NULL,
2497   `description` mediumtext,
2498   `dispute` mediumtext,
2499   `accounttype` varchar(5) default NULL,
2500   `amountoutstanding` decimal(28,6) default NULL,
2501   `lastincrement` decimal(28,6) default NULL,
2502   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
2503   `notify_id` int(11) NOT NULL default 0,
2504   `notify_level` int(2) NOT NULL default 0,
2505   `note` text NULL default NULL,
2506   `manager_id` int(11) NULL,
2507   PRIMARY KEY (`accountlines_id`),
2508   KEY `acctsborridx` (`borrowernumber`),
2509   KEY `timeidx` (`timestamp`),
2510   KEY `itemnumber` (`itemnumber`),
2511   CONSTRAINT `accountlines_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2512   CONSTRAINT `accountlines_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE SET NULL ON UPDATE SET NULL
2513 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2514
2515 --
2516 -- Table structure for table `accountoffsets`
2517 --
2518
2519 DROP TABLE IF EXISTS `accountoffsets`;
2520 CREATE TABLE `accountoffsets` (
2521   `borrowernumber` int(11) NOT NULL default 0,
2522   `accountno` smallint(6) NOT NULL default 0,
2523   `offsetaccount` smallint(6) NOT NULL default 0,
2524   `offsetamount` decimal(28,6) default NULL,
2525   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
2526   CONSTRAINT `accountoffsets_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
2527 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2528
2529 --
2530 -- Table structure for table `action_logs`
2531 --
2532
2533 DROP TABLE IF EXISTS `action_logs`;
2534 CREATE TABLE `action_logs` ( -- logs of actions taken in Koha (requires that the logs be turned on)
2535   `action_id` int(11) NOT NULL auto_increment, -- unique identifier for each action
2536   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- the date and time the action took place
2537   `user` int(11) NOT NULL default 0, -- the staff member who performed the action (borrowers.borrowernumber)
2538   `module` text, -- the module this action was taken against
2539   `action` text, -- the action (includes things like DELETED, ADDED, MODIFY, etc)
2540   `object` int(11) default NULL, -- the object that the action was taken against (could be a borrowernumber, itemnumber, etc)
2541   `info` text, -- information about the action (usually includes SQL statement)
2542   PRIMARY KEY (`action_id`),
2543   KEY  (`timestamp`,`user`)
2544 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2545
2546 --
2547 -- Table structure for table `alert`
2548 --
2549
2550 DROP TABLE IF EXISTS `alert`;
2551 CREATE TABLE `alert` (
2552   `alertid` int(11) NOT NULL auto_increment,
2553   `borrowernumber` int(11) NOT NULL default 0,
2554   `type` varchar(10) NOT NULL default '',
2555   `externalid` varchar(20) NOT NULL default '',
2556   PRIMARY KEY  (`alertid`),
2557   KEY `borrowernumber` (`borrowernumber`),
2558   KEY `type` (`type`,`externalid`)
2559 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2560
2561 --
2562 -- Table structure for table `aqbasketgroups`
2563 --
2564
2565 DROP TABLE IF EXISTS `aqbasketgroups`;
2566 CREATE TABLE `aqbasketgroups` (
2567   `id` int(11) NOT NULL auto_increment,
2568   `name` varchar(50) default NULL,
2569   `closed` tinyint(1) default NULL,
2570   `booksellerid` int(11) NOT NULL,
2571   `deliveryplace` varchar(10) default NULL,
2572   `freedeliveryplace` text default NULL,
2573   `deliverycomment` varchar(255) default NULL,
2574   `billingplace` varchar(10) default NULL,
2575   PRIMARY KEY  (`id`),
2576   KEY `booksellerid` (`booksellerid`),
2577   CONSTRAINT `aqbasketgroups_ibfk_1` FOREIGN KEY (`booksellerid`) REFERENCES `aqbooksellers` (`id`) ON UPDATE CASCADE ON DELETE CASCADE
2578 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2579
2580 --
2581 -- Table structure for table `aqbasket`
2582 --
2583
2584 DROP TABLE IF EXISTS `aqbasket`;
2585 CREATE TABLE `aqbasket` ( -- stores data about baskets in acquisitions
2586   `basketno` int(11) NOT NULL auto_increment, -- primary key, Koha defined number
2587   `basketname` varchar(50) default NULL, -- name given to the basket at creation
2588   `note` mediumtext, -- the internal note added at basket creation
2589   `booksellernote` mediumtext, -- the vendor note added at basket creation
2590   `contractnumber` int(11), -- links this basket to the aqcontract table (aqcontract.contractnumber)
2591   `creationdate` date default NULL, -- the date the basket was created
2592   `closedate` date default NULL, -- the date the basket was closed
2593   `booksellerid` int(11) NOT NULL default 1, -- the Koha assigned ID for the vendor (aqbooksellers.id)
2594   `authorisedby` varchar(10) default NULL, -- the borrowernumber of the person who created the basket
2595   `booksellerinvoicenumber` mediumtext, -- appears to always be NULL
2596   `basketgroupid` int(11), -- links this basket to its group (aqbasketgroups.id)
2597   `deliveryplace` varchar(10) default NULL, -- basket delivery place
2598   `billingplace` varchar(10) default NULL, -- basket billing place
2599   PRIMARY KEY  (`basketno`),
2600   KEY `booksellerid` (`booksellerid`),
2601   KEY `basketgroupid` (`basketgroupid`),
2602   KEY `contractnumber` (`contractnumber`),
2603   CONSTRAINT `aqbasket_ibfk_1` FOREIGN KEY (`booksellerid`) REFERENCES `aqbooksellers` (`id`) ON UPDATE CASCADE,
2604   CONSTRAINT `aqbasket_ibfk_2` FOREIGN KEY (`contractnumber`) REFERENCES `aqcontract` (`contractnumber`),
2605   CONSTRAINT `aqbasket_ibfk_3` FOREIGN KEY (`basketgroupid`) REFERENCES `aqbasketgroups` (`id`) ON UPDATE CASCADE
2606 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2607
2608 --
2609 -- Table structure for table `aqbooksellers`
2610 --
2611
2612 DROP TABLE IF EXISTS `aqbooksellers`;
2613 CREATE TABLE `aqbooksellers` ( -- information about the vendors listed in acquisitions
2614   `id` int(11) NOT NULL auto_increment, -- primary key and unique identifier assigned by Koha
2615   `name` mediumtext NOT NULL, -- vendor name
2616   `address1` mediumtext, -- first line of vendor physical address
2617   `address2` mediumtext, -- second line of vendor physical address
2618   `address3` mediumtext, -- third line of vendor physical address
2619   `address4` mediumtext, -- fourth line of vendor physical address
2620   `phone` varchar(30) default NULL, -- vendor phone number
2621   `accountnumber` mediumtext, -- unused in Koha
2622   `othersupplier` mediumtext,  -- unused in Koha
2623   `currency` varchar(3) NOT NULL default '', -- unused in Koha
2624   `booksellerfax` mediumtext, -- vendor fax number
2625   `notes` mediumtext, -- order notes
2626   `bookselleremail` mediumtext, -- vendor email
2627   `booksellerurl` mediumtext, -- unused in Koha
2628   `contact` varchar(100) default NULL, -- name of contact at vendor
2629   `postal` mediumtext, -- vendor postal address (all lines)
2630   `url` varchar(255) default NULL, -- vendor web address
2631   `contpos` varchar(100) default NULL, -- contact person's position
2632   `contphone` varchar(100) default NULL, -- contact's phone number
2633   `contfax` varchar(100) default NULL,  -- contact's fax number
2634   `contaltphone` varchar(100) default NULL, -- contact's alternate phone number
2635   `contemail` varchar(100) default NULL, -- contact's email address
2636   `contnotes` mediumtext, -- notes related to the contact
2637   `active` tinyint(4) default NULL, -- is this vendor active (1 for yes, 0 for no)
2638   `listprice` varchar(10) default NULL, -- currency code for list prices
2639   `invoiceprice` varchar(10) default NULL, -- currency code for invoice prices
2640   `gstreg` tinyint(4) default NULL, -- is your library charged tax (1 for yes, 0 for no)
2641   `listincgst` tinyint(4) default NULL, -- is tax included in list prices (1 for yes, 0 for no)
2642   `invoiceincgst` tinyint(4) default NULL, -- is tax included in invoice prices (1 for yes, 0 for no)
2643   `gstrate` decimal(6,4) default NULL, -- the tax rate the library is charged
2644   `discount` float(6,4) default NULL, -- discount offered on all items ordered from this vendor
2645   `fax` varchar(50) default NULL, -- vendor fax number
2646   deliverytime int(11) default NULL, -- vendor delivery time
2647   PRIMARY KEY  (`id`),
2648   KEY `listprice` (`listprice`),
2649   KEY `invoiceprice` (`invoiceprice`),
2650   CONSTRAINT `aqbooksellers_ibfk_1` FOREIGN KEY (`listprice`) REFERENCES `currency` (`currency`) ON DELETE CASCADE ON UPDATE CASCADE,
2651   CONSTRAINT `aqbooksellers_ibfk_2` FOREIGN KEY (`invoiceprice`) REFERENCES `currency` (`currency`) ON DELETE CASCADE ON UPDATE CASCADE
2652 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2653
2654 --
2655 -- Table structure for table `aqbudgets`
2656 --
2657
2658 DROP TABLE IF EXISTS `aqbudgets`;
2659 CREATE TABLE `aqbudgets` ( -- information related to Funds
2660   `budget_id` int(11) NOT NULL auto_increment, -- primary key and unique number assigned to each fund by Koha
2661   `budget_parent_id` int(11) default NULL, -- if this fund is a child of another this will include the parent id (aqbudgets.budget_id)
2662   `budget_code` varchar(30) default NULL, -- code assigned to the fund by the user
2663   `budget_name` varchar(80) default NULL, -- name assigned to the fund by the user
2664   `budget_branchcode` varchar(10) default NULL, -- branch that this fund belongs to (branches.branchcode)
2665   `budget_amount` decimal(28,6) NULL default '0.00', -- total amount for this fund
2666   `budget_encumb` decimal(28,6) NULL default '0.00', -- not used in the code
2667   `budget_expend` decimal(28,6) NULL default '0.00', -- not used in the code
2668   `budget_notes` mediumtext, -- notes related to this fund
2669   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- date and time this fund was last touched (created or modified)
2670   `budget_period_id` int(11) default NULL, -- id of the budget that this fund belongs to (aqbudgetperiods.budget_period_id)
2671   `sort1_authcat` varchar(80) default NULL, -- statistical category for this fund
2672   `sort2_authcat` varchar(80) default NULL, -- second statistical category for this fund
2673   `budget_owner_id` int(11) default NULL, -- borrowernumber of the person who owns this fund (borrowers.borrowernumber)
2674   `budget_permission` int(1) default '0', -- level of permission for this fund (used only by the owner, only by the library, or anyone)
2675   PRIMARY KEY  (`budget_id`)
2676 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2677
2678 --
2679 -- Table structure for table aqbudgetborrowers
2680 --
2681
2682 DROP TABLE IF EXISTS aqbudgetborrowers;
2683 CREATE TABLE aqbudgetborrowers (
2684   budget_id int(11) NOT NULL,
2685   borrowernumber int(11) NOT NULL,
2686   PRIMARY KEY (budget_id, borrowernumber),
2687   CONSTRAINT aqbudgetborrowers_ibfk_1 FOREIGN KEY (budget_id)
2688     REFERENCES aqbudgets (budget_id)
2689     ON DELETE CASCADE ON UPDATE CASCADE,
2690   CONSTRAINT aqbudgetborrowers_ibfk_2 FOREIGN KEY (borrowernumber)
2691     REFERENCES borrowers (borrowernumber)
2692     ON DELETE CASCADE ON UPDATE CASCADE
2693 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2694
2695 --
2696 -- Table structure for table `aqbudgetperiods`
2697 --
2698
2699
2700 DROP TABLE IF EXISTS `aqbudgetperiods`;
2701 CREATE TABLE `aqbudgetperiods` ( -- information related to Budgets
2702   `budget_period_id` int(11) NOT NULL auto_increment, -- primary key and unique number assigned by Koha
2703   `budget_period_startdate` date NOT NULL, -- date when the budget starts
2704   `budget_period_enddate` date NOT NULL, -- date when the budget ends
2705   `budget_period_active` tinyint(1) default '0', -- whether this budget is active or not (1 for yes, 0 for no)
2706   `budget_period_description` mediumtext, -- description assigned to this budget
2707   `budget_period_total` decimal(28,6), -- total amount available in this budget
2708   `budget_period_locked` tinyint(1) default NULL, -- whether this budget is locked or not (1 for yes, 0 for no)
2709   `sort1_authcat` varchar(10) default NULL, -- statistical category for this budget
2710   `sort2_authcat` varchar(10) default NULL, -- second statistical category for this budget
2711   PRIMARY KEY  (`budget_period_id`)
2712 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2713
2714 --
2715 -- Table structure for table `aqbudgets_planning`
2716 --
2717
2718 DROP TABLE IF EXISTS `aqbudgets_planning`;
2719 CREATE TABLE `aqbudgets_planning` (
2720   `plan_id` int(11) NOT NULL auto_increment,
2721   `budget_id` int(11) NOT NULL,
2722   `budget_period_id` int(11) NOT NULL,
2723   `estimated_amount` decimal(28,6) default NULL,
2724   `authcat` varchar(30) NOT NULL,
2725   `authvalue` varchar(30) NOT NULL,
2726   `display` tinyint(1) DEFAULT 1,
2727   PRIMARY KEY  (`plan_id`),
2728   CONSTRAINT `aqbudgets_planning_ifbk_1` FOREIGN KEY (`budget_id`) REFERENCES `aqbudgets` (`budget_id`) ON DELETE CASCADE ON UPDATE CASCADE
2729 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2730
2731 --
2732 -- Table structure for table 'aqcontract'
2733 --
2734
2735 DROP TABLE IF EXISTS `aqcontract`;
2736 CREATE TABLE `aqcontract` (
2737   `contractnumber` int(11) NOT NULL auto_increment,
2738   `contractstartdate` date default NULL,
2739   `contractenddate` date default NULL,
2740   `contractname` varchar(50) default NULL,
2741   `contractdescription` mediumtext,
2742   `booksellerid` int(11) not NULL,
2743   PRIMARY KEY  (`contractnumber`),
2744   CONSTRAINT `booksellerid_fk1` FOREIGN KEY (`booksellerid`)
2745        REFERENCES `aqbooksellers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
2746 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
2747
2748 --
2749 -- Table structure for table `aqorderdelivery`
2750 --
2751
2752 DROP TABLE IF EXISTS `aqorderdelivery`;
2753 CREATE TABLE `aqorderdelivery` (
2754   `ordernumber` date default NULL,
2755   `deliverynumber` smallint(6) NOT NULL default 0,
2756   `deliverydate` varchar(18) default NULL,
2757   `qtydelivered` smallint(6) default NULL,
2758   `deliverycomments` mediumtext
2759 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2760
2761 --
2762 -- Table structure for table `aqorders`
2763 --
2764
2765 DROP TABLE IF EXISTS `aqorders`;
2766 CREATE TABLE `aqorders` ( -- information related to the basket line items
2767   `ordernumber` int(11) NOT NULL auto_increment, -- primary key and unique identifier assigned by Koha to each line
2768   `biblionumber` int(11) default NULL, -- links the order to the biblio being ordered (biblio.biblionumber)
2769   `entrydate` date default NULL, -- the date the bib was added to the basket
2770   `quantity` smallint(6) default NULL, -- the quantity ordered
2771   `currency` varchar(3) default NULL, -- the currency used for the purchase
2772   `listprice` decimal(28,6) default NULL, -- the vendor price for this line item
2773   `totalamount` decimal(28,6) default NULL, -- not used? always NULL
2774   `datereceived` date default NULL, -- the date this order was received
2775   invoiceid int(11) default NULL, -- id of invoice
2776   `freight` decimal(28,6) default NULL, -- shipping costs (not used)
2777   `unitprice` decimal(28,6) default NULL, -- the actual cost entered when receiving this line item
2778   `quantityreceived` smallint(6) NOT NULL default 0, -- the quantity that have been received so far
2779   `cancelledby` varchar(10) default NULL, -- not used? always NULL
2780   `datecancellationprinted` date default NULL, -- the date the line item was deleted
2781   `notes` mediumtext, -- notes related to this order line
2782   `supplierreference` mediumtext, -- not used? always NULL
2783   `purchaseordernumber` mediumtext, -- not used? always NULL
2784   `subscription` tinyint(1) default NULL, -- not used? always NULL
2785   `serialid` varchar(30) default NULL, -- not used? always NULL
2786   `basketno` int(11) default NULL, -- links this order line to a specific basket (aqbasket.basketno)
2787   `biblioitemnumber` int(11) default NULL, -- links this order line the biblioitems table (biblioitems.biblioitemnumber)
2788   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- the date and time this order line was last modified
2789   `rrp` decimal(13,2) default NULL, -- the replacement cost for this line item
2790   `ecost` decimal(13,2) default NULL, -- the estimated cost for this line item
2791   `gstrate` decimal(6,4) default NULL, -- the tax rate for this line item
2792   `discount` float(6,4) default NULL, -- the discount for this line item
2793   `budget_id` int(11) NOT NULL, -- the fund this order goes against (aqbudgets.budget_id)
2794   `budgetgroup_id` int(11) NOT NULL, -- not used? always zero
2795   `budgetdate` date default NULL, -- not used? always NULL
2796   `sort1` varchar(80) default NULL, -- statistical field
2797   `sort2` varchar(80) default NULL, -- second statistical field
2798   `sort1_authcat` varchar(10) default NULL,
2799   `sort2_authcat` varchar(10) default NULL,
2800   `uncertainprice` tinyint(1), -- was this price uncertain (1 for yes, 0 for no)
2801   `claims_count` int(11) default 0, -- count of claim letters generated
2802   `claimed_date` date default NULL, -- last date a claim was generated
2803   parent_ordernumber int(11) default NULL, -- ordernumber of parent order line, or same as ordernumber if no parent
2804   PRIMARY KEY  (`ordernumber`),
2805   KEY `basketno` (`basketno`),
2806   KEY `biblionumber` (`biblionumber`),
2807   KEY `budget_id` (`budget_id`),
2808   CONSTRAINT `aqorders_ibfk_1` FOREIGN KEY (`basketno`) REFERENCES `aqbasket` (`basketno`) ON DELETE CASCADE ON UPDATE CASCADE,
2809   CONSTRAINT `aqorders_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE,
2810   CONSTRAINT aqorders_ibfk_3 FOREIGN KEY (invoiceid) REFERENCES aqinvoices (invoiceid) ON DELETE SET NULL ON UPDATE CASCADE
2811 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2812
2813
2814 --
2815 -- Table structure for table `aqorders_items`
2816 --
2817
2818 DROP TABLE IF EXISTS `aqorders_items`;
2819 CREATE TABLE `aqorders_items` ( -- information on items entered in the acquisitions process
2820   `ordernumber` int(11) NOT NULL, -- the order this item is attached to (aqorders.ordernumber)
2821   `itemnumber` int(11) NOT NULL, -- the item number for this item (items.itemnumber)
2822   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- the date and time this order item was last touched
2823   PRIMARY KEY  (`itemnumber`),
2824   KEY `ordernumber` (`ordernumber`)
2825 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2826
2827
2828 --
2829 -- Table structure for table aqinvoices
2830 --
2831
2832 DROP TABLE IF EXISTS aqinvoices;
2833 CREATE TABLE aqinvoices (
2834   invoiceid int(11) NOT NULL AUTO_INCREMENT,    -- ID of the invoice, primary key
2835   invoicenumber mediumtext NOT NULL,    -- Name of invoice
2836   booksellerid int(11) NOT NULL,    -- foreign key to aqbooksellers
2837   shipmentdate date default NULL,   -- date of shipment
2838   billingdate date default NULL,    -- date of billing
2839   closedate date default NULL,  -- invoice close date, NULL means the invoice is open
2840   shipmentcost decimal(28,6) default NULL,  -- shipment cost
2841   shipmentcost_budgetid int(11) default NULL,   -- foreign key to aqbudgets, link the shipment cost to a budget
2842   PRIMARY KEY (invoiceid),
2843   CONSTRAINT aqinvoices_fk_aqbooksellerid FOREIGN KEY (booksellerid) REFERENCES aqbooksellers (id) ON DELETE CASCADE ON UPDATE CASCADE,
2844   CONSTRAINT aqinvoices_fk_shipmentcost_budgetid FOREIGN KEY (shipmentcost_budgetid) REFERENCES aqbudgets (budget_id) ON DELETE SET NULL ON UPDATE CASCADE
2845 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2846
2847
2848 --
2849 -- Table structure for table `fieldmapping`
2850 --
2851
2852 DROP TABLE IF EXISTS `fieldmapping`;
2853 CREATE TABLE `fieldmapping` ( -- koha to keyword mapping
2854   `id` int(11) NOT NULL auto_increment, -- unique identifier assigned by Koha
2855   `field` varchar(255) NOT NULL, -- keyword to be mapped to (ex. subtitle)
2856   `frameworkcode` char(4) NOT NULL default '', -- foreign key from the biblio_framework table to link this mapping to a specific framework
2857   `fieldcode` char(3) NOT NULL, -- marc field number to map to this keyword
2858   `subfieldcode` char(1) NOT NULL, -- marc subfield associated with the fieldcode to map to this keyword
2859   PRIMARY KEY  (`id`)
2860 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2861
2862 --
2863 -- Table structure for table `transport_cost`
2864 --
2865
2866 DROP TABLE IF EXISTS transport_cost;
2867 CREATE TABLE transport_cost (
2868       frombranch varchar(10) NOT NULL,
2869       tobranch varchar(10) NOT NULL,
2870       cost decimal(6,2) NOT NULL,
2871       disable_transfer tinyint(1) NOT NULL DEFAULT 0,
2872       CHECK ( frombranch <> tobranch ), -- a dud check, mysql does not support that
2873       PRIMARY KEY (frombranch, tobranch),
2874       CONSTRAINT transport_cost_ibfk_1 FOREIGN KEY (frombranch) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE,
2875       CONSTRAINT transport_cost_ibfk_2 FOREIGN KEY (tobranch) REFERENCES branches (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
2876 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2877
2878 --
2879 -- Table structure for table `biblioimages`
2880 --
2881
2882 DROP TABLE IF EXISTS `biblioimages`;
2883
2884 CREATE TABLE `biblioimages` (
2885  `imagenumber` int(11) NOT NULL AUTO_INCREMENT,
2886  `biblionumber` int(11) NOT NULL,
2887  `mimetype` varchar(15) NOT NULL,
2888  `imagefile` mediumblob NOT NULL,
2889  `thumbnail` mediumblob NOT NULL,
2890  PRIMARY KEY (`imagenumber`),
2891  CONSTRAINT `bibliocoverimage_fk1` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
2892 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2893
2894 --
2895 -- Table structure for table `social_data`
2896 --
2897
2898 DROP TABLE IF EXISTS `social_data`;
2899 CREATE TABLE IF NOT EXISTS `social_data` (
2900   `isbn` VARCHAR(30),
2901   `num_critics` INT,
2902   `num_critics_pro` INT,
2903   `num_quotations` INT,
2904   `num_videos` INT,
2905   `score_avg` DECIMAL(5,2),
2906   `num_scores` INT,
2907   PRIMARY KEY  (`isbn`)
2908 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2909
2910 --
2911 -- 'Ratings' table. This tracks the star ratings set by borrowers.
2912 --
2913
2914 DROP TABLE IF EXISTS ratings;
2915 CREATE TABLE ratings ( -- information related to the star ratings in the OPAC
2916     borrowernumber int(11) NOT NULL, -- the borrowernumber of the patron who left this rating (borrowers.borrowernumber)
2917     biblionumber int(11) NOT NULL, -- the biblio this rating is for (biblio.biblionumber)
2918     rating_value tinyint(1) NOT NULL, -- the rating, from 1 to 5
2919     timestamp timestamp NOT NULL default CURRENT_TIMESTAMP,
2920     PRIMARY KEY  (borrowernumber,biblionumber),
2921     CONSTRAINT ratings_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE,
2922     CONSTRAINT ratings_ibfk_2 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE CASCADE
2923 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2924
2925 --
2926 -- Table structure for table `quotes`
2927 --
2928
2929 DROP TABLE IF EXISTS quotes;
2930 CREATE TABLE `quotes` (
2931   `id` int(11) NOT NULL AUTO_INCREMENT,
2932   `source` text DEFAULT NULL,
2933   `text` mediumtext NOT NULL,
2934   `timestamp` datetime NOT NULL,
2935   PRIMARY KEY (`id`)
2936 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2937
2938 /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
2939 /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
2940 /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
2941 /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
2942 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
2943 /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
2944 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
2945 /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
2946