Bug 22844: Add the new DB column borrower_attribute_types.mandatory
[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 utf8mb4 */;
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   `modification_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
28   `origincode` varchar(20) default NULL,
29   `authtrees` LONGTEXT,
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=utf8mb4 COLLATE=utf8mb4_unicode_ci;
36
37 --
38 -- Table structure for table `auth_types`
39 --
40
41 DROP TABLE IF EXISTS `auth_types`;
42 CREATE TABLE `auth_types` (
43   `authtypecode` varchar(10) NOT NULL default '',
44   `authtypetext` varchar(255) NOT NULL default '',
45   `auth_tag_to_report` varchar(3) NOT NULL default '',
46   `summary` LONGTEXT NOT NULL,
47   PRIMARY KEY  (`authtypecode`)
48 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
49
50 --
51 -- Table structure for table `auth_subfield_structure`
52 --
53
54 DROP TABLE IF EXISTS `auth_subfield_structure`;
55 CREATE TABLE `auth_subfield_structure` (
56   `authtypecode` varchar(10) NOT NULL default '',
57   `tagfield` varchar(3) NOT NULL default '',
58   `tagsubfield` varchar(1) NOT NULL default '',
59   `liblibrarian` varchar(255) NOT NULL default '',
60   `libopac` varchar(255) NOT NULL default '',
61   `repeatable` tinyint(4) NOT NULL default 0,
62   `mandatory` tinyint(4) NOT NULL default 0,
63   `tab` tinyint(1) default NULL,
64   `authorised_value` varchar(10) default NULL,
65   `value_builder` varchar(80) default NULL,
66   `seealso` varchar(255) default NULL,
67   `isurl` tinyint(1) default NULL,
68   `hidden` tinyint(3) NOT NULL default 0,
69   `linkid` tinyint(1) NOT NULL default 0,
70   `kohafield` varchar(45) NULL default '',
71   `frameworkcode` varchar(10) NOT NULL default '',
72   `defaultvalue` MEDIUMTEXT,
73   PRIMARY KEY  (`authtypecode`,`tagfield`,`tagsubfield`),
74   KEY `tab` (`authtypecode`,`tab`),
75   CONSTRAINT `auth_subfield_structure_ibfk_1` FOREIGN KEY (`authtypecode`) REFERENCES `auth_types` (`authtypecode`) ON DELETE CASCADE ON UPDATE CASCADE
76 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
77
78 --
79 -- Table structure for table `auth_tag_structure`
80 --
81
82 DROP TABLE IF EXISTS `auth_tag_structure`;
83 CREATE TABLE `auth_tag_structure` (
84   `authtypecode` varchar(10) NOT NULL default '',
85   `tagfield` varchar(3) NOT NULL default '',
86   `liblibrarian` varchar(255) NOT NULL default '',
87   `libopac` varchar(255) NOT NULL default '',
88   `repeatable` tinyint(4) NOT NULL default 0,
89   `mandatory` tinyint(4) NOT NULL default 0,
90   `authorised_value` varchar(10) default NULL,
91   PRIMARY KEY  (`authtypecode`,`tagfield`),
92   CONSTRAINT `auth_tag_structure_ibfk_1` FOREIGN KEY (`authtypecode`) REFERENCES `auth_types` (`authtypecode`) ON DELETE CASCADE ON UPDATE CASCADE
93 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
94
95
96 --
97 -- Table structure for table `authorised_value_categories`
98 --
99
100 DROP TABLE IF EXISTS `authorised_value_categories`;
101 CREATE TABLE `authorised_value_categories` (
102   `category_name` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
103   `is_system` tinyint(1) default 0,
104   PRIMARY KEY (`category_name`)
105 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
106
107 --
108 -- Table structure for table `authorised_values`
109 --
110
111 DROP TABLE IF EXISTS `authorised_values`;
112 CREATE TABLE `authorised_values` ( -- stores values for authorized values categories and values
113   `id` int(11) NOT NULL auto_increment, -- unique key, used to identify the authorized value
114   `category` varchar(32) NOT NULL default '', -- key used to identify the authorized value category
115   `authorised_value` varchar(80) NOT NULL default '', -- code use to identify the authorized value
116   `lib` varchar(200) default NULL, -- authorized value description as printed in the staff client
117   `lib_opac` varchar(200) default NULL, -- authorized value description as printed in the OPAC
118   `imageurl` varchar(200) default NULL, -- authorized value URL
119   PRIMARY KEY  (`id`),
120   KEY `name` (`category`),
121   KEY `lib` (`lib` (191)),
122   KEY `auth_value_idx` (`authorised_value`),
123   CONSTRAINT `av_uniq` UNIQUE (`category`,`authorised_value`),
124   CONSTRAINT `authorised_values_authorised_values_category` FOREIGN KEY (`category`) REFERENCES `authorised_value_categories` (`category_name`) ON DELETE CASCADE ON UPDATE CASCADE
125 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
126
127 --
128 -- Table structure for table `biblio`
129 --
130
131 DROP TABLE IF EXISTS `biblio`;
132 CREATE TABLE `biblio` ( -- table that stores bibliographic information
133   `biblionumber` int(11) NOT NULL auto_increment, -- unique identifier assigned to each bibliographic record
134   `frameworkcode` varchar(4) NOT NULL default '', -- foreign key from the biblio_framework table to identify which framework was used in cataloging this record
135   `author` LONGTEXT, -- statement of responsibility from MARC record (100$a in MARC21)
136   `title` LONGTEXT, -- title (without the subtitle) from the MARC record (245$a in MARC21)
137   `medium` LONGTEXT, -- medium from the MARC record (245$h in MARC21)
138   `subtitle` LONGTEXT, -- remainder of the title from the MARC record (245$b in MARC21)
139   `part_number` LONGTEXT, -- part number from the MARC record (245$n in MARC21)
140   `part_name` LONGTEXT, -- part name from the MARC record (245$p in MARC21)
141   `unititle` LONGTEXT, -- uniform title (without the subtitle) from the MARC record (240$a in MARC21)
142   `notes` LONGTEXT, -- values from the general notes field in the MARC record (500$a in MARC21) split by bar (|)
143   `serial` tinyint(1) default NULL, -- Boolean indicating whether biblio is for a serial
144   `seriestitle` LONGTEXT,
145   `copyrightdate` smallint(6) default NULL, -- publication or copyright date from the MARC record
146   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- date and time this record was last touched
147   `datecreated` DATE NOT NULL, -- the date this record was added to Koha
148   `abstract` LONGTEXT, -- summary from the MARC record (520$a in MARC21)
149   PRIMARY KEY  (`biblionumber`),
150   KEY `blbnoidx` (`biblionumber`)
151 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
152
153 --
154 -- Table structure for table `biblio_framework`
155 --
156
157 DROP TABLE IF EXISTS `biblio_framework`;
158 CREATE TABLE `biblio_framework` ( -- information about MARC frameworks
159   `frameworkcode` varchar(4) NOT NULL default '', -- the unique code assigned to the framework
160   `frameworktext` varchar(255) NOT NULL default '', -- the description/name given to the framework
161   PRIMARY KEY  (`frameworkcode`)
162 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
163
164 --
165 -- Table structure for table `biblioitems`
166 --
167
168 DROP TABLE IF EXISTS `biblioitems`;
169 CREATE TABLE `biblioitems` ( -- information related to bibliographic records in Koha
170   `biblioitemnumber` int(11) NOT NULL auto_increment, -- primary key, unique identifier assigned by Koha
171   `biblionumber` int(11) NOT NULL default 0, -- foreign key linking this table to the biblio table
172   `volume` LONGTEXT,
173   `number` LONGTEXT,
174   `itemtype` varchar(10) default NULL, -- biblio level item type (MARC21 942$c)
175   `isbn` LONGTEXT, -- ISBN (MARC21 020$a)
176   `issn` LONGTEXT, -- ISSN (MARC21 022$a)
177   `ean` LONGTEXT default NULL,
178   `publicationyear` MEDIUMTEXT,
179   `publishercode` varchar(255) default NULL, -- publisher (MARC21 260$b)
180   `volumedate` date default NULL,
181   `volumedesc` MEDIUMTEXT, -- volume information (MARC21 362$a)
182   `collectiontitle` LONGTEXT default NULL,
183   `collectionissn` MEDIUMTEXT default NULL,
184   `collectionvolume` LONGTEXT default NULL,
185   `editionstatement` MEDIUMTEXT default NULL,
186   `editionresponsibility` MEDIUMTEXT default NULL,
187   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
188   `illus` varchar(255) default NULL, -- illustrations (MARC21 300$b)
189   `pages` varchar(255) default NULL, -- number of pages (MARC21 300$c)
190   `notes` LONGTEXT,
191   `size` varchar(255) default NULL, -- material size (MARC21 300$c)
192   `place` varchar(255) default NULL, -- publication place (MARC21 260$a)
193   `lccn` varchar(25) default NULL, -- library of congress control number (MARC21 010$a)
194   `url` MEDIUMTEXT default NULL, -- url (MARC21 856$u)
195   `cn_source` varchar(10) default NULL, -- classification source (MARC21 942$2)
196   `cn_class` varchar(30) default NULL,
197   `cn_item` varchar(10) default NULL,
198   `cn_suffix` varchar(10) default NULL,
199   `cn_sort` varchar(255) default NULL, -- normalized version of the call number used for sorting
200   `agerestriction` varchar(255) default NULL, -- target audience/age restriction from the bib record (MARC21 521$a)
201   `totalissues` int(10),
202   PRIMARY KEY  (`biblioitemnumber`),
203   KEY `bibinoidx` (`biblioitemnumber`),
204   KEY `bibnoidx` (`biblionumber`),
205   KEY `itemtype_idx` (`itemtype`),
206   KEY `isbn` (`isbn`(255)),
207   KEY `issn` (`issn`(255)),
208   KEY `ean` (`ean`(255)),
209   KEY `publishercode` (`publishercode` (191)),
210   KEY `timestamp` (`timestamp`),
211   CONSTRAINT `biblioitems_ibfk_1` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
212 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
213
214 --
215 -- Table structure for table `borrower_attribute_types`
216 --
217
218 DROP TABLE IF EXISTS `borrower_attribute_types`;
219 CREATE TABLE `borrower_attribute_types` ( -- definitions for custom patron fields known as extended patron attributes
220   `code` varchar(10) NOT NULL, -- unique key used to identify each custom field
221   `description` varchar(255) NOT NULL, -- description for each custom field
222   `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)
223   `unique_id` tinyint(1) NOT NULL default 0, -- defines if this value needs to be unique (1 for yes, 0 for no)
224   `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)
225   `opac_editable` tinyint(1) NOT NULL default 0, -- defines if this field is editable by patrons on their account in the OPAC (1 for yes, 0 for no)
226   `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)
227   `authorised_value_category` varchar(32) default NULL, -- foreign key from authorised_values that links this custom field to an authorized value category
228   `display_checkout` tinyint(1) NOT NULL default 0,-- defines if this field displays in checkout screens
229   `category_code` VARCHAR(10) NULL DEFAULT NULL,-- defines a category for an attribute_type
230   `class` VARCHAR(255) NOT NULL DEFAULT '',-- defines a class for an attribute_type
231   `keep_for_pseudonymization` tinyint(1) NOT NULL default 0, -- defines if this field is copied to anonymized_borrower_attributes (1 for yes, 0 for no)
232   `mandatory` tinyint(1) NOT NULL DEFAULT 0, -- defines if the attribute is mandatory or not
233   PRIMARY KEY  (`code`),
234   KEY `auth_val_cat_idx` (`authorised_value_category`)
235 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
236
237 --
238 -- Table structure for table `borrower_password_recovery`
239 --
240
241 DROP TABLE IF EXISTS `borrower_password_recovery`;
242 CREATE TABLE IF NOT EXISTS `borrower_password_recovery` ( -- holds information about password recovery attempts
243   `borrowernumber` int(11) NOT NULL, -- the user asking a password recovery
244   `uuid` varchar(128) NOT NULL, -- a unique string to identify a password recovery attempt
245   `valid_until` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- a time limit on the password recovery attempt
246   PRIMARY KEY (`borrowernumber`),
247   KEY borrowernumber (borrowernumber)
248 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
249
250 --
251 -- Table structure for table `branches`
252 --
253
254 DROP TABLE IF EXISTS `branches`;
255 CREATE TABLE `branches` ( -- information about your libraries or branches are stored here
256   `branchcode` varchar(10) NOT NULL default '', -- a unique key assigned to each branch
257   `branchname` LONGTEXT NOT NULL, -- the name of your library or branch
258   `branchaddress1` LONGTEXT, -- the first address line of for your library or branch
259   `branchaddress2` LONGTEXT, -- the second address line of for your library or branch
260   `branchaddress3` LONGTEXT, -- the third address line of for your library or branch
261   `branchzip` varchar(25) default NULL, -- the zip or postal code for your library or branch
262   `branchcity` LONGTEXT, -- the city or province for your library or branch
263   `branchstate` LONGTEXT, -- the state for your library or branch
264   `branchcountry` MEDIUMTEXT, -- the county for your library or branch
265   `branchphone` LONGTEXT, -- the primary phone for your library or branch
266   `branchfax` LONGTEXT, -- the fax number for your library or branch
267   `branchemail` LONGTEXT, -- the primary email address for your library or branch
268   `branchreplyto` LONGTEXT, -- the email to be used as a Reply-To
269   `branchreturnpath` LONGTEXT, -- the email to be used as Return-Path
270   `branchurl` LONGTEXT, -- the URL for your library or branch's website
271   `issuing` tinyint(4) default NULL, -- unused in Koha
272   `branchip` varchar(15) default NULL, -- the IP address for your library or branch
273   `branchnotes` LONGTEXT, -- notes related to your library or branch
274   opac_info MEDIUMTEXT, -- HTML that displays in OPAC
275   `geolocation` VARCHAR(255) default NULL, -- geolocation of your library
276   `marcorgcode` VARCHAR(16) default NULL, -- MARC Organization Code, see http://www.loc.gov/marc/organizations/orgshome.html, when empty defaults to syspref MARCOrgCode
277   `pickup_location` tinyint(1) NOT NULL default 1, -- the ability to act as a pickup location
278   PRIMARY KEY (`branchcode`)
279 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
280
281 --
282 -- Table structure for table `branches_overdrive`
283 --
284
285 DROP TABLE IF EXISTS `branches_overdrive`;
286 CREATE TABLE IF NOT EXISTS branches_overdrive (
287   `branchcode` VARCHAR( 10 ) NOT NULL ,
288   `authname` VARCHAR( 255 ) NOT NULL ,
289   PRIMARY KEY (`branchcode`) ,
290   CONSTRAINT `branches_overdrive_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
291 ) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
292
293 --
294 -- Table structure for table `browser`
295 --
296 DROP TABLE IF EXISTS `browser`;
297 CREATE TABLE `browser` (
298   `level` int(11) NOT NULL,
299   `classification` varchar(20) NOT NULL,
300   `description` varchar(255) NOT NULL,
301   `number` bigint(20) NOT NULL,
302   `endnode` tinyint(4) NOT NULL
303 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
304
305 --
306 -- Table structure for table `categories`
307 --
308
309 DROP TABLE IF EXISTS `categories`;
310 CREATE TABLE `categories` ( -- this table shows information related to Koha patron categories
311   `categorycode` varchar(10) NOT NULL default '', -- unique primary key used to idenfity the patron category
312   `description` LONGTEXT, -- description of the patron category
313   `enrolmentperiod` smallint(6) default NULL, -- number of months the patron is enrolled for (will be NULL if enrolmentperioddate is set)
314   `enrolmentperioddate` DATE NULL DEFAULT NULL, -- date the patron is enrolled until (will be NULL if enrolmentperiod is set)
315   `upperagelimit` smallint(6) default NULL, -- age limit for the patron
316   `dateofbirthrequired` tinyint(1) default NULL, -- the minimum age required for the patron category
317   `finetype` varchar(30) default NULL, -- unused in Koha
318   `bulk` tinyint(1) default NULL,
319   `enrolmentfee` decimal(28,6) default NULL, -- enrollment fee for the patron
320   `overduenoticerequired` tinyint(1) default NULL, -- are overdue notices sent to this patron category (1 for yes, 0 for no)
321   `issuelimit` smallint(6) default NULL, -- unused in Koha
322   `reservefee` decimal(28,6) default NULL, -- cost to place holds
323   `hidelostitems` tinyint(1) NOT NULL default '0', -- are lost items shown to this category (1 for yes, 0 for no)
324   `category_type` varchar(1) NOT NULL default 'A', -- type of Koha patron (Adult, Child, Professional, Organizational, Statistical, Staff)
325   `BlockExpiredPatronOpacActions` tinyint(1) NOT NULL default '-1', -- wheither or not a patron of this category can renew books or place holds once their card has expired. 0 means they can, 1 means they cannot, -1 means use syspref BlockExpiredPatronOpacActions
326   `default_privacy` ENUM( 'default', 'never', 'forever' ) NOT NULL DEFAULT 'default', -- Default privacy setting for this patron category
327   `checkprevcheckout` varchar(7) NOT NULL default 'inherit', -- produce a warning for this patron category if this item has previously been checked out to this patron if 'yes', not if 'no', defer to syspref setting if 'inherit'.
328   `reset_password` TINYINT(1) NULL DEFAULT NULL, -- if patrons of this category can do the password reset flow,
329   `change_password` TINYINT(1) NULL DEFAULT NULL, -- if patrons of this category can change their passwords in the OAPC
330   PRIMARY KEY  (`categorycode`),
331   UNIQUE KEY `categorycode` (`categorycode`)
332 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
333
334 --
335 -- Table: collections
336 --
337 DROP TABLE IF EXISTS collections;
338 CREATE TABLE collections (
339   colId integer(11) NOT NULL auto_increment,
340   colTitle varchar(100) NOT NULL DEFAULT '',
341   colDesc MEDIUMTEXT NOT NULL,
342   colBranchcode varchar(10) DEFAULT NULL, -- 'branchcode for branch where item should be held.'
343   PRIMARY KEY (colId)
344 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
345
346 --
347 -- Constraints for table `collections`
348 --
349 ALTER TABLE `collections`
350   ADD CONSTRAINT `collections_ibfk_1` FOREIGN KEY (`colBranchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE;
351
352 --
353 -- Table: collections_tracking
354 --
355
356 DROP TABLE IF EXISTS collections_tracking;
357 CREATE TABLE collections_tracking (
358   collections_tracking_id integer(11) NOT NULL auto_increment,
359   colId integer(11) NOT NULL DEFAULT 0 comment 'collections.colId',
360   itemnumber integer(11) NOT NULL DEFAULT 0 comment 'items.itemnumber',
361   PRIMARY KEY (collections_tracking_id)
362 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
363
364 --
365 -- Table structure for table `cities`
366 --
367
368 DROP TABLE IF EXISTS `cities`;
369 CREATE TABLE `cities` ( -- authorized values for cities/states/countries to choose when adding/editing a patron/borrower
370   `cityid` int(11) NOT NULL auto_increment, -- unique identifier added by Koha
371   `city_name` varchar(100) NOT NULL default '', -- name of the city
372   `city_state` VARCHAR( 100 ) NULL DEFAULT NULL, -- name of the state/province
373   `city_country` VARCHAR( 100 ) NULL DEFAULT NULL, -- name of the country
374   `city_zipcode` varchar(20) default NULL, -- zip or postal code
375   PRIMARY KEY  (`cityid`)
376 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
377
378 --
379 -- Table structure for table desks
380 --
381
382 DROP TABLE IF EXISTS desks;
383 CREATE TABLE desks ( -- desks available in a library
384   desk_id int(11) NOT NULL auto_increment, -- unique identifier
385   desk_name varchar(100) NOT NULL default '', -- name of the desk
386   branchcode varchar(10) NOT NULL,       -- library the desk is located at
387   PRIMARY KEY  (desk_id),
388   KEY `fk_desks_branchcode` (branchcode),
389   CONSTRAINT `fk_desks_branchcode` FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE
390 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
391
392 --
393 -- Table structure for table `class_sort_rules`
394 --
395
396 DROP TABLE IF EXISTS `class_sort_rules`;
397 CREATE TABLE `class_sort_rules` (
398   `class_sort_rule` varchar(10) NOT NULL default '',
399   `description` LONGTEXT,
400   `sort_routine` varchar(30) NOT NULL default '',
401   PRIMARY KEY (`class_sort_rule`),
402   UNIQUE KEY `class_sort_rule_idx` (`class_sort_rule`)
403 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
404
405 --
406 -- Table structure for table `class_split_rules`
407 --
408
409 DROP TABLE IF EXISTS `class_split_rules`;
410
411 CREATE TABLE class_split_rules (
412   class_split_rule varchar(10) NOT NULL default '',
413   description LONGTEXT,
414   split_routine varchar(30) NOT NULL default '',
415   split_regex varchar(255) NOT NULL default '',
416   PRIMARY KEY (class_split_rule),
417   UNIQUE KEY class_split_rule_idx (class_split_rule)
418 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
419
420 --
421 -- Table structure for table `class_sources`
422 --
423
424 DROP TABLE IF EXISTS `class_sources`;
425 CREATE TABLE `class_sources` (
426   `cn_source` varchar(10) NOT NULL default '',
427   `description` LONGTEXT,
428   `used` tinyint(4) NOT NULL default 0,
429   `class_sort_rule` varchar(10) NOT NULL default '',
430   `class_split_rule` varchar(10) NOT NULL default '',
431   PRIMARY KEY (`cn_source`),
432   UNIQUE KEY `cn_source_idx` (`cn_source`),
433   KEY `used_idx` (`used`),
434   CONSTRAINT `class_source_ibfk_1` FOREIGN KEY (`class_sort_rule`) REFERENCES `class_sort_rules` (`class_sort_rule`),
435   CONSTRAINT `class_source_ibfk_2` FOREIGN KEY (`class_split_rule`) REFERENCES `class_split_rules` (`class_split_rule`)
436 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
437
438 --
439 -- Table structure for table `currency`
440 --
441
442 DROP TABLE IF EXISTS `currency`;
443 CREATE TABLE `currency` (
444   `currency` varchar(10) NOT NULL default '',
445   `symbol` varchar(5) default NULL,
446   `isocode` varchar(5) default NULL,
447   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
448   `rate` float(15,5) default NULL,
449   `active` tinyint(1) default NULL,
450   `archived` tinyint(1) DEFAULT 0,
451   `p_sep_by_space` tinyint(1) DEFAULT 0,
452   PRIMARY KEY  (`currency`)
453 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
454
455 --
456 -- Table structure for table `deletedbiblio`
457 --
458
459 DROP TABLE IF EXISTS `deletedbiblio`;
460 CREATE TABLE `deletedbiblio` ( -- stores information about bibliographic records that have been deleted
461   `biblionumber` int(11) NOT NULL auto_increment, -- unique identifier assigned to each bibliographic record
462   `frameworkcode` varchar(4) NOT NULL default '', -- foriegn key from the biblio_framework table to identify which framework was used in cataloging this record
463   `author` LONGTEXT, -- statement of responsibility from MARC record (100$a in MARC21)
464   `title` LONGTEXT, -- title (without the subtitle) from the MARC record (245$a in MARC21)
465   `medium` LONGTEXT, -- medium from the MARC record (245$h in MARC21)
466   `subtitle` LONGTEXT, -- remainder of the title from the MARC record (245$b in MARC21)
467   `part_number` LONGTEXT, -- part number from the MARC record (245$n in MARC21)
468   `part_name` LONGTEXT, -- part name from the MARC record (245$p in MARC21)
469   `unititle` LONGTEXT, -- uniform title (without the subtitle) from the MARC record (240$a in MARC21)
470   `notes` LONGTEXT, -- values from the general notes field in the MARC record (500$a in MARC21) split by bar (|)
471   `serial` tinyint(1) default NULL, -- Boolean indicating whether biblio is for a serial
472   `seriestitle` LONGTEXT,
473   `copyrightdate` smallint(6) default NULL, -- publication or copyright date from the MARC record
474   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- date and time this record was last touched
475   `datecreated` DATE NOT NULL, -- the date this record was added to Koha
476   `abstract` LONGTEXT, -- summary from the MARC record (520$a in MARC21)
477   PRIMARY KEY  (`biblionumber`),
478   KEY `blbnoidx` (`biblionumber`)
479 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
480
481 --
482 -- Table structure for table `deletedbiblioitems`
483 --
484
485 DROP TABLE IF EXISTS `deletedbiblioitems`;
486 CREATE TABLE `deletedbiblioitems` ( -- information about bibliographic records that have been deleted
487   `biblioitemnumber` int(11) NOT NULL default 0, -- primary key, unique identifier assigned by Koha
488   `biblionumber` int(11) NOT NULL default 0, -- foreign key linking this table to the biblio table
489   `volume` LONGTEXT,
490   `number` LONGTEXT,
491   `itemtype` varchar(10) default NULL, -- biblio level item type (MARC21 942$c)
492   `isbn` LONGTEXT default NULL, -- ISBN (MARC21 020$a)
493   `issn` LONGTEXT default NULL, -- ISSN (MARC21 022$a)
494   `ean` LONGTEXT default NULL,
495   `publicationyear` MEDIUMTEXT,
496   `publishercode` varchar(255) default NULL, -- publisher (MARC21 260$b)
497   `volumedate` date default NULL,
498   `volumedesc` MEDIUMTEXT, -- volume information (MARC21 362$a)
499   `collectiontitle` LONGTEXT default NULL,
500   `collectionissn` MEDIUMTEXT default NULL,
501   `collectionvolume` LONGTEXT default NULL,
502   `editionstatement` MEDIUMTEXT default NULL,
503   `editionresponsibility` MEDIUMTEXT default NULL,
504   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
505   `illus` varchar(255) default NULL, -- illustrations (MARC21 300$b)
506   `pages` varchar(255) default NULL, -- number of pages (MARC21 300$c)
507   `notes` LONGTEXT,
508   `size` varchar(255) default NULL, -- material size (MARC21 300$c)
509   `place` varchar(255) default NULL, -- publication place (MARC21 260$a)
510   `lccn` varchar(25) default NULL, -- library of congress control number (MARC21 010$a)
511   `url` MEDIUMTEXT default NULL, -- url (MARC21 856$u)
512   `cn_source` varchar(10) default NULL, -- classification source (MARC21 942$2)
513   `cn_class` varchar(30) default NULL,
514   `cn_item` varchar(10) default NULL,
515   `cn_suffix` varchar(10) default NULL,
516   `cn_sort` varchar(255) default NULL, -- normalized version of the call number used for sorting
517   `agerestriction` varchar(255) default NULL, -- target audience/age restriction from the bib record (MARC21 521$a)
518   `totalissues` int(10),
519   PRIMARY KEY  (`biblioitemnumber`),
520   KEY `bibinoidx` (`biblioitemnumber`),
521   KEY `bibnoidx` (`biblionumber`),
522   KEY `itemtype_idx` (`itemtype`),
523   KEY `isbn` (`isbn`(255)),
524   KEY `ean` (`ean`(255)),
525   KEY `publishercode` (`publishercode` (191)),
526   KEY `timestamp` (`timestamp`)
527 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
528
529 --
530 -- Table structure for table `deletedborrowers`
531 --
532
533 DROP TABLE IF EXISTS `deletedborrowers`;
534 CREATE TABLE `deletedborrowers` ( -- stores data related to the patrons/borrowers you have deleted
535   `borrowernumber` int(11) NOT NULL default 0, -- primary key, Koha assigned ID number for patrons/borrowers
536   `cardnumber` varchar(32) default NULL, -- unique key, library assigned ID number for patrons/borrowers
537   `surname` LONGTEXT, -- patron/borrower's last name (surname)
538   `firstname` MEDIUMTEXT, -- patron/borrower's first name
539   `title` LONGTEXT, -- patron/borrower's title, for example: Mr. or Mrs.
540   `othernames` LONGTEXT, -- any other names associated with the patron/borrower
541   `initials` MEDIUMTEXT, -- initials for your patron/borrower
542   `streetnumber` TINYTEXT default NULL, -- the house number for your patron/borrower's primary address
543   `streettype` TINYTEXT default NULL, -- the street type (Rd., Blvd, etc) for your patron/borrower's primary address
544   `address` LONGTEXT, -- the first address line for your patron/borrower's primary address
545   `address2` MEDIUMTEXT, -- the second address line for your patron/borrower's primary address
546   `city` LONGTEXT, -- the city or town for your patron/borrower's primary address
547   `state` MEDIUMTEXT default NULL, -- the state or province for your patron/borrower's primary address
548   `zipcode` TINYTEXT default NULL, -- the zip or postal code for your patron/borrower's primary address
549   `country` MEDIUMTEXT, -- the country for your patron/borrower's primary address
550   `email` LONGTEXT, -- the primary email address for your patron/borrower's primary address
551   `phone` MEDIUMTEXT, -- the primary phone number for your patron/borrower's primary address
552   `mobile` TINYTEXT default NULL, -- the other phone number for your patron/borrower's primary address
553   `fax` LONGTEXT, -- the fax number for your patron/borrower's primary address
554   `emailpro` MEDIUMTEXT, -- the secondary email addres for your patron/borrower's primary address
555   `phonepro` MEDIUMTEXT, -- the secondary phone number for your patron/borrower's primary address
556   `B_streetnumber` TINYTEXT default NULL, -- the house number for your patron/borrower's alternate address
557   `B_streettype` TINYTEXT default NULL, -- the street type (Rd., Blvd, etc) for your patron/borrower's alternate address
558   `B_address` MEDIUMTEXT default NULL, -- the first address line for your patron/borrower's alternate address
559   `B_address2` MEDIUMTEXT default NULL, -- the second address line for your patron/borrower's alternate address
560   `B_city` LONGTEXT, -- the city or town for your patron/borrower's alternate address
561   `B_state` MEDIUMTEXT default NULL, -- the state for your patron/borrower's alternate address
562   `B_zipcode` TINYTEXT default NULL, -- the zip or postal code for your patron/borrower's alternate address
563   `B_country` MEDIUMTEXT, -- the country for your patron/borrower's alternate address
564   `B_email` MEDIUMTEXT, -- the patron/borrower's alternate email address
565   `B_phone` LONGTEXT, -- the patron/borrower's alternate phone number
566   `dateofbirth` date default NULL, -- the patron/borrower's date of birth (YYYY-MM-DD)
567   `branchcode` varchar(10) NOT NULL default '', -- foreign key from the branches table, includes the code of the patron/borrower's home branch
568   `categorycode` varchar(10) NOT NULL default '', -- foreign key from the categories table, includes the code of the patron category
569   `dateenrolled` date default NULL, -- date the patron was added to Koha (YYYY-MM-DD)
570   `dateexpiry` date default NULL, -- date the patron/borrower's card is set to expire (YYYY-MM-DD)
571   `date_renewed` date default NULL, -- date the patron/borrower's card was last renewed
572   `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
573   `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
574   `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 (YYYY-MM-DD)
575   `debarredcomment` VARCHAR(255) DEFAULT NULL, -- comment on the stop of patron
576   `contactname` LONGTEXT, -- used for children and profesionals to include surname or last name of guarantor or organization name
577   `contactfirstname` MEDIUMTEXT, -- used for children to include first name of guarantor
578   `contacttitle` MEDIUMTEXT, -- used for children to include title (Mr., Mrs., etc) of guarantor
579   `borrowernotes` LONGTEXT, -- a note on the patron/borrower's account that is only visible in the staff client
580   `relationship` varchar(100) default NULL, -- used for children to include the relationship to their guarantor
581   `sex` varchar(1) default NULL, -- patron/borrower's gender
582   `password` varchar(60) default NULL, -- patron/borrower's encrypted password
583   `flags` int(11) default NULL, -- will include a number associated with the staff member's permissions
584   `userid` varchar(75) default NULL, -- patron/borrower's opac and/or staff client log in
585   `opacnote` LONGTEXT, -- a note on the patron/borrower's account that is visible in the OPAC and staff client
586   `contactnote` varchar(255) default NULL, -- a note related to the patron/borrower's alternate address
587   `sort1` varchar(80) default NULL, -- a field that can be used for any information unique to the library
588   `sort2` varchar(80) default NULL, -- a field that can be used for any information unique to the library
589   `altcontactfirstname` MEDIUMTEXT default NULL, -- first name of alternate contact for the patron/borrower
590   `altcontactsurname` MEDIUMTEXT default NULL, -- surname or last name of the alternate contact for the patron/borrower
591   `altcontactaddress1` MEDIUMTEXT default NULL, -- the first address line for the alternate contact for the patron/borrower
592   `altcontactaddress2` MEDIUMTEXT default NULL, -- the second address line for the alternate contact for the patron/borrower
593   `altcontactaddress3` MEDIUMTEXT default NULL, -- the city for the alternate contact for the patron/borrower
594   `altcontactstate` MEDIUMTEXT default NULL, -- the state for the alternate contact for the patron/borrower
595   `altcontactzipcode` MEDIUMTEXT default NULL, -- the zipcode for the alternate contact for the patron/borrower
596   `altcontactcountry` MEDIUMTEXT default NULL, -- the country for the alternate contact for the patron/borrower
597   `altcontactphone` MEDIUMTEXT default NULL, -- the phone number for the alternate contact for the patron/borrower
598   `smsalertnumber` varchar(50) default NULL, -- the mobile phone number where the patron/borrower would like to receive notices (if SMS turned on)
599   `sms_provider_id` int(11) DEFAULT NULL, -- the provider of the mobile phone number defined in smsalertnumber
600   `privacy` integer(11) DEFAULT '1' NOT NULL, -- patron/borrower's privacy settings related to their reading history  KEY `borrowernumber` (`borrowernumber`),
601   `privacy_guarantor_fines` tinyint(1) NOT NULL DEFAULT '0', -- controls if relatives can see this patron's fines
602   `privacy_guarantor_checkouts` tinyint(1) NOT NULL DEFAULT '0', -- controls if relatives can see this patron's checkouts
603   `checkprevcheckout` varchar(7) NOT NULL default 'inherit', -- produce a warning for this patron if this item has previously been checked out to this patron if 'yes', not if 'no', defer to category setting if 'inherit'.
604   `updated_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, -- time of last change could be useful for synchronization with external systems (among others)
605   `lastseen` datetime default NULL, -- last time a patron has been seen (connected at the OPAC or staff interface)
606   `lang` varchar(25) NOT NULL default 'default', -- lang to use to send notices to this patron
607   `login_attempts` int(4) NOT NULL default 0, -- number of failed login attemps
608   `overdrive_auth_token` MEDIUMTEXT default NULL, -- persist OverDrive auth token
609   `anonymized` TINYINT(1) NOT NULL DEFAULT 0, -- flag for data anonymization
610   `autorenew_checkouts` TINYINT(1) NOT NULL DEFAULT 1, -- flag for allowing auto-renewal
611   KEY borrowernumber (borrowernumber),
612   KEY `cardnumber` (`cardnumber`),
613   KEY `sms_provider_id` (`sms_provider_id`)
614 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
615
616 --
617 -- Table structure for table `deleteditems`
618 --
619
620 DROP TABLE IF EXISTS `deleteditems`;
621 CREATE TABLE `deleteditems` (
622   `itemnumber` int(11) NOT NULL default 0, -- primary key and unique identifier added by Koha
623   `biblionumber` int(11) NOT NULL default 0, -- foreign key from biblio table used to link this item to the right bib record
624   `biblioitemnumber` int(11) NOT NULL default 0, -- foreign key from the biblioitems table to link to item to additional information
625   `barcode` varchar(20) default NULL, -- item barcode (MARC21 952$p)
626   `dateaccessioned` date default NULL, -- date the item was acquired or added to Koha (MARC21 952$d)
627   `booksellerid` LONGTEXT default NULL, -- where the item was purchased (MARC21 952$e)
628   `homebranch` varchar(10) default NULL, -- foreign key from the branches table for the library that owns this item (MARC21 952$a)
629   `price` decimal(8,2) default NULL, -- purchase price (MARC21 952$g)
630   `replacementprice` decimal(8,2) default NULL, -- cost the library charges to replace the item if it has been marked lost (MARC21 952$v)
631   `replacementpricedate` date default NULL, -- the date the price is effective from (MARC21 952$w)
632   `datelastborrowed` date default NULL, -- the date the item was last checked out
633   `datelastseen` date default NULL, -- the date the item was last see (usually the last time the barcode was scanned or inventory was done)
634   `stack` tinyint(1) default NULL,
635   `notforloan` tinyint(1) NOT NULL default 0, -- authorized value defining why this item is not for loan (MARC21 952$7)
636   `damaged` tinyint(1) NOT NULL default 0, -- authorized value defining this item as damaged (MARC21 952$4)
637   `damaged_on` datetime DEFAULT NULL, -- the date and time an item was last marked as damaged, NULL if not damaged
638   `itemlost` tinyint(1) NOT NULL default 0, -- authorized value defining this item as lost (MARC21 952$1)
639   `itemlost_on` datetime DEFAULT NULL, -- the date and time an item was last marked as lost, NULL if not lost
640   `withdrawn` tinyint(1) NOT NULL default 0, -- authorized value defining this item as withdrawn (MARC21 952$0)
641   `withdrawn_on` datetime DEFAULT NULL, -- the date and time an item was last marked as withdrawn, NULL if not withdrawn
642   `itemcallnumber` varchar(255) default NULL, -- call number for this item (MARC21 952$o)
643   `coded_location_qualifier` varchar(10) default NULL, -- coded location qualifier(MARC21 952$f)
644   `issues` smallint(6) default 0, -- number of times this item has been checked out
645   `renewals` smallint(6) default NULL, -- number of times this item has been renewed
646   `reserves` smallint(6) default NULL, -- number of times this item has been placed on hold/reserved
647   `restricted` tinyint(1) default NULL, -- authorized value defining use restrictions for this item (MARC21 952$5)
648   `itemnotes` LONGTEXT, -- public notes on this item (MARC21 952$z)
649   `itemnotes_nonpublic` LONGTEXT default NULL, -- non-public notes on this item (MARC21 952$x)
650   `holdingbranch` varchar(10) default NULL, -- foreign key from the branches table for the library that is currently in possession item (MARC21 952$b)
651   `paidfor` LONGTEXT,
652   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- date and time this item was last altered
653   `location` varchar(80) default NULL, -- authorized value for the shelving location for this item (MARC21 952$c)
654   `permanent_location` varchar(80) default NULL, -- linked to the CART and PROC temporary locations feature, stores the permanent shelving location
655   `onloan` date default NULL, -- defines if item is checked out (NULL for not checked out, and due date for checked out)
656   `cn_source` varchar(10) default NULL, -- classification source used on this item (MARC21 952$2)
657   `cn_sort` varchar(255) default NULL, -- normalized form of the call number (MARC21 952$o) used for sorting
658   `ccode` varchar(80) default NULL, -- authorized value for the collection code associated with this item (MARC21 952$8)
659   `materials` MEDIUMTEXT default NULL, -- materials specified (MARC21 952$3)
660   `uri` MEDIUMTEXT default NULL, -- URL for the item (MARC21 952$u)
661   `itype` varchar(10) default NULL, -- foreign key from the itemtypes table defining the type for this item (MARC21 952$y)
662   `more_subfields_xml` LONGTEXT default NULL, -- additional 952 subfields in XML format
663   `enumchron` MEDIUMTEXT default NULL, -- serial enumeration/chronology for the item (MARC21 952$h)
664   `copynumber` varchar(32) default NULL, -- copy number (MARC21 952$t)
665   `stocknumber` varchar(32) default NULL, -- inventory number (MARC21 952$i)
666   `new_status` VARCHAR(32) DEFAULT NULL, -- 'new' value, you can put whatever free-text information. This field is intented to be managed by the automatic_item_modification_by_age cronjob.
667   PRIMARY KEY  (`itemnumber`),
668   KEY `delitembarcodeidx` (`barcode`),
669   KEY `delitemstocknumberidx` (`stocknumber`),
670   KEY `delitembinoidx` (`biblioitemnumber`),
671   KEY `delitembibnoidx` (`biblionumber`),
672   KEY `delhomebranch` (`homebranch`),
673   KEY `delholdingbranch` (`holdingbranch`),
674   KEY `itype_idx` (`itype`),
675   KEY `timestamp` (`timestamp`)
676 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
677
678 --
679 -- Table structure for table `export_format`
680 --
681
682 DROP TABLE IF EXISTS `export_format`;
683 CREATE TABLE `export_format` (
684   `export_format_id` int(11) NOT NULL auto_increment,
685   `profile` varchar(255) NOT NULL,
686   `description` LONGTEXT NOT NULL,
687   `content` LONGTEXT NOT NULL,
688   `csv_separator` varchar(2) NOT NULL DEFAULT ',',
689   `field_separator` varchar(2),
690   `subfield_separator` varchar(2),
691   `encoding` varchar(255) NOT NULL DEFAULT 'utf8',
692   `type` varchar(255) DEFAULT 'marc',
693   `used_for` varchar(255) DEFAULT 'export_records',
694   PRIMARY KEY  (`export_format_id`)
695 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Used for CSV export';
696
697 --
698 -- Table structure for table `import_batches`
699 --
700
701 DROP TABLE IF EXISTS `import_batches`;
702 CREATE TABLE `import_batches` ( -- information about batches of marc records that have been imported
703   `import_batch_id` int(11) NOT NULL auto_increment, -- unique identifier and primary key
704   `matcher_id` int(11) default NULL, -- the id of the match rule used (matchpoints.matcher_id)
705   `template_id` int(11) default NULL,
706   `branchcode` varchar(10) default NULL,
707   `num_records` int(11) NOT NULL default 0, -- number of records in the file
708   `num_items` int(11) NOT NULL default 0, -- number of items in the file
709   `upload_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP, -- date and time the file was uploaded
710   `overlay_action` enum('replace', 'create_new', 'use_template', 'ignore') NOT NULL default 'create_new', -- how to handle duplicate records
711   `nomatch_action` enum('create_new', 'ignore') NOT NULL default 'create_new', -- how to handle records where no match is found
712   `item_action` enum('always_add', 'add_only_for_matches', 'add_only_for_new', 'ignore', 'replace') NOT NULL default 'always_add', -- what to do with item records
713   `import_status` enum('staging', 'staged', 'importing', 'imported', 'reverting', 'reverted', 'cleaned') NOT NULL default 'staging', -- the status of the imported file
714   `batch_type` enum('batch', 'z3950', 'webservice') NOT NULL default 'batch', -- where this batch has come from
715   `record_type` enum('biblio', 'auth', 'holdings') NOT NULL default 'biblio', -- type of record in the batch
716   `file_name` varchar(100), -- the name of the file uploaded
717   `comments` LONGTEXT, -- any comments added when the file was uploaded
718   PRIMARY KEY (`import_batch_id`),
719   KEY `branchcode` (`branchcode`)
720 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
721
722 --
723 -- Table structure for table `import_records`
724 --
725
726 DROP TABLE IF EXISTS `import_records`;
727 CREATE TABLE `import_records` (
728   `import_record_id` int(11) NOT NULL auto_increment,
729   `import_batch_id` int(11) NOT NULL,
730   `branchcode` varchar(10) default NULL,
731   `record_sequence` int(11) NOT NULL default 0,
732   `upload_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
733   `import_date` DATE default NULL,
734   `marc` longblob NOT NULL,
735   `marcxml` LONGTEXT NOT NULL,
736   `marcxml_old` LONGTEXT NOT NULL,
737   `record_type` enum('biblio', 'auth', 'holdings') NOT NULL default 'biblio',
738   `overlay_status` enum('no_match', 'auto_match', 'manual_match', 'match_applied') NOT NULL default 'no_match',
739   `status` enum('error', 'staged', 'imported', 'reverted', 'items_reverted', 'ignored') NOT NULL default 'staged',
740   `import_error` LONGTEXT,
741   `encoding` varchar(40) NOT NULL default '',
742   PRIMARY KEY (`import_record_id`),
743   CONSTRAINT `import_records_ifbk_1` FOREIGN KEY (`import_batch_id`)
744              REFERENCES `import_batches` (`import_batch_id`) ON DELETE CASCADE ON UPDATE CASCADE,
745   KEY `branchcode` (`branchcode`),
746   KEY `batch_sequence` (`import_batch_id`, `record_sequence`),
747   KEY `batch_id_record_type` (`import_batch_id`,`record_type`)
748 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
749
750 --
751 -- Table structure for `import_record_matches`
752 --
753 DROP TABLE IF EXISTS `import_record_matches`;
754 CREATE TABLE `import_record_matches` ( -- matches found when importing a batch of records
755   `import_record_id` int(11) NOT NULL, -- the id given to the imported bib record (import_records.import_record_id)
756   `candidate_match_id` int(11) NOT NULL, -- the biblio the imported record matches (biblio.biblionumber)
757   `score` int(11) NOT NULL default 0, -- the match score
758   CONSTRAINT `import_record_matches_ibfk_1` FOREIGN KEY (`import_record_id`)
759              REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
760   KEY `record_score` (`import_record_id`, `score`)
761 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
762
763 --
764 -- Table structure for table `import_auths`
765 --
766
767 DROP TABLE IF EXISTS `import_auths`;
768 CREATE TABLE `import_auths` (
769   `import_record_id` int(11) NOT NULL,
770   `matched_authid` int(11) default NULL,
771   `control_number` varchar(25) default NULL,
772   `authorized_heading` varchar(128) default NULL,
773   `original_source` varchar(25) default NULL,
774   CONSTRAINT `import_auths_ibfk_1` FOREIGN KEY (`import_record_id`)
775              REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
776   KEY `matched_authid` (`matched_authid`)
777 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
778
779 --
780 -- Table structure for table `import_biblios`
781 --
782
783 DROP TABLE IF EXISTS `import_biblios`;
784 CREATE TABLE `import_biblios` (
785   `import_record_id` int(11) NOT NULL,
786   `matched_biblionumber` int(11) default NULL,
787   `control_number` varchar(25) default NULL,
788   `original_source` varchar(25) default NULL,
789   `title` varchar(128) default NULL,
790   `author` varchar(80) default NULL,
791   `isbn` varchar(30) default NULL,
792   `issn` varchar(9) default NULL,
793   `has_items` tinyint(1) NOT NULL default 0,
794   CONSTRAINT `import_biblios_ibfk_1` FOREIGN KEY (`import_record_id`)
795              REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
796   KEY `matched_biblionumber` (`matched_biblionumber`),
797   KEY `title` (`title`),
798   KEY `isbn` (`isbn`)
799 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
800
801 --
802 -- Table structure for table `import_items`
803 --
804
805 DROP TABLE IF EXISTS `import_items`;
806 CREATE TABLE `import_items` (
807   `import_items_id` int(11) NOT NULL auto_increment,
808   `import_record_id` int(11) NOT NULL,
809   `itemnumber` int(11) default NULL,
810   `branchcode` varchar(10) default NULL,
811   `status` enum('error', 'staged', 'imported', 'reverted', 'ignored') NOT NULL default 'staged',
812   `marcxml` LONGTEXT NOT NULL,
813   `import_error` LONGTEXT,
814   PRIMARY KEY (`import_items_id`),
815   CONSTRAINT `import_items_ibfk_1` FOREIGN KEY (`import_record_id`)
816              REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
817   KEY `itemnumber` (`itemnumber`),
818   KEY `branchcode` (`branchcode`)
819 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
820
821 --
822 -- Table structure for table `items`
823 --
824
825 DROP TABLE IF EXISTS `items`;
826 CREATE TABLE `items` ( -- holdings/item information
827   `itemnumber` int(11) NOT NULL auto_increment, -- primary key and unique identifier added by Koha
828   `biblionumber` int(11) NOT NULL default 0, -- foreign key from biblio table used to link this item to the right bib record
829   `biblioitemnumber` int(11) NOT NULL default 0, -- foreign key from the biblioitems table to link to item to additional information
830   `barcode` varchar(20) default NULL, -- item barcode (MARC21 952$p)
831   `dateaccessioned` date default NULL, -- date the item was acquired or added to Koha (MARC21 952$d)
832   `booksellerid` LONGTEXT default NULL, -- where the item was purchased (MARC21 952$e)
833   `homebranch` varchar(10) default NULL, -- foreign key from the branches table for the library that owns this item (MARC21 952$a)
834   `price` decimal(8,2) default NULL, -- purchase price (MARC21 952$g)
835   `replacementprice` decimal(8,2) default NULL, -- cost the library charges to replace the item if it has been marked lost (MARC21 952$v)
836   `replacementpricedate` date default NULL, -- the date the price is effective from (MARC21 952$w)
837   `datelastborrowed` date default NULL, -- the date the item was last checked out/issued
838   `datelastseen` date default NULL, -- the date the item was last see (usually the last time the barcode was scanned or inventory was done)
839   `stack` tinyint(1) default NULL,
840   `notforloan` tinyint(1) NOT NULL default 0, -- authorized value defining why this item is not for loan (MARC21 952$7)
841   `damaged` tinyint(1) NOT NULL default 0, -- authorized value defining this item as damaged (MARC21 952$4)
842   `damaged_on` datetime DEFAULT NULL, -- the date and time an item was last marked as damaged, NULL if not damaged
843   `itemlost` tinyint(1) NOT NULL default 0, -- authorized value defining this item as lost (MARC21 952$1)
844   `itemlost_on` datetime DEFAULT NULL, -- the date and time an item was last marked as lost, NULL if not lost
845   `withdrawn` tinyint(1) NOT NULL default 0, -- authorized value defining this item as withdrawn (MARC21 952$0)
846   `withdrawn_on` datetime DEFAULT NULL, -- the date and time an item was last marked as withdrawn, NULL if not withdrawn
847   `itemcallnumber` varchar(255) default NULL, -- call number for this item (MARC21 952$o)
848   `coded_location_qualifier` varchar(10) default NULL, -- coded location qualifier(MARC21 952$f)
849   `issues` smallint(6) default 0, -- number of times this item has been checked out/issued
850   `renewals` smallint(6) default NULL, -- number of times this item has been renewed
851   `reserves` smallint(6) default NULL, -- number of times this item has been placed on hold/reserved
852   `restricted` tinyint(1) default NULL, -- authorized value defining use restrictions for this item (MARC21 952$5)
853   `itemnotes` LONGTEXT, -- public notes on this item (MARC21 952$z)
854   `itemnotes_nonpublic` LONGTEXT default NULL, -- non-public notes on this item (MARC21 952$x)
855   `holdingbranch` varchar(10) default NULL, -- foreign key from the branches table for the library that is currently in possession item (MARC21 952$b)
856   `paidfor` LONGTEXT,
857   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- date and time this item was last altered
858   `location` varchar(80) default NULL, -- authorized value for the shelving location for this item (MARC21 952$c)
859   `permanent_location` varchar(80) default NULL, -- linked to the CART and PROC temporary locations feature, stores the permanent shelving location
860   `onloan` date default NULL, -- defines if item is checked out (NULL for not checked out, and due date for checked out)
861   `cn_source` varchar(10) default NULL, -- classification source used on this item (MARC21 952$2)
862   `cn_sort` varchar(255) default NULL,  -- normalized form of the call number (MARC21 952$o) used for sorting
863   `ccode` varchar(80) default NULL, -- authorized value for the collection code associated with this item (MARC21 952$8)
864   `materials` MEDIUMTEXT default NULL, -- materials specified (MARC21 952$3)
865   `uri` MEDIUMTEXT default NULL, -- URL for the item (MARC21 952$u)
866   `itype` varchar(10) default NULL, -- foreign key from the itemtypes table defining the type for this item (MARC21 952$y)
867   `more_subfields_xml` LONGTEXT default NULL, -- additional 952 subfields in XML format
868   `enumchron` MEDIUMTEXT default NULL, -- serial enumeration/chronology for the item (MARC21 952$h)
869   `copynumber` varchar(32) default NULL, -- copy number (MARC21 952$t)
870   `stocknumber` varchar(32) default NULL, -- inventory number (MARC21 952$i)
871   `new_status` VARCHAR(32) DEFAULT NULL, -- 'new' value, you can put whatever free-text information. This field is intented to be managed by the automatic_item_modification_by_age cronjob.
872   PRIMARY KEY  (`itemnumber`),
873   UNIQUE KEY `itembarcodeidx` (`barcode`),
874   KEY `itemstocknumberidx` (`stocknumber`),
875   KEY `itembinoidx` (`biblioitemnumber`),
876   KEY `itembibnoidx` (`biblionumber`),
877   KEY `homebranch` (`homebranch`),
878   KEY `holdingbranch` (`holdingbranch`),
879   KEY `itemcallnumber` (`itemcallnumber` (191)),
880   KEY `items_location` (`location`),
881   KEY `items_ccode` (`ccode`),
882   KEY `itype_idx` (`itype`),
883   KEY `timestamp` (`timestamp`),
884   CONSTRAINT `items_ibfk_1` FOREIGN KEY (`biblioitemnumber`) REFERENCES `biblioitems` (`biblioitemnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
885   CONSTRAINT `items_ibfk_2` FOREIGN KEY (`homebranch`) REFERENCES `branches` (`branchcode`) ON UPDATE CASCADE,
886   CONSTRAINT `items_ibfk_3` FOREIGN KEY (`holdingbranch`) REFERENCES `branches` (`branchcode`) ON UPDATE CASCADE,
887   CONSTRAINT `items_ibfk_4` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
888 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
889
890 --
891 -- Table structure for table `itemtypes`
892 --
893
894 DROP TABLE IF EXISTS `itemtypes`;
895 CREATE TABLE `itemtypes` ( -- defines the item types
896   itemtype varchar(10) NOT NULL default '', -- unique key, a code associated with the item type
897   description LONGTEXT, -- a plain text explanation of the item type
898   rentalcharge decimal(28,6) default NULL, -- the amount charged when this item is checked out/issued
899   rentalcharge_daily decimal(28,6) default NULL, -- the amount charged for each day between checkout date and due date
900   rentalcharge_daily_calendar tinyint(1) NOT NULL DEFAULT 1, -- controls if the daily retnal fee is calculated directly or using finesCalendar
901   rentalcharge_hourly decimal(28,6) default NULL, -- the amount charged for each hour between checkout date and due date
902   rentalcharge_hourly_calendar tinyint(1) NOT NULL DEFAULT 1, -- controls if the hourly retnal fee is calculated directly or using finesCalendar
903   defaultreplacecost decimal(28,6) default NULL, -- default replacement cost
904   processfee decimal(28,6) default NULL, -- default text be recorded in the column note when the processing fee is applied
905   notforloan smallint(6) default NULL, -- 1 if the item is not for loan, 0 if the item is available for loan
906   imageurl varchar(200) default NULL, -- URL for the item type icon
907   summary MEDIUMTEXT, -- information from the summary field, may include HTML
908   checkinmsg VARCHAR(255), -- message that is displayed when an item with the given item type is checked in
909   checkinmsgtype CHAR(16) DEFAULT 'message' NOT NULL, -- type (CSS class) for the checkinmsg, can be "alert" or "message"
910   sip_media_type VARCHAR(3) DEFAULT NULL, -- SIP2 protocol media type for this itemtype
911   hideinopac tinyint(1) NOT NULL DEFAULT 0, -- Hide the item type from the search options in OPAC
912   searchcategory varchar(80) default NULL, -- Group this item type with others with the same value on OPAC search options
913   PRIMARY KEY  (`itemtype`),
914   UNIQUE KEY `itemtype` (`itemtype`)
915 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
916
917 --
918 -- Table structure for table `branchtransfers`
919 --
920
921 DROP TABLE IF EXISTS `branchtransfers`;
922 CREATE TABLE `branchtransfers` ( -- information for items that are in transit between branches
923   `branchtransfer_id` int(12) NOT NULL auto_increment, -- primary key
924   `itemnumber` int(11) NOT NULL default 0, -- the itemnumber that it is in transit (items.itemnumber)
925   `datesent` datetime default NULL, -- the date the transfer was initialized
926   `frombranch` varchar(10) NOT NULL default '', -- the branch the transfer is coming from
927   `datearrived` datetime default NULL, -- the date the transfer arrived at its destination
928   `tobranch` varchar(10) NOT NULL default '', -- the branch the transfer was going to
929   `comments` LONGTEXT, -- any comments related to the transfer
930   `reason` ENUM('Manual', 'StockrotationAdvance', 'StockrotationRepatriation', 'ReturnToHome', 'ReturnToHolding', 'RotatingCollection', 'Reserve', 'LostReserve', 'CancelReserve'), -- what triggered the transfer
931   PRIMARY KEY (`branchtransfer_id`),
932   KEY `frombranch` (`frombranch`),
933   KEY `tobranch` (`tobranch`),
934   KEY `itemnumber` (`itemnumber`),
935   CONSTRAINT `branchtransfers_ibfk_1` FOREIGN KEY (`frombranch`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE,
936   CONSTRAINT `branchtransfers_ibfk_2` FOREIGN KEY (`tobranch`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE,
937   CONSTRAINT `branchtransfers_ibfk_3` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE
938 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
939
940 --
941 -- Table structure for table `creator_images`
942 --
943
944 DROP TABLE IF EXISTS `creator_images`;
945 SET @saved_cs_client     = @@character_set_client;
946 SET character_set_client = utf8;
947 CREATE TABLE `creator_images` (
948   `image_id` int(4) NOT NULL AUTO_INCREMENT,
949   `imagefile` mediumblob,
950   `image_name` char(20) NOT NULL DEFAULT 'DEFAULT',
951   PRIMARY KEY (`image_id`),
952   UNIQUE KEY `image_name_index` (`image_name`)
953 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
954
955 --
956 -- Table structure for table `creator_layouts`
957 --
958
959 DROP TABLE IF EXISTS `creator_layouts`;
960 SET @saved_cs_client     = @@character_set_client;
961 SET character_set_client = utf8;
962 CREATE TABLE `creator_layouts` (
963   `layout_id` int(4) NOT NULL AUTO_INCREMENT,
964   `barcode_type` char(100) NOT NULL DEFAULT 'CODE39',
965   `start_label` int(2) NOT NULL DEFAULT '1',
966   `printing_type` char(32) NOT NULL DEFAULT 'BAR',
967   `layout_name` char(25) NOT NULL DEFAULT 'DEFAULT',
968   `guidebox` int(1) DEFAULT '0',
969   `oblique_title` int(1) DEFAULT '1',
970   `font` char(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'TR',
971   `font_size` int(4) NOT NULL DEFAULT '10',
972   `units` char(20) NOT NULL DEFAULT 'POINT',
973   `callnum_split` int(1) DEFAULT '0',
974   `text_justify` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'L',
975   `format_string` varchar(210) NOT NULL DEFAULT 'barcode',
976   `layout_xml` MEDIUMTEXT NOT NULL,
977   `creator` char(15) NOT NULL DEFAULT 'Labels',
978   PRIMARY KEY (`layout_id`)
979 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
980
981 --
982 -- Table structure for table `creator_templates`
983 --
984
985 DROP TABLE IF EXISTS `creator_templates`;
986 SET @saved_cs_client     = @@character_set_client;
987 SET character_set_client = utf8;
988 CREATE TABLE `creator_templates` (
989   `template_id` int(4) NOT NULL AUTO_INCREMENT,
990   `profile_id` int(4) DEFAULT NULL,
991   `template_code` char(100) NOT NULL DEFAULT 'DEFAULT TEMPLATE',
992   `template_desc` char(100) NOT NULL DEFAULT 'Default description',
993   `page_width` float NOT NULL DEFAULT '0',
994   `page_height` float NOT NULL DEFAULT '0',
995   `label_width` float NOT NULL DEFAULT '0',
996   `label_height` float NOT NULL DEFAULT '0',
997   `top_text_margin` float NOT NULL DEFAULT '0',
998   `left_text_margin` float NOT NULL DEFAULT '0',
999   `top_margin` float NOT NULL DEFAULT '0',
1000   `left_margin` float NOT NULL DEFAULT '0',
1001   `cols` int(2) NOT NULL DEFAULT '0',
1002   `rows` int(2) NOT NULL DEFAULT '0',
1003   `col_gap` float NOT NULL DEFAULT '0',
1004   `row_gap` float NOT NULL DEFAULT '0',
1005   `units` char(20) NOT NULL DEFAULT 'POINT',
1006   `creator` char(15) NOT NULL DEFAULT 'Labels',
1007   PRIMARY KEY (`template_id`),
1008   KEY `template_profile_fk_constraint` (`profile_id`)
1009 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1010
1011 --
1012 -- Table structure for table `marc_subfield_structure`
1013 --
1014
1015 DROP TABLE IF EXISTS `marc_subfield_structure`;
1016 CREATE TABLE `marc_subfield_structure` (
1017   `tagfield` varchar(3) NOT NULL default '',
1018   `tagsubfield` varchar(1) NOT NULL default '' COLLATE utf8mb4_bin,
1019   `liblibrarian` varchar(255) NOT NULL default '',
1020   `libopac` varchar(255) NOT NULL default '',
1021   `repeatable` tinyint(4) NOT NULL default 0,
1022   `mandatory` tinyint(4) NOT NULL default 0,
1023   `important` tinyint(4) NOT NULL DEFAULT '0',
1024   `kohafield` varchar(40) default NULL,
1025   `tab` tinyint(1) default NULL,
1026   `authorised_value` varchar(32) default NULL,
1027   `authtypecode` varchar(20) default NULL,
1028   `value_builder` varchar(80) default NULL,
1029   `isurl` tinyint(1) default NULL,
1030   `hidden` tinyint(1) NOT NULL default 8,
1031   `frameworkcode` varchar(4) NOT NULL default '',
1032   `seealso` varchar(1100) default NULL,
1033   `link` varchar(80) default NULL,
1034   `defaultvalue` MEDIUMTEXT default NULL,
1035   `maxlength` int(4) NOT NULL DEFAULT '9999',
1036   PRIMARY KEY  (`frameworkcode`,`tagfield`,`tagsubfield`),
1037   KEY `kohafield_2` (`kohafield`),
1038   KEY `tab` (`frameworkcode`,`tab`),
1039   KEY `kohafield` (`frameworkcode`,`kohafield`),
1040   CONSTRAINT `marc_subfield_structure_ibfk_1` FOREIGN KEY (`authorised_value`) REFERENCES `authorised_value_categories` (`category_name`) ON DELETE SET NULL ON UPDATE CASCADE
1041 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1042
1043 --
1044 -- Table structure for table `marc_tag_structure`
1045 --
1046
1047 DROP TABLE IF EXISTS `marc_tag_structure`;
1048 CREATE TABLE `marc_tag_structure` (
1049   `tagfield` varchar(3) NOT NULL default '',
1050   `liblibrarian` varchar(255) NOT NULL default '',
1051   `libopac` varchar(255) NOT NULL default '',
1052   `repeatable` tinyint(4) NOT NULL default 0,
1053   `mandatory` tinyint(4) NOT NULL default 0,
1054   `important` tinyint(4) NOT NULL DEFAULT '0',
1055   `authorised_value` varchar(10) default NULL,
1056   `ind1_defaultvalue` varchar(1) NOT NULL default '',
1057   `ind2_defaultvalue` varchar(1) NOT NULL default '',
1058   `frameworkcode` varchar(4) NOT NULL default '',
1059   PRIMARY KEY  (`frameworkcode`,`tagfield`)
1060 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1061
1062 --
1063 -- Table structure for table `marc_matchers`
1064 --
1065
1066 DROP TABLE IF EXISTS `marc_matchers`;
1067 CREATE TABLE `marc_matchers` (
1068   `matcher_id` int(11) NOT NULL auto_increment,
1069   `code` varchar(10) NOT NULL default '',
1070   `description` varchar(255) NOT NULL default '',
1071   `record_type` varchar(10) NOT NULL default 'biblio',
1072   `threshold` int(11) NOT NULL default 0,
1073   PRIMARY KEY (`matcher_id`),
1074   KEY `code` (`code`),
1075   KEY `record_type` (`record_type`)
1076 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1077
1078 --
1079 -- Table structure for table `matchpoints`
1080 --
1081 DROP TABLE IF EXISTS `matchpoints`;
1082 CREATE TABLE `matchpoints` (
1083   `matcher_id` int(11) NOT NULL,
1084   `matchpoint_id` int(11) NOT NULL auto_increment,
1085   `search_index` varchar(30) NOT NULL default '',
1086   `score` int(11) NOT NULL default 0,
1087   PRIMARY KEY (`matchpoint_id`),
1088   CONSTRAINT `matchpoints_ifbk_1` FOREIGN KEY (`matcher_id`)
1089   REFERENCES `marc_matchers` (`matcher_id`) ON DELETE CASCADE ON UPDATE CASCADE
1090 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1091
1092
1093 --
1094 -- Table structure for table `matchpoint_components`
1095 --
1096 DROP TABLE IF EXISTS `matchpoint_components`;
1097 CREATE TABLE `matchpoint_components` (
1098   `matchpoint_id` int(11) NOT NULL,
1099   `matchpoint_component_id` int(11) NOT NULL auto_increment,
1100   sequence int(11) NOT NULL default 0,
1101   tag varchar(3) NOT NULL default '',
1102   subfields varchar(40) NOT NULL default '',
1103   offset int(4) NOT NULL default 0,
1104   length int(4) NOT NULL default 0,
1105   PRIMARY KEY (`matchpoint_component_id`),
1106   KEY `by_sequence` (`matchpoint_id`, `sequence`),
1107   CONSTRAINT `matchpoint_components_ifbk_1` FOREIGN KEY (`matchpoint_id`)
1108   REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE
1109 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1110
1111 --
1112 -- Table structure for table `matcher_component_norms`
1113 --
1114 DROP TABLE IF EXISTS `matchpoint_component_norms`;
1115 CREATE TABLE `matchpoint_component_norms` (
1116   `matchpoint_component_id` int(11) NOT NULL,
1117   `sequence`  int(11) NOT NULL default 0,
1118   `norm_routine` varchar(50) NOT NULL default '',
1119   KEY `matchpoint_component_norms` (`matchpoint_component_id`, `sequence`),
1120   CONSTRAINT `matchpoint_component_norms_ifbk_1` FOREIGN KEY (`matchpoint_component_id`)
1121   REFERENCES `matchpoint_components` (`matchpoint_component_id`) ON DELETE CASCADE ON UPDATE CASCADE
1122 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1123
1124 --
1125 -- Table structure for table `matcher_matchpoints`
1126 --
1127 DROP TABLE IF EXISTS `matcher_matchpoints`;
1128 CREATE TABLE `matcher_matchpoints` (
1129   `matcher_id` int(11) NOT NULL,
1130   `matchpoint_id` int(11) NOT NULL,
1131   CONSTRAINT `matcher_matchpoints_ifbk_1` FOREIGN KEY (`matcher_id`)
1132   REFERENCES `marc_matchers` (`matcher_id`) ON DELETE CASCADE ON UPDATE CASCADE,
1133   CONSTRAINT `matcher_matchpoints_ifbk_2` FOREIGN KEY (`matchpoint_id`)
1134   REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE
1135 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1136
1137 --
1138 -- Table structure for table `matchchecks`
1139 --
1140 DROP TABLE IF EXISTS `matchchecks`;
1141 CREATE TABLE `matchchecks` (
1142   `matcher_id` int(11) NOT NULL,
1143   `matchcheck_id` int(11) NOT NULL auto_increment,
1144   `source_matchpoint_id` int(11) NOT NULL,
1145   `target_matchpoint_id` int(11) NOT NULL,
1146   PRIMARY KEY (`matchcheck_id`),
1147   CONSTRAINT `matcher_matchchecks_ifbk_1` FOREIGN KEY (`matcher_id`)
1148   REFERENCES `marc_matchers` (`matcher_id`) ON DELETE CASCADE ON UPDATE CASCADE,
1149   CONSTRAINT `matcher_matchchecks_ifbk_2` FOREIGN KEY (`source_matchpoint_id`)
1150   REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE,
1151   CONSTRAINT `matcher_matchchecks_ifbk_3` FOREIGN KEY (`target_matchpoint_id`)
1152   REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE
1153 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1154
1155 --
1156 -- Table structure for table `need_merge_authorities`
1157 --
1158
1159 DROP TABLE IF EXISTS `need_merge_authorities`;
1160 CREATE TABLE `need_merge_authorities` ( -- keeping track of authority records still to be merged by merge_authority cron job
1161   `id` int NOT NULL auto_increment PRIMARY KEY, -- unique id
1162   `authid` bigint NOT NULL, -- reference to original authority record
1163   `authid_new` bigint, -- reference to optional new authority record
1164   `reportxml` MEDIUMTEXT, -- xml showing original reporting tag
1165   `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, -- date and time last modified
1166   `done` tinyint DEFAULT 0  -- indication whether merge has been executed (0=not done, 1=done, 2=in progress)
1167 -- Note: authid and authid_new should NOT be FOREIGN keys !
1168 -- authid may have been deleted; authid_new may be zero
1169 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1170
1171 --
1172 -- Table structure for table `oai_sets`
1173 --
1174
1175 DROP TABLE IF EXISTS `oai_sets`;
1176 CREATE TABLE `oai_sets` (
1177   `id` int(11) NOT NULL auto_increment,
1178   `spec` varchar(80) NOT NULL UNIQUE,
1179   `name` varchar(80) NOT NULL,
1180   PRIMARY KEY (`id`)
1181 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1182
1183 --
1184 -- Table structure for table `oai_sets_descriptions`
1185 --
1186
1187 DROP TABLE IF EXISTS `oai_sets_descriptions`;
1188 CREATE TABLE `oai_sets_descriptions` (
1189   `set_id` int(11) NOT NULL,
1190   `description` varchar(255) NOT NULL,
1191   CONSTRAINT `oai_sets_descriptions_ibfk_1` FOREIGN KEY (`set_id`) REFERENCES `oai_sets` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1192 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1193
1194 --
1195 -- Table structure for table `oai_sets_mappings`
1196 --
1197
1198 DROP TABLE IF EXISTS `oai_sets_mappings`;
1199 CREATE TABLE `oai_sets_mappings` (
1200   `set_id` int(11) NOT NULL,
1201   `rule_order` int NULL,
1202   `rule_operator` varchar(3) NULL,
1203   `marcfield` char(3) NOT NULL,
1204   `marcsubfield` char(1) NOT NULL,
1205   `operator` varchar(8) NOT NULL default 'equal',
1206   `marcvalue` varchar(80) NOT NULL,
1207   CONSTRAINT `oai_sets_mappings_ibfk_1` FOREIGN KEY (`set_id`) REFERENCES `oai_sets` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1208 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1209
1210 --
1211 -- Table structure for table `oai_sets_biblios`
1212 --
1213
1214 DROP TABLE IF EXISTS `oai_sets_biblios`;
1215 CREATE TABLE `oai_sets_biblios` (
1216   `biblionumber` int(11) NOT NULL,
1217   `set_id` int(11) NOT NULL,
1218   PRIMARY KEY (`biblionumber`, `set_id`),
1219   CONSTRAINT `oai_sets_biblios_ibfk_2` FOREIGN KEY (`set_id`) REFERENCES `oai_sets` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
1220 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1221
1222 --
1223 -- Table structure for table `overduerules`
1224 --
1225
1226 DROP TABLE IF EXISTS `overduerules`;
1227 CREATE TABLE `overduerules` ( -- overdue notice status and triggers
1228   `overduerules_id` int(11) NOT NULL AUTO_INCREMENT, -- unique identifier for the overduerules
1229   `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)
1230   `categorycode` varchar(10) NOT NULL default '', -- foreign key from the categories table to define which patron category this rule is for
1231   `delay1` int(4) default NULL, -- number of days after the item is overdue that the first notice is sent
1232   `letter1` varchar(20) default NULL, -- foreign key from the letter table to define which notice should be sent as the first notice
1233   `debarred1` varchar(1) default 0, -- is the patron restricted when the first notice is sent (1 for yes, 0 for no)
1234   `delay2` int(4) default NULL, -- number of days after the item is overdue that the second notice is sent
1235   `debarred2` varchar(1) default 0, -- is the patron restricted when the second notice is sent (1 for yes, 0 for no)
1236   `letter2` varchar(20) default NULL, -- foreign key from the letter table to define which notice should be sent as the second notice
1237   `delay3` int(4) default NULL, -- number of days after the item is overdue that the third notice is sent
1238   `letter3` varchar(20) default NULL, -- foreign key from the letter table to define which notice should be sent as the third notice
1239   `debarred3` int(1) default 0, -- is the patron restricted when the third notice is sent (1 for yes, 0 for no)
1240   PRIMARY KEY  (`overduerules_id`),
1241   UNIQUE KEY `overduerules_branch_cat` (`branchcode`,`categorycode`)
1242 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1243
1244 -- Table structure for table `pending_offline_operations`
1245 --
1246 -- this table is MyISAM, InnoDB tables are growing only and this table is filled/emptied/filled/emptied...
1247 -- so MyISAM is better in this case
1248
1249 DROP TABLE IF EXISTS `pending_offline_operations`;
1250 CREATE TABLE pending_offline_operations (
1251   operationid int(11) NOT NULL AUTO_INCREMENT,
1252   userid varchar(30) NOT NULL,
1253   branchcode varchar(10) NOT NULL,
1254   `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
1255   `action` varchar(10) NOT NULL,
1256   barcode varchar(20) DEFAULT NULL,
1257   cardnumber varchar(32) DEFAULT NULL,
1258   amount decimal(28,6) DEFAULT NULL,
1259   PRIMARY KEY (operationid)
1260 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1261
1262 --
1263 -- Table structure for table `printers_profile`
1264 --
1265
1266 DROP TABLE IF EXISTS `printers_profile`;
1267 CREATE TABLE `printers_profile` (
1268   `profile_id` int(4) NOT NULL auto_increment,
1269   `printer_name` varchar(40) NOT NULL default 'Default Printer',
1270   `template_id` int(4) NOT NULL default '0',
1271   `paper_bin` varchar(20) NOT NULL default 'Bypass',
1272   `offset_horz` float NOT NULL default '0',
1273   `offset_vert` float NOT NULL default '0',
1274   `creep_horz` float NOT NULL default '0',
1275   `creep_vert` float NOT NULL default '0',
1276   `units` char(20) NOT NULL default 'POINT',
1277   `creator` char(15) NOT NULL DEFAULT 'Labels',
1278   PRIMARY KEY  (`profile_id`),
1279   UNIQUE KEY `printername` (`printer_name`,`template_id`,`paper_bin`,`creator`)
1280 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1281
1282 --
1283 -- Table structure for table `repeatable_holidays`
1284 --
1285
1286 DROP TABLE IF EXISTS `repeatable_holidays`;
1287 CREATE TABLE `repeatable_holidays` ( -- information for the days the library is closed
1288   `id` int(11) NOT NULL auto_increment, -- unique identifier assigned by Koha
1289   `branchcode` varchar(10) NOT NULL, -- foreign key from the branches table, defines which branch this closing is for
1290   `weekday` smallint(6) default NULL, -- day of the week (0=Sunday, 1=Monday, etc) this closing is repeated on
1291   `day` smallint(6) default NULL, -- day of the month this closing is on
1292   `month` smallint(6) default NULL, -- month this closing is in
1293   `title` varchar(50) NOT NULL default '', -- title of this closing
1294   `description` MEDIUMTEXT NOT NULL, -- description for this closing
1295   PRIMARY KEY  (`id`),
1296   CONSTRAINT `repeatable_holidays_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
1297 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1298
1299 --
1300 -- Table structure for table `reports_dictionary`
1301 --
1302
1303 DROP TABLE IF EXISTS `reports_dictionary`;
1304 CREATE TABLE reports_dictionary ( -- definitions (or snippets of SQL) stored for use in reports
1305    `id` int(11) NOT NULL auto_increment, -- unique identifier assigned by Koha
1306    `name` varchar(255) default NULL, -- name for this definition
1307    `description` MEDIUMTEXT, -- description for this definition
1308    `date_created` datetime default NULL, -- date and time this definition was created
1309    `date_modified` datetime default NULL, -- date and time this definition was last modified
1310    `saved_sql` MEDIUMTEXT, -- SQL snippet for us in reports
1311    report_area varchar(6) DEFAULT NULL, -- Koha module this definition is for Circulation, Catalog, Patrons, Acquistions, Accounts)
1312    PRIMARY KEY  (id),
1313    KEY dictionary_area_idx (report_area)
1314 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1315
1316 --
1317 -- Table structure for table `saved_sql`
1318 --
1319
1320 DROP TABLE IF EXISTS `saved_sql`;
1321 CREATE TABLE saved_sql ( -- saved sql reports
1322    `id` int(11) NOT NULL auto_increment, -- unique id and primary key assigned by Koha
1323    `borrowernumber` int(11) default NULL, -- the staff member who created this report (borrowers.borrowernumber)
1324    `date_created` datetime default NULL, -- the date this report was created
1325    `last_modified` datetime default NULL, -- the date this report was last edited
1326    `savedsql` MEDIUMTEXT, -- the SQL for this report
1327    `last_run` datetime default NULL,
1328    `report_name` varchar(255) NOT NULL default '', -- the name of this report
1329    `type` varchar(255) default NULL, -- always 1 for tabular
1330    `notes` MEDIUMTEXT, -- the notes or description given to this report
1331    `cache_expiry` int NOT NULL default 300,
1332    `public` tinyint(1) NOT NULL default FALSE,
1333     report_area varchar(6) default NULL,
1334     report_group varchar(80) default NULL,
1335     report_subgroup varchar(80) default NULL,
1336     `mana_id` int(11) NULL DEFAULT NULL,
1337    PRIMARY KEY  (`id`),
1338    KEY sql_area_group_idx (report_group, report_subgroup),
1339    KEY boridx (`borrowernumber`)
1340 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1341
1342
1343 --
1344 -- Table structure for `saved_reports`
1345 --
1346
1347 DROP TABLE IF EXISTS `saved_reports`;
1348 CREATE TABLE saved_reports (
1349    `id` int(11) NOT NULL auto_increment,
1350    `report_id` int(11) default NULL,
1351    `report` LONGTEXT,
1352    `date_run` datetime default NULL,
1353    PRIMARY KEY (`id`)
1354 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1355
1356 --
1357 -- Table structure for table 'search_field'
1358 --
1359
1360 DROP TABLE IF EXISTS search_field;
1361 CREATE TABLE `search_field` (
1362   `id` int(11) NOT NULL AUTO_INCREMENT,
1363   `name` varchar(255) NOT NULL COMMENT 'the name of the field as it will be stored in the search engine',
1364   `label` varchar(255) NOT NULL COMMENT 'the human readable name of the field, for display',
1365   `type` ENUM('', 'string', 'date', 'number', 'boolean', 'sum', 'isbn', 'stdno') NOT NULL COMMENT 'what type of data this holds, relevant when storing it in the search engine',
1366   `weight` decimal(5,2) DEFAULT NULL,
1367   `facet_order` TINYINT(4) DEFAULT NULL COMMENT 'the order place of the field in facet list if faceted',
1368   `staff_client` tinyint(1) NOT NULL DEFAULT 1,
1369   `opac` tinyint(1) NOT NULL DEFAULT 1,
1370   PRIMARY KEY (`id`),
1371   UNIQUE KEY (`name` (191))
1372 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1373
1374 --
1375 -- Table structure for table `search_history`
1376 --
1377
1378 DROP TABLE IF EXISTS `search_history`;
1379 CREATE TABLE IF NOT EXISTS `search_history` ( -- patron's opac search history
1380   `id` int(11) NOT NULL auto_increment, -- search history id
1381   `userid` int(11) NOT NULL, -- the patron who performed the search (borrowers.borrowernumber)
1382   `sessionid` varchar(32) NOT NULL, -- a system generated session id
1383   `query_desc` varchar(255) NOT NULL, -- the search that was performed
1384   `query_cgi` MEDIUMTEXT NOT NULL, -- the string to append to the search url to rerun the search
1385   `type` varchar(16) NOT NULL DEFAULT 'biblio', -- search type, must be 'biblio' or 'authority'
1386   `total` int(11) NOT NULL, -- the total of results found
1387   `time` timestamp NOT NULL default CURRENT_TIMESTAMP, -- the date and time the search was run
1388   KEY `userid` (`userid`),
1389   KEY `sessionid` (`sessionid`),
1390   PRIMARY KEY (`id`)
1391 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Opac search history results';
1392
1393 --
1394 -- Table structure for table 'search_marc_map'
1395 --
1396
1397 DROP TABLE IF EXISTS search_marc_map;
1398 CREATE TABLE `search_marc_map` (
1399   id int(11) NOT NULL AUTO_INCREMENT,
1400   index_name ENUM('biblios','authorities') NOT NULL COMMENT 'what storage index this map is for',
1401   marc_type ENUM('marc21', 'unimarc', 'normarc') COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'what MARC type this map is for',
1402   marc_field VARCHAR(255) NOT NULL COLLATE utf8mb4_bin COMMENT 'the MARC specifier for this field',
1403   PRIMARY KEY(`id`),
1404   UNIQUE key `index_name` (`index_name`, `marc_field` (191), `marc_type`),
1405   INDEX (`index_name`)
1406 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1407
1408 --
1409 -- Table structure for table 'search_marc_to_field'
1410 --
1411
1412 DROP TABLE IF EXISTS search_marc_to_field;
1413 CREATE TABLE `search_marc_to_field` (
1414   search tinyint(1) NOT NULL DEFAULT 1,
1415   search_marc_map_id int(11) NOT NULL,
1416   search_field_id int(11) NOT NULL,
1417   facet tinyint(1) DEFAULT FALSE COMMENT 'true if a facet field should be generated for this',
1418   suggestible tinyint(1) DEFAULT FALSE COMMENT 'true if this field can be used to generate suggestions for browse',
1419   sort tinyint(1) DEFAULT NULL COMMENT 'true/false creates special sort handling, null doesn''t',
1420   PRIMARY KEY(search_marc_map_id, search_field_id),
1421   FOREIGN KEY(search_marc_map_id) REFERENCES search_marc_map(id) ON DELETE CASCADE ON UPDATE CASCADE,
1422   FOREIGN KEY(search_field_id) REFERENCES search_field(id) ON DELETE CASCADE ON UPDATE CASCADE
1423 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1424
1425 --
1426 -- Table structure for table `sessions`
1427 --
1428
1429 DROP TABLE IF EXISTS sessions;
1430 CREATE TABLE sessions (
1431   `id` varchar(32) NOT NULL,
1432   `a_session` LONGTEXT NOT NULL,
1433   PRIMARY KEY (`id`)
1434 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1435
1436 --
1437 -- Table structure for table `sms_providers`
1438 --
1439
1440 DROP TABLE IF EXISTS sms_providers;
1441 CREATE TABLE `sms_providers` (
1442   `id` int(11) NOT NULL AUTO_INCREMENT,
1443   `name` varchar(255) NOT NULL,
1444   `domain` varchar(255) NOT NULL,
1445   PRIMARY KEY (`id`),
1446   UNIQUE KEY `name` (`name` (191))
1447 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1448
1449 --
1450 -- Table structure for table `borrowers`
1451 --
1452
1453 DROP TABLE IF EXISTS `borrowers`;
1454 CREATE TABLE `borrowers` ( -- this table includes information about your patrons/borrowers/members
1455   `borrowernumber` int(11) NOT NULL auto_increment, -- primary key, Koha assigned ID number for patrons/borrowers
1456   `cardnumber` varchar(32) default NULL, -- unique key, library assigned ID number for patrons/borrowers
1457   `surname` LONGTEXT, -- patron/borrower's last name (surname)
1458   `firstname` MEDIUMTEXT, -- patron/borrower's first name
1459   `title` LONGTEXT, -- patron/borrower's title, for example: Mr. or Mrs.
1460   `othernames` LONGTEXT, -- any other names associated with the patron/borrower
1461   `initials` MEDIUMTEXT, -- initials for your patron/borrower
1462   `streetnumber` TINYTEXT default NULL, -- the house number for your patron/borrower's primary address
1463   `streettype` TINYTEXT default NULL, -- the street type (Rd., Blvd, etc) for your patron/borrower's primary address
1464   `address` LONGTEXT, -- the first address line for your patron/borrower's primary address
1465   `address2` MEDIUMTEXT, -- the second address line for your patron/borrower's primary address
1466   `city` LONGTEXT, -- the city or town for your patron/borrower's primary address
1467   `state` MEDIUMTEXT default NULL, -- the state or province for your patron/borrower's primary address
1468   `zipcode` TINYTEXT default NULL, -- the zip or postal code for your patron/borrower's primary address
1469   `country` MEDIUMTEXT, -- the country for your patron/borrower's primary address
1470   `email` LONGTEXT, -- the primary email address for your patron/borrower's primary address
1471   `phone` MEDIUMTEXT, -- the primary phone number for your patron/borrower's primary address
1472   `mobile` TINYTEXT default NULL, -- the other phone number for your patron/borrower's primary address
1473   `fax` LONGTEXT, -- the fax number for your patron/borrower's primary address
1474   `emailpro` MEDIUMTEXT, -- the secondary email addres for your patron/borrower's primary address
1475   `phonepro` MEDIUMTEXT, -- the secondary phone number for your patron/borrower's primary address
1476   `B_streetnumber` TINYTEXT default NULL, -- the house number for your patron/borrower's alternate address
1477   `B_streettype` TINYTEXT default NULL, -- the street type (Rd., Blvd, etc) for your patron/borrower's alternate address
1478   `B_address` MEDIUMTEXT default NULL, -- the first address line for your patron/borrower's alternate address
1479   `B_address2` MEDIUMTEXT default NULL, -- the second address line for your patron/borrower's alternate address
1480   `B_city` LONGTEXT, -- the city or town for your patron/borrower's alternate address
1481   `B_state` MEDIUMTEXT default NULL, -- the state for your patron/borrower's alternate address
1482   `B_zipcode` TINYTEXT default NULL, -- the zip or postal code for your patron/borrower's alternate address
1483   `B_country` MEDIUMTEXT, -- the country for your patron/borrower's alternate address
1484   `B_email` MEDIUMTEXT, -- the patron/borrower's alternate email address
1485   `B_phone` LONGTEXT, -- the patron/borrower's alternate phone number
1486   `dateofbirth` date default NULL, -- the patron/borrower's date of birth (YYYY-MM-DD)
1487   `branchcode` varchar(10) NOT NULL default '', -- foreign key from the branches table, includes the code of the patron/borrower's home branch
1488   `categorycode` varchar(10) NOT NULL default '', -- foreign key from the categories table, includes the code of the patron category
1489   `dateenrolled` date default NULL, -- date the patron was added to Koha (YYYY-MM-DD)
1490   `dateexpiry` date default NULL, -- date the patron/borrower's card is set to expire (YYYY-MM-DD)
1491   `date_renewed` date default NULL, -- date the patron/borrower's card was last renewed
1492   `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
1493   `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
1494   `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 (YYYY-MM-DD)
1495   `debarredcomment` VARCHAR(255) DEFAULT NULL, -- comment on the stop of the patron
1496   `contactname` LONGTEXT, -- used for children and profesionals to include surname or last name of guarantor or organization name
1497   `contactfirstname` MEDIUMTEXT, -- used for children to include first name of guarantor
1498   `contacttitle` MEDIUMTEXT, -- used for children to include title (Mr., Mrs., etc) of guarantor
1499   `borrowernotes` LONGTEXT, -- a note on the patron/borrower's account that is only visible in the staff client
1500   `relationship` varchar(100) default NULL, -- used for children to include the relationship to their guarantor
1501   `sex` varchar(1) default NULL, -- patron/borrower's gender
1502   `password` varchar(60) default NULL, -- patron/borrower's Bcrypt encrypted password
1503   `flags` int(11) default NULL, -- will include a number associated with the staff member's permissions
1504   `userid` varchar(75) default NULL, -- patron/borrower's opac and/or staff client log in
1505   `opacnote` LONGTEXT, -- a note on the patron/borrower's account that is visible in the OPAC and staff client
1506   `contactnote` varchar(255) default NULL, -- a note related to the patron/borrower's alternate address
1507   `sort1` varchar(80) default NULL, -- a field that can be used for any information unique to the library
1508   `sort2` varchar(80) default NULL, -- a field that can be used for any information unique to the library
1509   `altcontactfirstname` MEDIUMTEXT  default NULL, -- first name of alternate contact for the patron/borrower
1510   `altcontactsurname` MEDIUMTEXT default NULL, -- surname or last name of the alternate contact for the patron/borrower
1511   `altcontactaddress1` MEDIUMTEXT default NULL, -- the first address line for the alternate contact for the patron/borrower
1512   `altcontactaddress2` MEDIUMTEXT default NULL, -- the second address line for the alternate contact for the patron/borrower
1513   `altcontactaddress3` MEDIUMTEXT default NULL, -- the city for the alternate contact for the patron/borrower
1514   `altcontactstate` MEDIUMTEXT default NULL, -- the state for the alternate contact for the patron/borrower
1515   `altcontactzipcode` MEDIUMTEXT default NULL, -- the zipcode for the alternate contact for the patron/borrower
1516   `altcontactcountry` MEDIUMTEXT default NULL, -- the country for the alternate contact for the patron/borrower
1517   `altcontactphone` MEDIUMTEXT default NULL, -- the phone number for the alternate contact for the patron/borrower
1518   `smsalertnumber` varchar(50) default NULL, -- the mobile phone number where the patron/borrower would like to receive notices (if SMS turned on)
1519   `sms_provider_id` int(11) DEFAULT NULL, -- the provider of the mobile phone number defined in smsalertnumber
1520   `privacy` integer(11) DEFAULT '1' NOT NULL, -- patron/borrower's privacy settings related to their reading history
1521   `privacy_guarantor_fines` tinyint(1) NOT NULL DEFAULT '0', -- controls if relatives can see this patron's fines
1522   `privacy_guarantor_checkouts` tinyint(1) NOT NULL DEFAULT '0', -- controls if relatives can see this patron's checkouts
1523   `checkprevcheckout` varchar(7) NOT NULL default 'inherit', -- produce a warning for this patron if this item has previously been checked out to this patron if 'yes', not if 'no', defer to category setting if 'inherit'.
1524   `updated_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, -- time of last change could be useful for synchronization with external systems (among others)
1525   `lastseen` datetime default NULL, -- last time a patron has been seen (connected at the OPAC or staff interface)
1526   `lang` varchar(25) NOT NULL default 'default', -- lang to use to send notices to this patron
1527   `login_attempts` int(4) NOT NULL default 0, -- number of failed login attemps
1528   `overdrive_auth_token` MEDIUMTEXT default NULL, -- persist OverDrive auth token
1529   `anonymized` TINYINT(1) NOT NULL DEFAULT 0, -- flag for data anonymization
1530   `autorenew_checkouts` TINYINT(1) NOT NULL DEFAULT 1, -- flag for allowing auto-renewal
1531   UNIQUE KEY `cardnumber` (`cardnumber`),
1532   PRIMARY KEY `borrowernumber` (`borrowernumber`),
1533   KEY `categorycode` (`categorycode`),
1534   KEY `branchcode` (`branchcode`),
1535   UNIQUE KEY `userid` (`userid`),
1536   KEY `surname_idx` (`surname` (191)),
1537   KEY `firstname_idx` (`firstname` (191)),
1538   KEY `othernames_idx` (`othernames` (191)),
1539   KEY `sms_provider_id` (`sms_provider_id`),
1540   CONSTRAINT `borrowers_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`),
1541   CONSTRAINT `borrowers_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`),
1542   CONSTRAINT `borrowers_ibfk_3` FOREIGN KEY (`sms_provider_id`) REFERENCES `sms_providers` (`id`) ON UPDATE CASCADE ON DELETE SET NULL
1543 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1544
1545 --
1546 -- Table structure for table `borrower_attributes`
1547 --
1548
1549 DROP TABLE IF EXISTS `borrower_attributes`;
1550 CREATE TABLE `borrower_attributes` ( -- values of custom patron fields known as extended patron attributes linked to patrons/borrowers
1551   `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, -- Row id field
1552   `borrowernumber` int(11) NOT NULL, -- foreign key from the borrowers table, defines which patron/borrower has this attribute
1553   `code` varchar(10) NOT NULL, -- foreign key from the borrower_attribute_types table, defines which custom field this value was entered for
1554   `attribute` varchar(255) default NULL, -- custom patron field value
1555   KEY `borrowernumber` (`borrowernumber`),
1556   KEY `code_attribute` (`code`, `attribute` (191)),
1557   CONSTRAINT `borrower_attributes_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1558     ON DELETE CASCADE ON UPDATE CASCADE,
1559   CONSTRAINT `borrower_attributes_ibfk_2` FOREIGN KEY (`code`) REFERENCES `borrower_attribute_types` (`code`)
1560     ON DELETE CASCADE ON UPDATE CASCADE
1561 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1562
1563 --
1564 -- Table structure for table `borrower_debarments`
1565 --
1566
1567 DROP TABLE IF EXISTS `borrower_debarments`;
1568 CREATE TABLE borrower_debarments ( -- tracks restrictions on the patron's record
1569   borrower_debarment_id int(11) NOT NULL AUTO_INCREMENT, -- unique key for the restriction
1570   borrowernumber int(11) NOT NULL, -- foreign key for borrowers.borrowernumber for patron who is restricted
1571   expiration date DEFAULT NULL, -- expiration date of the restriction
1572   `type` enum('SUSPENSION','OVERDUES','MANUAL','DISCHARGE') NOT NULL DEFAULT 'MANUAL', -- type of restriction
1573   `comment` MEDIUMTEXT, -- comments about the restriction
1574   manager_id int(11) DEFAULT NULL, -- foreign key for borrowers.borrowernumber for the librarian managing the restriction
1575   created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, -- date the restriction was added
1576   updated timestamp NULL DEFAULT NULL, -- date the restriction was updated
1577   PRIMARY KEY (borrower_debarment_id),
1578   KEY borrowernumber (borrowernumber),
1579   CONSTRAINT `borrower_debarments_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1580     ON DELETE CASCADE ON UPDATE CASCADE
1581 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1582
1583 --
1584 -- Table structure for table api_keys
1585 --
1586
1587 DROP TABLE IF EXISTS `api_keys`;
1588 CREATE TABLE `api_keys` (
1589     `client_id`   VARCHAR(191) NOT NULL,           -- API client ID
1590     `secret`      VARCHAR(191) NOT NULL,           -- API client secret used for API authentication
1591     `description` VARCHAR(255) NOT NULL,           -- API client description
1592     `patron_id`   INT(11) NOT NULL,                -- Foreign key to the borrowers table
1593     `active`      TINYINT(1) DEFAULT 1 NOT NULL,   -- 0 means this API key is revoked
1594     PRIMARY KEY `client_id` (`client_id`),
1595     UNIQUE KEY `secret` (`secret`),
1596     KEY `patron_id` (`patron_id`),
1597     CONSTRAINT `api_keys_fk_patron_id`
1598       FOREIGN KEY (`patron_id`)
1599       REFERENCES `borrowers` (`borrowernumber`)
1600       ON DELETE CASCADE ON UPDATE CASCADE
1601 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1602
1603 --
1604 -- Table structure for table `issues`
1605 --
1606
1607 DROP TABLE IF EXISTS `issues`;
1608 CREATE TABLE `issues` ( -- information related to check outs or issues
1609   `issue_id` int(11) NOT NULL AUTO_INCREMENT, -- primary key for issues table
1610   `borrowernumber` int(11), -- foreign key, linking this to the borrowers table for the patron this item was checked out to
1611   `itemnumber` int(11), -- foreign key, linking this to the items table for the item that was checked out
1612   `date_due` datetime default NULL, -- datetime the item is due (yyyy-mm-dd hh:mm::ss)
1613   `branchcode` varchar(10) default NULL, -- foreign key, linking to the branches table for the location the item was checked out
1614   `returndate` datetime default NULL, -- date the item was returned, will be NULL until moved to old_issues
1615   `lastreneweddate` datetime default NULL, -- date the item was last renewed
1616   `renewals` tinyint(4) NOT NULL default 0, -- lists the number of times the item was renewed
1617   `auto_renew` tinyint(1) default FALSE, -- automatic renewal
1618   `auto_renew_error` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL, -- automatic renewal error
1619   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- the date and time this record was last touched
1620   `issuedate` datetime default NULL, -- date the item was checked out or issued
1621   `onsite_checkout` int(1) NOT NULL default 0, -- in house use flag
1622   `note` LONGTEXT default NULL, -- issue note text
1623   `notedate` datetime default NULL, -- datetime of issue note (yyyy-mm-dd hh:mm::ss)
1624   `noteseen` int(1) default NULL, -- describes whether checkout note has been seen 1, not been seen 0 or doesn't exist null
1625   PRIMARY KEY (`issue_id`),
1626   UNIQUE KEY `itemnumber` (`itemnumber`),
1627   KEY `issuesborridx` (`borrowernumber`),
1628   KEY `itemnumber_idx` (`itemnumber`),
1629   KEY `branchcode_idx` (`branchcode`),
1630   KEY `bordate` (`borrowernumber`,`timestamp`),
1631   CONSTRAINT `issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE RESTRICT ON UPDATE CASCADE,
1632   CONSTRAINT `issues_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE RESTRICT ON UPDATE CASCADE
1633 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1634
1635 --
1636 -- Table structure for table `old_issues`
1637 --
1638
1639 DROP TABLE IF EXISTS `old_issues`;
1640 CREATE TABLE `old_issues` ( -- lists items that were checked out and have been returned
1641   `issue_id` int(11) NOT NULL, -- primary key for issues table
1642   `borrowernumber` int(11) default NULL, -- foreign key, linking this to the borrowers table for the patron this item was checked out to
1643   `itemnumber` int(11) default NULL, -- foreign key, linking this to the items table for the item that was checked out
1644   `date_due` datetime default NULL, -- date the item is due (yyyy-mm-dd)
1645   `branchcode` varchar(10) default NULL, -- foreign key, linking to the branches table for the location the item was checked out
1646   `returndate` datetime default NULL, -- date the item was returned
1647   `lastreneweddate` datetime default NULL, -- date the item was last renewed
1648   `renewals` tinyint(4) NOT NULL default 0, -- lists the number of times the item was renewed
1649   `auto_renew` tinyint(1) default FALSE, -- automatic renewal
1650   `auto_renew_error` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL, -- automatic renewal error
1651   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- the date and time this record was last touched
1652   `issuedate` datetime default NULL, -- date the item was checked out or issued
1653   `onsite_checkout` int(1) NOT NULL default 0, -- in house use flag
1654   `note` LONGTEXT default NULL, -- issue note text
1655   `notedate` datetime default NULL, -- datetime of issue note (yyyy-mm-dd hh:mm::ss)
1656   `noteseen` int(1) default NULL, -- describes whether checkout note has been seen 1, not been seen 0 or doesn't exist null
1657   PRIMARY KEY (`issue_id`),
1658   KEY `old_issuesborridx` (`borrowernumber`),
1659   KEY `old_issuesitemidx` (`itemnumber`),
1660   KEY `branchcode_idx` (`branchcode`),
1661   KEY `old_bordate` (`borrowernumber`,`timestamp`),
1662   CONSTRAINT `old_issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1663     ON DELETE SET NULL ON UPDATE SET NULL,
1664   CONSTRAINT `old_issues_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`)
1665     ON DELETE SET NULL ON UPDATE SET NULL
1666 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1667
1668 --
1669 -- Table structure for table `items_last_borrower`
1670 --
1671
1672 CREATE TABLE IF NOT EXISTS `items_last_borrower` (
1673   `id` int(11) NOT NULL AUTO_INCREMENT,
1674   `itemnumber` int(11) NOT NULL,
1675   `borrowernumber` int(11) NOT NULL,
1676   `created_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
1677   PRIMARY KEY (`id`),
1678   UNIQUE KEY `itemnumber` (`itemnumber`),
1679   KEY `borrowernumber` (`borrowernumber`),
1680   CONSTRAINT `items_last_borrower_ibfk_2` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1681   CONSTRAINT `items_last_borrower_ibfk_1` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE
1682 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1683
1684 --
1685 -- Table structure for table `creator_batches`
1686 --
1687
1688 DROP TABLE IF EXISTS `creator_batches`;
1689 SET @saved_cs_client     = @@character_set_client;
1690 SET character_set_client = utf8;
1691 CREATE TABLE `creator_batches` (
1692   `label_id` int(11) NOT NULL AUTO_INCREMENT,
1693   `batch_id` int(10) NOT NULL DEFAULT '1',
1694   `description` mediumtext DEFAULT NULL,
1695   `item_number` int(11) DEFAULT NULL,
1696   `borrower_number` int(11) DEFAULT NULL,
1697   `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
1698   `branch_code` varchar(10) NOT NULL DEFAULT 'NB',
1699   `creator` char(15) NOT NULL DEFAULT 'Labels',
1700   PRIMARY KEY (`label_id`),
1701   KEY `branch_fk_constraint` (`branch_code`),
1702   KEY `item_fk_constraint` (`item_number`),
1703   KEY `borrower_fk_constraint` (`borrower_number`),
1704   CONSTRAINT `creator_batches_ibfk_1` FOREIGN KEY (`borrower_number`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1705   CONSTRAINT `creator_batches_ibfk_2` FOREIGN KEY (`branch_code`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE,
1706   CONSTRAINT `creator_batches_ibfk_3` FOREIGN KEY (`item_number`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE
1707 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1708
1709 --
1710 -- Table structure for table `opac_news`
1711 --
1712
1713 DROP TABLE IF EXISTS `opac_news`;
1714 CREATE TABLE `opac_news` ( -- data from the news tool
1715   `idnew` int(10) unsigned NOT NULL auto_increment, -- unique identifier for the news article
1716   `branchcode` varchar(10) default NULL, -- branch code users to create branch specific news, NULL is every branch.
1717   `title` varchar(250) NOT NULL default '', -- title of the news article
1718   `content` MEDIUMTEXT NOT NULL, -- the body of your news article
1719   `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)
1720   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP, -- pulibcation date and time
1721   `expirationdate` date default NULL, -- date the article is set to expire or no longer be visible
1722   `number` int(11) default NULL, -- the order in which this article appears in that specific location
1723   `borrowernumber` int(11) default NULL, -- The user who created the news article
1724   PRIMARY KEY  (`idnew`),
1725   CONSTRAINT `borrowernumber_fk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
1726   CONSTRAINT opac_news_branchcode_ibfk FOREIGN KEY (branchcode) REFERENCES branches (branchcode)
1727     ON DELETE CASCADE ON UPDATE CASCADE
1728 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1729
1730 --
1731 -- Table structure for table `patronimage`
1732 --
1733
1734 DROP TABLE IF EXISTS `patronimage`;
1735 CREATE TABLE `patronimage` ( -- information related to patron images
1736   `borrowernumber` int(11) NOT NULL, -- the borrowernumber of the patron this image is attached to (borrowers.borrowernumber)
1737   `mimetype` varchar(15) NOT NULL, -- the format of the image (png, jpg, etc)
1738   `imagefile` mediumblob NOT NULL, -- the image
1739   PRIMARY KEY  (`borrowernumber`),
1740   CONSTRAINT `patronimage_fk1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
1741 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1742
1743 --
1744 -- Table structure for table `reserves`
1745 --
1746
1747 DROP TABLE IF EXISTS `reserves`;
1748 CREATE TABLE `reserves` ( -- information related to holds/reserves in Koha
1749   `reserve_id` int(11) NOT NULL auto_increment, -- primary key
1750   `borrowernumber` int(11) NOT NULL default 0, -- foreign key from the borrowers table defining which patron this hold is for
1751   `reservedate` date default NULL, -- the date the hold was placed
1752   `biblionumber` int(11) NOT NULL default 0, -- foreign key from the biblio table defining which bib record this hold is on
1753   `branchcode` varchar(10) default NULL, -- foreign key from the branches table defining which branch the patron wishes to pick this hold up at
1754   `notificationdate` date default NULL, -- currently unused
1755   `reminderdate` date default NULL, -- currently unused
1756   `cancellationdate` date default NULL, -- the date this hold was cancelled
1757   `reservenotes` LONGTEXT, -- notes related to this hold
1758   `priority` smallint(6) NOT NULL DEFAULT 1, -- where in the queue the patron sits
1759   `found` varchar(1) default NULL, -- a one letter code defining what the status is of the hold is after it has been confirmed
1760   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- the date and time this hold was last updated
1761   `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
1762   `waitingdate` date default NULL, -- the date the item was marked as waiting for the patron at the library
1763   `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)
1764   `lowestPriority` tinyint(1) NOT NULL DEFAULT 0,
1765   `suspend` tinyint(1) NOT NULL DEFAULT 0,
1766   `suspend_until` DATETIME NULL DEFAULT NULL,
1767   `itemtype` VARCHAR(10) NULL DEFAULT NULL, -- If record level hold, the optional itemtype of the item the patron is requesting
1768   `item_level_hold` tinyint(1) NOT NULL DEFAULT 0, -- Is the hpld placed at item level
1769   PRIMARY KEY (`reserve_id`),
1770   KEY priorityfoundidx (priority,found),
1771   KEY `borrowernumber` (`borrowernumber`),
1772   KEY `biblionumber` (`biblionumber`),
1773   KEY `itemnumber` (`itemnumber`),
1774   KEY `branchcode` (`branchcode`),
1775   KEY `itemtype` (`itemtype`),
1776   CONSTRAINT `reserves_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1777   CONSTRAINT `reserves_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1778   CONSTRAINT `reserves_ibfk_3` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1779   CONSTRAINT `reserves_ibfk_4` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE,
1780   CONSTRAINT `reserves_ibfk_5` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE CASCADE ON UPDATE CASCADE
1781 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1782
1783 --
1784 -- Table structure for table `old_reserves`
1785 --
1786
1787 DROP TABLE IF EXISTS `old_reserves`;
1788 CREATE TABLE `old_reserves` ( -- this table holds all holds/reserves that have been completed (either filled or cancelled)
1789   `reserve_id` int(11) NOT NULL, -- primary key
1790   `borrowernumber` int(11) default NULL, -- foreign key from the borrowers table defining which patron this hold is for
1791   `reservedate` date default NULL, -- the date the hold was places
1792   `biblionumber` int(11) default NULL, -- foreign key from the biblio table defining which bib record this hold is on
1793   `branchcode` varchar(10) default NULL, -- foreign key from the branches table defining which branch the patron wishes to pick this hold up at
1794   `notificationdate` date default NULL, -- currently unused
1795   `reminderdate` date default NULL, -- currently unused
1796   `cancellationdate` date default NULL, -- the date this hold was cancelled
1797   `reservenotes` LONGTEXT, -- notes related to this hold
1798   `priority` smallint(6) NOT NULL DEFAULT 1, -- where in the queue the patron sits
1799   `found` varchar(1) default NULL, -- a one letter code defining what the status is of the hold is after it has been confirmed
1800   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- the date and time this hold was last updated
1801   `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
1802   `waitingdate` date default NULL, -- the date the item was marked as waiting for the patron at the library
1803   `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)
1804   `lowestPriority` tinyint(1) NOT NULL DEFAULT 0, -- has this hold been pinned to the lowest priority in the holds queue (1 for yes, 0 for no)
1805   `suspend` tinyint(1) NOT NULL DEFAULT 0, -- in this hold suspended (1 for yes, 0 for no)
1806   `suspend_until` DATETIME NULL DEFAULT NULL, -- the date this hold is suspended until (NULL for infinitely)
1807   `itemtype` VARCHAR(10) NULL DEFAULT NULL, -- If record level hold, the optional itemtype of the item the patron is requesting
1808   `item_level_hold` tinyint(1) NOT NULL DEFAULT 0, -- Is the hpld placed at item level
1809   PRIMARY KEY (`reserve_id`),
1810   KEY `old_reserves_borrowernumber` (`borrowernumber`),
1811   KEY `old_reserves_biblionumber` (`biblionumber`),
1812   KEY `old_reserves_itemnumber` (`itemnumber`),
1813   KEY `old_reserves_branchcode` (`branchcode`),
1814   KEY `old_reserves_itemtype` (`itemtype`),
1815   CONSTRAINT `old_reserves_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1816     ON DELETE SET NULL ON UPDATE SET NULL,
1817   CONSTRAINT `old_reserves_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`)
1818     ON DELETE SET NULL ON UPDATE SET NULL,
1819   CONSTRAINT `old_reserves_ibfk_3` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`)
1820     ON DELETE SET NULL ON UPDATE SET NULL,
1821   CONSTRAINT `old_reserves_ibfk_4` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`)
1822     ON DELETE SET NULL ON UPDATE SET NULL
1823 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1824
1825 --
1826 -- Table structure for table `reviews`
1827 --
1828
1829 DROP TABLE IF EXISTS `reviews`;
1830 CREATE TABLE `reviews` ( -- patron opac comments
1831   `reviewid` int(11) NOT NULL auto_increment, -- unique identifier for this comment
1832   `borrowernumber` int(11) default NULL, -- foreign key from the borrowers table defining which patron left this comment
1833   `biblionumber` int(11) default NULL, -- foreign key from the biblio table defining which bibliographic record this comment is for
1834   `review` MEDIUMTEXT, -- the body of the comment
1835   `approved` tinyint(4) default 0, -- whether this comment has been approved by a librarian (1 for yes, 0 for no)
1836   `datereviewed` datetime default NULL, -- the date the comment was left
1837   PRIMARY KEY  (`reviewid`),
1838   CONSTRAINT `reviews_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
1839   CONSTRAINT `reviews_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
1840 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1841
1842 --
1843 -- Table structure for table `special_holidays`
1844 --
1845
1846 DROP TABLE IF EXISTS `special_holidays`;
1847 CREATE TABLE `special_holidays` ( -- non repeatable holidays/library closings
1848   `id` int(11) NOT NULL auto_increment, -- unique identifier assigned by Koha
1849   `branchcode` varchar(10) NOT NULL, -- foreign key from the branches table, defines which branch this closing is for
1850   `day` smallint(6) NOT NULL default 0, -- day of the month this closing is on
1851   `month` smallint(6) NOT NULL default 0, -- month this closing is in
1852   `year` smallint(6) NOT NULL default 0, -- year this closing is in
1853   `isexception` smallint(1) NOT NULL default 1, -- is this a holiday exception to a repeatable holiday (1 for yes, 0 for no)
1854   `title` varchar(50) NOT NULL default '', -- title for this closing
1855   `description` MEDIUMTEXT NOT NULL, -- description of this closing
1856   PRIMARY KEY  (`id`),
1857   CONSTRAINT `special_holidays_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
1858 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1859
1860 --
1861 -- Table structure for table `statistics`
1862 --
1863
1864 DROP TABLE IF EXISTS `statistics`;
1865 CREATE TABLE `statistics` ( -- information related to transactions (circulation and fines) in Koha
1866   `datetime` datetime default NULL, -- date and time of the transaction
1867   `branch` varchar(10) default NULL, -- foreign key, branch where the transaction occurred
1868   `value` double(16,4) default NULL, -- monetary value associated with the transaction
1869   `type` varchar(16) default NULL, -- transaction type (localuse, issue, return, renew, writeoff, payment)
1870   `other` LONGTEXT, -- used by SIP
1871   `itemnumber` int(11) default NULL, -- foreign key from the items table, links transaction to a specific item
1872   `itemtype` varchar(10) default NULL, -- foreign key from the itemtypes table, links transaction to a specific item type
1873   `location` varchar(80) default NULL, -- authorized value for the shelving location for this item (MARC21 952$c)
1874   `borrowernumber` int(11) default NULL, -- foreign key from the borrowers table, links transaction to a specific borrower
1875   `ccode` varchar(80) default NULL, -- foreign key from the items table, links transaction to a specific collection code
1876   KEY `timeidx` (`datetime`),
1877   KEY `branch_idx` (`branch`),
1878   KEY `type_idx` (`type`),
1879   KEY `itemnumber_idx` (`itemnumber`),
1880   KEY `itemtype_idx` (`itemtype`),
1881   KEY `borrowernumber_idx` (`borrowernumber`),
1882   KEY `ccode_idx` (`ccode`)
1883 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1884
1885 --
1886 -- Table structure for table pseudonymized_transactions
1887 --
1888
1889 DROP TABLE IF EXISTS pseudonymized_transactions;
1890 CREATE TABLE `pseudonymized_transactions` (
1891   `id` INT(11) NOT NULL AUTO_INCREMENT,
1892   `hashed_borrowernumber` VARCHAR(60) NOT NULL,
1893   `has_cardnumber` TINYINT(1) NOT NULL DEFAULT 0,
1894   `title` LONGTEXT,
1895   `city` LONGTEXT,
1896   `state` MEDIUMTEXT default NULL,
1897   `zipcode` varchar(25) default NULL,
1898   `country` MEDIUMTEXT,
1899   `branchcode` varchar(10) NOT NULL default '',
1900   `categorycode` varchar(10) NOT NULL default '',
1901   `dateenrolled` date default NULL,
1902   `sex` varchar(1) default NULL,
1903   `sort1` varchar(80) default NULL,
1904   `sort2` varchar(80) default NULL,
1905   `datetime` datetime default NULL,
1906   `transaction_branchcode` varchar(10) default NULL,
1907   `transaction_type` varchar(16) default NULL,
1908   `itemnumber` int(11) default NULL,
1909   `itemtype` varchar(10) default NULL,
1910   `holdingbranch` varchar(10) default null,
1911   `homebranch` varchar(10) default null,
1912   `location` varchar(80) default NULL,
1913   `itemcallnumber` varchar(255) default NULL,
1914   `ccode` varchar(80) default NULL,
1915   PRIMARY KEY (`id`),
1916   CONSTRAINT `pseudonymized_transactions_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`),
1917   CONSTRAINT `pseudonymized_transactions_borrowers_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`),
1918   CONSTRAINT `pseudonymized_transactions_borrowers_ibfk_3` FOREIGN KEY (`transaction_branchcode`) REFERENCES `branches` (`branchcode`)
1919 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1920
1921 --
1922 -- Table structure for table borrower_attributes
1923 --
1924
1925 DROP TABLE IF EXISTS pseudonymized_borrower_attributes;
1926 CREATE TABLE pseudonymized_borrower_attributes ( -- association table between pseudonymized_transactions and borrower_attributes
1927   `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, -- Row id field
1928   `transaction_id` int(11) NOT NULL,
1929   `code` varchar(10) NOT NULL, -- foreign key from the borrower_attribute_types table, defines which custom field this value was entered for
1930   `attribute` varchar(255) default NULL, -- custom patron field value
1931   CONSTRAINT `pseudonymized_borrower_attributes_ibfk_1` FOREIGN KEY (`transaction_id`) REFERENCES `pseudonymized_transactions` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
1932   CONSTRAINT `anonymized_borrower_attributes_ibfk_2` FOREIGN KEY (`code`) REFERENCES `borrower_attribute_types` (`code`) ON DELETE CASCADE ON UPDATE CASCADE
1933 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1934
1935 --
1936 -- Table structure for table subscription_frequencies
1937 --
1938
1939 DROP TABLE IF EXISTS subscription_frequencies;
1940 CREATE TABLE subscription_frequencies (
1941     id INTEGER NOT NULL AUTO_INCREMENT,
1942     description MEDIUMTEXT NOT NULL,
1943     displayorder INT DEFAULT NULL,
1944     unit ENUM('day','week','month','year') DEFAULT NULL,
1945     unitsperissue INTEGER NOT NULL DEFAULT '1',
1946     issuesperunit INTEGER NOT NULL DEFAULT '1',
1947     PRIMARY KEY (id)
1948 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1949
1950 --
1951 -- Table structure for table subscription_numberpatterns
1952 --
1953
1954 DROP TABLE IF EXISTS subscription_numberpatterns;
1955 CREATE TABLE subscription_numberpatterns (
1956     id INTEGER NOT NULL AUTO_INCREMENT,
1957     label VARCHAR(255) NOT NULL,
1958     displayorder INTEGER DEFAULT NULL,
1959     description MEDIUMTEXT NOT NULL,
1960     numberingmethod VARCHAR(255) NOT NULL,
1961     label1 VARCHAR(255) DEFAULT NULL,
1962     add1 INTEGER DEFAULT NULL,
1963     every1 INTEGER DEFAULT NULL,
1964     whenmorethan1 INTEGER DEFAULT NULL,
1965     setto1 INTEGER DEFAULT NULL,
1966     numbering1 VARCHAR(255) DEFAULT NULL,
1967     label2 VARCHAR(255) DEFAULT NULL,
1968     add2 INTEGER DEFAULT NULL,
1969     every2 INTEGER DEFAULT NULL,
1970     whenmorethan2 INTEGER DEFAULT NULL,
1971     setto2 INTEGER DEFAULT NULL,
1972     numbering2 VARCHAR(255) DEFAULT NULL,
1973     label3 VARCHAR(255) DEFAULT NULL,
1974     add3 INTEGER DEFAULT NULL,
1975     every3 INTEGER DEFAULT NULL,
1976     whenmorethan3 INTEGER DEFAULT NULL,
1977     setto3 INTEGER DEFAULT NULL,
1978     numbering3 VARCHAR(255) DEFAULT NULL,
1979     PRIMARY KEY (id)
1980 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1981
1982 --
1983 -- Table structure for table `subscription`
1984 --
1985
1986 DROP TABLE IF EXISTS `subscription`;
1987 CREATE TABLE `subscription` ( -- information related to the subscription
1988   `biblionumber` int(11) NOT NULL, -- foreign key for biblio.biblionumber that this subscription is attached to
1989   `subscriptionid` int(11) NOT NULL auto_increment, -- unique key for this subscription
1990   `librarian` varchar(100) default '', -- the librarian's username from borrowers.userid
1991   `startdate` date default NULL, -- start date for this subscription
1992   `aqbooksellerid` int(11) default 0, -- foreign key for aqbooksellers.id to link to the vendor
1993   `cost` int(11) default 0,
1994   `aqbudgetid` int(11) default 0,
1995   `weeklength` int(11) default 0, -- subscription length in weeks (will not be filled in if monthlength or numberlength is set)
1996   `monthlength` int(11) default 0, -- subscription length in weeks (will not be filled in if weeklength or numberlength is set)
1997   `numberlength` int(11) default 0, -- subscription length in weeks (will not be filled in if monthlength or weeklength is set)
1998   `periodicity` integer default null, -- frequency type links to subscription_frequencies.id
1999   countissuesperunit INTEGER NOT NULL DEFAULT 1,
2000   `notes` LONGTEXT, -- notes
2001   `status` varchar(100) NOT NULL default '',  -- status of this subscription
2002   `lastvalue1` int(11) default NULL,
2003   `innerloop1` int(11) default 0,
2004   `lastvalue2` int(11) default NULL,
2005   `innerloop2` int(11) default 0,
2006   `lastvalue3` int(11) default NULL,
2007   `innerloop3` int(11) default 0,
2008   `firstacquidate` date default NULL, -- first issue received date
2009   `manualhistory` tinyint(1) NOT NULL default 0, -- yes or no to managing the history manually
2010   `irregularity` MEDIUMTEXT, -- any irregularities in the subscription
2011   skip_serialseq tinyint(1) NOT NULL DEFAULT 0,
2012   `letter` varchar(20) default NULL,
2013   `numberpattern` integer default null, -- the numbering pattern used links to subscription_numberpatterns.id
2014   locale VARCHAR(80) DEFAULT NULL, -- for foreign language subscriptions to display months, seasons, etc correctly
2015   `distributedto` MEDIUMTEXT,
2016   `internalnotes` LONGTEXT,
2017   `callnumber` MEDIUMTEXT, -- default call number
2018   `location` varchar(80) NULL default '', -- default shelving location (items.location)
2019   `branchcode` varchar(10) NOT NULL default '', -- default branches (items.homebranch)
2020   `lastbranch` varchar(10),
2021   `serialsadditems` tinyint(1) NOT NULL default '0', -- does receiving this serial create an item record
2022   `staffdisplaycount` VARCHAR(10) NULL, -- how many issues to show to the staff
2023   `opacdisplaycount` VARCHAR(10) NULL, -- how many issues to show to the public
2024   `graceperiod` int(11) NOT NULL default '0', -- grace period in days
2025   `enddate` date default NULL, -- subscription end date
2026   `closed` TINYINT(1) NOT NULL DEFAULT 0, -- yes / no if the subscription is closed
2027   `reneweddate` date default NULL, -- date of last renewal for the subscription
2028   `itemtype` VARCHAR( 10 ) NULL,
2029   `previousitemtype` VARCHAR( 10 ) NULL,
2030   `mana_id` int(11) NULL DEFAULT NULL,
2031   PRIMARY KEY  (`subscriptionid`),
2032   CONSTRAINT subscription_ibfk_1 FOREIGN KEY (periodicity) REFERENCES subscription_frequencies (id) ON DELETE SET NULL ON UPDATE CASCADE,
2033   CONSTRAINT subscription_ibfk_2 FOREIGN KEY (numberpattern) REFERENCES subscription_numberpatterns (id) ON DELETE SET NULL ON UPDATE CASCADE,
2034   CONSTRAINT subscription_ibfk_3 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE CASCADE
2035 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2036
2037 --
2038 -- Table structure for table `serial`
2039 --
2040
2041 DROP TABLE IF EXISTS `serial`;
2042 CREATE TABLE `serial` ( -- issues related to subscriptions
2043   `serialid` int(11) NOT NULL auto_increment, -- unique key for the issue
2044   `biblionumber` int(11) NOT NULL, -- foreign key for the biblio.biblionumber that this issue is attached to
2045   `subscriptionid` int(11) NOT NULL, -- foreign key to the subscription.subscriptionid that this issue is part of
2046   `serialseq` varchar(100) NOT NULL default '', -- issue information (volume, number, etc)
2047   `serialseq_x` varchar( 100 ) NULL DEFAULT NULL, -- first part of issue information
2048   `serialseq_y` varchar( 100 ) NULL DEFAULT NULL, -- second part of issue information
2049   `serialseq_z` varchar( 100 ) NULL DEFAULT NULL, -- third part of issue information
2050   `status` tinyint(4) NOT NULL default 0, -- status code for this issue (see manual for full descriptions)
2051   `planneddate` date default NULL, -- date expected
2052   `notes` MEDIUMTEXT, -- notes
2053   `publisheddate` date default NULL, -- date published
2054   publisheddatetext varchar(100) default NULL, -- date published (descriptive)
2055   `claimdate` date default NULL, -- date claimed
2056   claims_count int(11) default 0, -- number of claims made related to this issue
2057   `routingnotes` MEDIUMTEXT, -- notes from the routing list
2058   PRIMARY KEY (`serialid`),
2059   CONSTRAINT serial_ibfk_1 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE CASCADE,
2060   CONSTRAINT serial_ibfk_2 FOREIGN KEY (subscriptionid) REFERENCES subscription (subscriptionid) ON DELETE CASCADE ON UPDATE CASCADE
2061 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2062
2063 --
2064 -- Table structure for table `subscriptionhistory`
2065 --
2066
2067 DROP TABLE IF EXISTS `subscriptionhistory`;
2068 CREATE TABLE `subscriptionhistory` (
2069   `biblionumber` int(11) NOT NULL,
2070   `subscriptionid` int(11) NOT NULL,
2071   `histstartdate` date default NULL,
2072   `histenddate` date default NULL,
2073   `missinglist` LONGTEXT NOT NULL,
2074   `recievedlist` LONGTEXT NOT NULL,
2075   `opacnote` LONGTEXT NULL,
2076   `librariannote` LONGTEXT NULL,
2077   PRIMARY KEY  (`subscriptionid`),
2078   CONSTRAINT subscription_history_ibfk_1 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE CASCADE,
2079   CONSTRAINT subscription_history_ibfk_2 FOREIGN KEY (subscriptionid) REFERENCES subscription (subscriptionid) ON DELETE CASCADE ON UPDATE CASCADE
2080 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2081
2082 --
2083 -- Table structure for table `subscriptionroutinglist`
2084 --
2085
2086 DROP TABLE IF EXISTS `subscriptionroutinglist`;
2087 CREATE TABLE `subscriptionroutinglist` ( -- information related to the routing lists attached to subscriptions
2088   `routingid` int(11) NOT NULL auto_increment, -- unique identifier assigned by Koha
2089   `borrowernumber` int(11) NOT NULL, -- foreign key from the borrowers table, defines with patron is on the routing list
2090   `ranking` int(11) default NULL, -- where the patron stands in line to receive the serial
2091   `subscriptionid` int(11) NOT NULL, -- foreign key from the subscription table, defines which subscription this routing list is for
2092   PRIMARY KEY  (`routingid`),
2093   UNIQUE (`subscriptionid`, `borrowernumber`),
2094   CONSTRAINT `subscriptionroutinglist_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
2095     ON DELETE CASCADE ON UPDATE CASCADE,
2096   CONSTRAINT `subscriptionroutinglist_ibfk_2` FOREIGN KEY (`subscriptionid`) REFERENCES `subscription` (`subscriptionid`)
2097     ON DELETE CASCADE ON UPDATE CASCADE
2098 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2099
2100 --
2101 -- Table structure for table `systempreferences`
2102 --
2103
2104 DROP TABLE IF EXISTS `systempreferences`;
2105 CREATE TABLE `systempreferences` ( -- global system preferences
2106   `variable` varchar(50) NOT NULL default '', -- system preference name
2107   `value` MEDIUMTEXT, -- system preference values
2108   `options` LONGTEXT, -- options for multiple choice system preferences
2109   `explanation` MEDIUMTEXT, -- descriptive text for the system preference
2110   `type` varchar(20) default NULL, -- type of question this preference asks (multiple choice, plain text, yes or no, etc)
2111   PRIMARY KEY  (`variable`)
2112 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2113
2114 --
2115 -- Table structure for table `tags`
2116 --
2117
2118 DROP TABLE IF EXISTS `tags`;
2119 CREATE TABLE `tags` (
2120   `entry` varchar(255) NOT NULL default '',
2121   `weight` bigint(20) NOT NULL default 0,
2122   PRIMARY KEY  (`entry` (191))
2123 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2124
2125 --
2126 -- Table structure for table `tags_all`
2127 --
2128
2129 DROP TABLE IF EXISTS `tags_all`;
2130 CREATE TABLE `tags_all` ( -- all of the tags
2131   `tag_id`         int(11) NOT NULL auto_increment, -- unique id and primary key
2132   `borrowernumber` int(11) DEFAULT NULL, -- the patron who added the tag (borrowers.borrowernumber)
2133   `biblionumber`   int(11) NOT NULL, -- the bib record this tag was left on (biblio.biblionumber)
2134   `term`      varchar(191) NOT NULL COLLATE utf8mb4_bin, -- the tag
2135   `language`       int(4) default NULL, -- the language the tag was left in
2136   `date_created` datetime  NOT NULL, -- the date the tag was added
2137   PRIMARY KEY  (`tag_id`),
2138   KEY `tags_borrowers_fk_1` (`borrowernumber`),
2139   KEY `tags_biblionumber_fk_1` (`biblionumber`),
2140   CONSTRAINT `tags_borrowers_fk_1` FOREIGN KEY (`borrowernumber`)
2141         REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
2142   CONSTRAINT `tags_biblionumber_fk_1` FOREIGN KEY (`biblionumber`)
2143         REFERENCES `biblio`     (`biblionumber`)  ON DELETE CASCADE ON UPDATE CASCADE
2144 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2145
2146 --
2147 -- Table structure for table `tags_approval`
2148 --
2149
2150 DROP TABLE IF EXISTS `tags_approval`;
2151 CREATE TABLE `tags_approval` ( -- approved tags
2152   `term`   varchar(191) NOT NULL COLLATE utf8mb4_bin, -- the tag
2153   `approved`     int(1) NOT NULL default '0', -- whether the tag is approved or not (1=yes, 0=pending, -1=rejected)
2154   `date_approved` datetime       default NULL, -- the date this tag was approved
2155   `approved_by` int(11)          default NULL, -- the librarian who approved the tag (borrowers.borrowernumber)
2156   `weight_total` int(9) NOT NULL default '1', -- the total number of times this tag was used
2157   PRIMARY KEY  (`term`),
2158   KEY `tags_approval_borrowers_fk_1` (`approved_by`),
2159   CONSTRAINT `tags_approval_borrowers_fk_1` FOREIGN KEY (`approved_by`)
2160         REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE
2161 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2162
2163 --
2164 -- Table structure for table `tags_index`
2165 --
2166
2167 DROP TABLE IF EXISTS `tags_index`;
2168 CREATE TABLE `tags_index` ( -- a weighted list of all tags and where they are used
2169   `term`    varchar(191) NOT NULL COLLATE utf8mb4_bin, -- the tag
2170   `biblionumber` int(11) NOT NULL, -- the bib record this tag was used on (biblio.biblionumber)
2171   `weight`        int(9) NOT NULL default '1', -- the number of times this term was used on this bib record
2172   PRIMARY KEY  (`term`,`biblionumber`),
2173   KEY `tags_index_biblionumber_fk_1` (`biblionumber`),
2174   CONSTRAINT `tags_index_term_fk_1` FOREIGN KEY (`term`)
2175         REFERENCES `tags_approval` (`term`)  ON DELETE CASCADE ON UPDATE CASCADE,
2176   CONSTRAINT `tags_index_biblionumber_fk_1` FOREIGN KEY (`biblionumber`)
2177         REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
2178 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2179
2180 --
2181 -- Table structure for table `userflags`
2182 --
2183
2184 DROP TABLE IF EXISTS `userflags`;
2185 CREATE TABLE `userflags` (
2186   `bit` int(11) NOT NULL default 0,
2187   `flag` varchar(30) default NULL,
2188   `flagdesc` varchar(255) default NULL,
2189   `defaulton` int(11) default NULL,
2190   PRIMARY KEY  (`bit`)
2191 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2192
2193 --
2194 -- Table structure for table `virtualshelves`
2195 --
2196
2197 DROP TABLE IF EXISTS `virtualshelves`;
2198 CREATE TABLE `virtualshelves` ( -- information about lists (or virtual shelves)
2199   `shelfnumber` int(11) NOT NULL auto_increment, -- unique identifier assigned by Koha
2200   `shelfname` varchar(255) default NULL, -- name of the list
2201   `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)
2202   `category` varchar(1) default NULL, -- type of list (private [1], public [2])
2203   `sortfield` varchar(16) default 'title', -- the field this list is sorted on
2204   `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- date and time the list was last modified
2205   `created_on` datetime NOT NULL, -- creation time
2206   `allow_change_from_owner` tinyint(1) default 1, -- can owner change contents?
2207   `allow_change_from_others` tinyint(1) default 0, -- can others change contents?
2208   PRIMARY KEY  (`shelfnumber`),
2209   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 Members.pm
2210 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2211
2212 --
2213 -- Table structure for table `virtualshelfcontents`
2214 --
2215
2216 DROP TABLE IF EXISTS `virtualshelfcontents`;
2217 CREATE TABLE `virtualshelfcontents` ( -- information about the titles in a list (or virtual shelf)
2218   `shelfnumber` int(11) NOT NULL default 0, -- foreign key linking to the virtualshelves table, defines the list that this record has been added to
2219   `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
2220   `flags` int(11) default NULL,
2221   `dateadded` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, -- date and time this bib record was added to the list
2222   `borrowernumber` int, -- borrower number that created this list entry (only the first one is saved: no need for use in/as key)
2223   KEY `shelfnumber` (`shelfnumber`),
2224   KEY `biblionumber` (`biblionumber`),
2225   CONSTRAINT `virtualshelfcontents_ibfk_1` FOREIGN KEY (`shelfnumber`) REFERENCES `virtualshelves` (`shelfnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2226   CONSTRAINT `shelfcontents_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2227   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 Members.pm
2228 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2229
2230 --
2231 -- Table structure for table `virtualshelfshares`
2232 --
2233
2234 DROP TABLE IF EXISTS `virtualshelfshares`;
2235 CREATE TABLE `virtualshelfshares` ( -- shared private lists
2236   `id` int AUTO_INCREMENT PRIMARY KEY,  -- unique key
2237   `shelfnumber` int NOT NULL,  -- foreign key for virtualshelves
2238   `borrowernumber` int,  -- borrower that accepted access to this list
2239   `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
2240   `sharedate` datetime,  -- date of invitation or acceptance of invitation
2241   CONSTRAINT `virtualshelfshares_ibfk_1` FOREIGN KEY (`shelfnumber`) REFERENCES `virtualshelves` (`shelfnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2242   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 Members.pm
2243 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2244
2245 --
2246 -- Table structure for table `z3950servers`
2247 --
2248
2249 DROP TABLE IF EXISTS `z3950servers`;
2250 CREATE TABLE `z3950servers` ( -- connection information for the Z39.50 targets used in cataloging
2251   `id` int(11) NOT NULL auto_increment, -- unique identifier assigned by Koha
2252   `host` varchar(255) default NULL, -- target's host name
2253   `port` int(11) default NULL, -- port number used to connect to target
2254   `db` varchar(255) default NULL, -- target's database name
2255   `userid` varchar(255) default NULL, -- username needed to log in to target
2256   `password` varchar(255) default NULL, -- password needed to log in to target
2257   `servername` LONGTEXT NOT NULL, -- name given to the target by the library
2258   `checked` smallint(6) default NULL, -- whether this target is checked by default  (1 for yes, 0 for no)
2259   `rank` int(11) default NULL, -- where this target appears in the list of targets
2260   `syntax` varchar(80) default NULL, -- marc format provided by this target
2261   `timeout` int(11) NOT NULL DEFAULT '0', -- number of seconds before Koha stops trying to access this server
2262   `servertype` enum('zed','sru') NOT NULL default 'zed', -- zed means z39.50 server
2263   `encoding` MEDIUMTEXT default NULL, -- characters encoding provided by this target
2264   `recordtype` enum('authority','biblio') NOT NULL default 'biblio', -- server contains bibliographic or authority records
2265   `sru_options` varchar(255) default NULL, -- options like sru=get, sru_version=1.1; will be passed to the server via ZOOM
2266   `sru_fields` LONGTEXT default NULL, -- contains the mapping between the Z3950 search fields and the specific SRU server indexes
2267   `add_xslt` LONGTEXT default NULL, -- zero or more paths to XSLT files to be processed on the search results
2268   `attributes` VARCHAR(255) default NULL, -- additional attributes passed to PQF queries
2269   PRIMARY KEY  (`id`)
2270 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2271
2272 --
2273 -- Table structure for table `zebraqueue`
2274 --
2275
2276 DROP TABLE IF EXISTS `zebraqueue`;
2277 CREATE TABLE `zebraqueue` (
2278   `id` int(11) NOT NULL auto_increment,
2279   `biblio_auth_number` bigint(20) unsigned NOT NULL default '0',
2280   `operation` char(20) NOT NULL default '',
2281   `server` char(20) NOT NULL default '',
2282   `done` int(11) NOT NULL default '0',
2283   `time` timestamp NOT NULL default CURRENT_TIMESTAMP,
2284   PRIMARY KEY  (`id`),
2285   KEY `zebraqueue_lookup` (`server`, `biblio_auth_number`, `operation`, `done`)
2286 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2287
2288 --
2289 -- Table structure for table `language_subtag_registry`
2290 -- http://www.w3.org/International/articles/language-tags/
2291 -- RFC4646
2292 --
2293
2294 DROP TABLE IF EXISTS language_subtag_registry;
2295 CREATE TABLE language_subtag_registry (
2296         subtag varchar(25),
2297         type varchar(25), -- language-script-region-variant-extension-privateuse
2298         description varchar(25), -- only one of the possible descriptions for ease of reference, see language_descriptions for the complete list
2299         added date,
2300         id int(11) NOT NULL auto_increment,
2301         PRIMARY KEY  (`id`),
2302         KEY `subtag` (`subtag`)
2303 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2304
2305 --
2306 -- Table structure for table `language_rfc4646_to_iso639`
2307 -- TODO: add suppress_scripts
2308 -- this maps three letter codes defined in iso639.2 back to their
2309 -- two letter equivilents in rfc4646 (LOC maintains iso639+)
2310 --
2311
2312 DROP TABLE IF EXISTS language_rfc4646_to_iso639;
2313 CREATE TABLE language_rfc4646_to_iso639 (
2314         rfc4646_subtag varchar(25),
2315         iso639_2_code varchar(25),
2316         id int(11) NOT NULL auto_increment,
2317         PRIMARY KEY  (`id`),
2318         KEY `rfc4646_subtag` (`rfc4646_subtag`)
2319 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2320
2321 --
2322 -- Table structure for table `language_descriptions`
2323 --
2324
2325 DROP TABLE IF EXISTS language_descriptions;
2326 CREATE TABLE language_descriptions (
2327         subtag varchar(25),
2328         type varchar(25),
2329         lang varchar(25),
2330         description varchar(255),
2331         id int(11) NOT NULL auto_increment,
2332         PRIMARY KEY  (`id`),
2333         KEY `lang` (`lang`),
2334         KEY `subtag_type_lang` (`subtag`, `type`, `lang`)
2335 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2336
2337 --
2338 -- Table structure for table `language_script_bidi`
2339 -- bi-directional support, keyed by script subcode
2340 --
2341
2342 DROP TABLE IF EXISTS language_script_bidi;
2343 CREATE TABLE language_script_bidi (
2344         rfc4646_subtag varchar(25), -- script subtag, Arab, Hebr, etc.
2345         bidi varchar(3), -- rtl ltr
2346         KEY `rfc4646_subtag` (`rfc4646_subtag`)
2347 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2348
2349 --
2350 -- Table structure for table `language_script_mapping`
2351 -- TODO: need to map language subtags to script subtags for detection
2352 -- of bidi when script is not specified (like ar, he)
2353 --
2354
2355 DROP TABLE IF EXISTS language_script_mapping;
2356 CREATE TABLE language_script_mapping (
2357         language_subtag varchar(25),
2358         script_subtag varchar(25),
2359         KEY `language_subtag` (`language_subtag`)
2360 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2361
2362 --
2363 -- Table structure for table `permissions`
2364 --
2365
2366 DROP TABLE IF EXISTS `permissions`;
2367 CREATE TABLE `permissions` (
2368   `module_bit` int(11) NOT NULL DEFAULT 0,
2369   `code` varchar(64) NOT NULL DEFAULT '',
2370   `description` varchar(255) DEFAULT NULL,
2371   PRIMARY KEY  (`module_bit`, `code`),
2372   CONSTRAINT `permissions_ibfk_1` FOREIGN KEY (`module_bit`) REFERENCES `userflags` (`bit`)
2373     ON DELETE CASCADE ON UPDATE CASCADE
2374 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2375
2376 --
2377 -- Table structure for table `serialitems`
2378 --
2379
2380 DROP TABLE IF EXISTS `serialitems`;
2381 CREATE TABLE `serialitems` (
2382         `itemnumber` int(11) NOT NULL,
2383         `serialid` int(11) NOT NULL,
2384     PRIMARY KEY (`itemnumber`),
2385         KEY `serialitems_sfk_1` (`serialid`),
2386         CONSTRAINT `serialitems_sfk_1` FOREIGN KEY (`serialid`) REFERENCES `serial` (`serialid`) ON DELETE CASCADE ON UPDATE CASCADE,
2387         CONSTRAINT `serialitems_sfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE
2388 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2389
2390 --
2391 -- Table structure for table `user_permissions`
2392 --
2393
2394 DROP TABLE IF EXISTS `user_permissions`;
2395 CREATE TABLE `user_permissions` (
2396   `borrowernumber` int(11) NOT NULL DEFAULT 0,
2397   `module_bit` int(11) NOT NULL DEFAULT 0,
2398   `code` varchar(64) DEFAULT NULL,
2399   CONSTRAINT `user_permissions_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
2400     ON DELETE CASCADE ON UPDATE CASCADE,
2401   CONSTRAINT `user_permissions_ibfk_2` FOREIGN KEY (`module_bit`, `code`) REFERENCES `permissions` (`module_bit`, `code`)
2402     ON DELETE CASCADE ON UPDATE CASCADE
2403 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2404
2405 --
2406 -- Table structure for table `tmp_holdsqueue`
2407 --
2408
2409 DROP TABLE IF EXISTS `tmp_holdsqueue`;
2410 CREATE TABLE `tmp_holdsqueue` (
2411   `biblionumber` int(11) default NULL,
2412   `itemnumber` int(11) default NULL,
2413   `barcode` varchar(20) default NULL,
2414   `surname` LONGTEXT NOT NULL,
2415   `firstname` MEDIUMTEXT,
2416   `phone` MEDIUMTEXT,
2417   `borrowernumber` int(11) NOT NULL,
2418   `cardnumber` varchar(32) default NULL,
2419   `reservedate` date default NULL,
2420   `title` LONGTEXT,
2421   `itemcallnumber` varchar(255) default NULL,
2422   `holdingbranch` varchar(10) default NULL,
2423   `pickbranch` varchar(10) default NULL,
2424   `notes` MEDIUMTEXT,
2425   `item_level_request` tinyint(4) NOT NULL default 0,
2426   CONSTRAINT `tmp_holdsqueue_ibfk_1` FOREIGN KEY (`itemnumber`)
2427     REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE
2428 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2429
2430 --
2431 -- Table structure for table `message_transport_types`
2432 --
2433
2434 DROP TABLE IF EXISTS `message_transport_types`;
2435 CREATE TABLE `message_transport_types` (
2436   `message_transport_type` varchar(20) NOT NULL,
2437   PRIMARY KEY  (`message_transport_type`)
2438 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2439
2440 --
2441 -- Table structure for table `message_queue`
2442 --
2443
2444 DROP TABLE IF EXISTS `message_queue`;
2445 CREATE TABLE `message_queue` (
2446   `message_id` int(11) NOT NULL auto_increment,
2447   `borrowernumber` int(11) default NULL,
2448   `subject` MEDIUMTEXT,
2449   `content` MEDIUMTEXT,
2450   `metadata` MEDIUMTEXT DEFAULT NULL,
2451   `letter_code` varchar(64) DEFAULT NULL,
2452   `message_transport_type` varchar(20) NOT NULL,
2453   `status` enum('sent','pending','failed','deleted') NOT NULL default 'pending',
2454   `time_queued` timestamp NULL,
2455   `updated_on` timestamp NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
2456   `to_address` LONGTEXT,
2457   `from_address` LONGTEXT,
2458   `reply_address` LONGTEXT,
2459   `content_type` MEDIUMTEXT,
2460   PRIMARY KEY `message_id` (`message_id`),
2461   KEY `borrowernumber` (`borrowernumber`),
2462   KEY `message_transport_type` (`message_transport_type`),
2463   CONSTRAINT `messageq_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2464   CONSTRAINT `messageq_ibfk_2` FOREIGN KEY (`message_transport_type`) REFERENCES `message_transport_types` (`message_transport_type`) ON DELETE RESTRICT ON UPDATE CASCADE
2465 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2466
2467 --
2468 -- Table structure for table `letter`
2469 --
2470
2471 DROP TABLE IF EXISTS `letter`;
2472 CREATE TABLE `letter` ( -- table for all notice templates in Koha
2473   `module` varchar(20) NOT NULL default '', -- Koha module that triggers this notice or slip
2474   `code` varchar(20) NOT NULL default '', -- unique identifier for this notice or slip
2475   `branchcode` varchar(10) NOT NULL default '', -- the branch this notice or slip is used at (branches.branchcode)
2476   `name` varchar(100) NOT NULL default '', -- plain text name for this notice or slip
2477   `is_html` tinyint(1) default 0, -- does this notice or slip use HTML (1 for yes, 0 for no)
2478   `title` varchar(200) NOT NULL default '', -- subject line of the notice
2479   `content` MEDIUMTEXT, -- body text for the notice or slip
2480   `message_transport_type` varchar(20) NOT NULL DEFAULT 'email', -- transport type for this notice
2481   `lang` varchar(25) NOT NULL DEFAULT 'default', -- lang of the notice
2482   PRIMARY KEY  (`module`,`code`, `branchcode`, `message_transport_type`, `lang`),
2483   CONSTRAINT `message_transport_type_fk` FOREIGN KEY (`message_transport_type`)
2484   REFERENCES `message_transport_types` (`message_transport_type`) ON DELETE CASCADE ON UPDATE CASCADE
2485 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2486
2487 --
2488 -- Table structure for table `overduerules_transport_types`
2489 --
2490
2491 DROP TABLE IF EXISTS `overduerules_transport_types`;
2492 CREATE TABLE overduerules_transport_types(
2493     `id` INT(11) NOT NULL AUTO_INCREMENT,
2494     `letternumber` INT(1) NOT NULL DEFAULT 1,
2495     `message_transport_type` VARCHAR(20) NOT NULL DEFAULT 'email',
2496     `overduerules_id` INT(11) NOT NULL,
2497     PRIMARY KEY (id),
2498     CONSTRAINT overduerules_fk FOREIGN KEY (overduerules_id) REFERENCES overduerules (overduerules_id) ON DELETE CASCADE ON UPDATE CASCADE,
2499     CONSTRAINT mtt_fk FOREIGN KEY (message_transport_type) REFERENCES message_transport_types (message_transport_type) ON DELETE CASCADE ON UPDATE CASCADE
2500 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2501
2502 --
2503 -- Table structure for table `message_attributes`
2504 --
2505
2506 DROP TABLE IF EXISTS `message_attributes`;
2507 CREATE TABLE `message_attributes` (
2508   `message_attribute_id` int(11) NOT NULL auto_increment,
2509   `message_name` varchar(40) NOT NULL default '',
2510   `takes_days` tinyint(1) NOT NULL default '0',
2511   PRIMARY KEY  (`message_attribute_id`),
2512   UNIQUE KEY `message_name` (`message_name`)
2513 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2514
2515 --
2516 -- Table structure for table `message_transports`
2517 --
2518
2519 DROP TABLE IF EXISTS `message_transports`;
2520 CREATE TABLE `message_transports` (
2521   `message_attribute_id` int(11) NOT NULL,
2522   `message_transport_type` varchar(20) NOT NULL,
2523   `is_digest` tinyint(1) NOT NULL default '0',
2524   `letter_module` varchar(20) NOT NULL default '',
2525   `letter_code` varchar(20) NOT NULL default '',
2526   `branchcode` varchar(10) NOT NULL default '',
2527   PRIMARY KEY  (`message_attribute_id`,`message_transport_type`,`is_digest`),
2528   KEY `message_transport_type` (`message_transport_type`),
2529   KEY `letter_module` (`letter_module`,`letter_code`),
2530   CONSTRAINT `message_transports_ibfk_1` FOREIGN KEY (`message_attribute_id`) REFERENCES `message_attributes` (`message_attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE,
2531   CONSTRAINT `message_transports_ibfk_2` FOREIGN KEY (`message_transport_type`) REFERENCES `message_transport_types` (`message_transport_type`) ON DELETE CASCADE ON UPDATE CASCADE
2532 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2533
2534 --
2535 -- Table structure for table `borrower_files`
2536 --
2537
2538 DROP TABLE IF EXISTS `borrower_files`;
2539 CREATE TABLE IF NOT EXISTS `borrower_files` ( -- files attached to the patron/borrower record
2540   `file_id` int(11) NOT NULL AUTO_INCREMENT, -- unique key
2541   `borrowernumber` int(11) NOT NULL, -- foreign key linking to the patron via the borrowernumber
2542   `file_name` varchar(255) NOT NULL, -- file name
2543   `file_type` varchar(255) NOT NULL, -- type of file
2544   `file_description` varchar(255) DEFAULT NULL, -- description given to the file
2545   `file_content` longblob NOT NULL, -- the file
2546   `date_uploaded` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- date and time the file was added
2547   PRIMARY KEY (`file_id`),
2548   KEY `borrowernumber` (`borrowernumber`),
2549   CONSTRAINT borrower_files_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE
2550 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2551
2552 --
2553 -- Table structure for table `borrower_message_preferences`
2554 --
2555
2556 DROP TABLE IF EXISTS `borrower_message_preferences`;
2557 CREATE TABLE `borrower_message_preferences` (
2558   `borrower_message_preference_id` int(11) NOT NULL auto_increment,
2559   `borrowernumber` int(11) default NULL,
2560   `categorycode` varchar(10) default NULL,
2561   `message_attribute_id` int(11) default '0',
2562   `days_in_advance` int(11) default '0',
2563   `wants_digest` tinyint(1) NOT NULL default '0',
2564   PRIMARY KEY  (`borrower_message_preference_id`),
2565   KEY `borrowernumber` (`borrowernumber`),
2566   KEY `categorycode` (`categorycode`),
2567   KEY `message_attribute_id` (`message_attribute_id`),
2568   CONSTRAINT `borrower_message_preferences_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2569   CONSTRAINT `borrower_message_preferences_ibfk_2` FOREIGN KEY (`message_attribute_id`) REFERENCES `message_attributes` (`message_attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE,
2570   CONSTRAINT `borrower_message_preferences_ibfk_3` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) ON DELETE CASCADE ON UPDATE CASCADE
2571 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2572
2573 --
2574 -- Table structure for table `borrower_message_transport_preferences`
2575 --
2576
2577 DROP TABLE IF EXISTS `borrower_message_transport_preferences`;
2578 CREATE TABLE `borrower_message_transport_preferences` (
2579   `borrower_message_preference_id` int(11) NOT NULL default '0',
2580   `message_transport_type` varchar(20) NOT NULL default '0',
2581   PRIMARY KEY  (`borrower_message_preference_id`,`message_transport_type`),
2582   KEY `message_transport_type` (`message_transport_type`),
2583   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,
2584   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
2585 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2586
2587 --
2588 -- Table structure for the table branch_transfer_limits
2589 --
2590
2591 DROP TABLE IF EXISTS `branch_transfer_limits`;
2592 CREATE TABLE branch_transfer_limits (
2593     limitId int(8) NOT NULL auto_increment,
2594     toBranch varchar(10) NOT NULL,
2595     fromBranch varchar(10) NOT NULL,
2596     itemtype varchar(10) NULL,
2597     ccode varchar(80) NULL,
2598     PRIMARY KEY  (limitId)
2599 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2600
2601 --
2602 -- Table structure for table `item_circulation_alert_preferences`
2603 --
2604
2605 DROP TABLE IF EXISTS `item_circulation_alert_preferences`;
2606 CREATE TABLE `item_circulation_alert_preferences` (
2607   `id` int(11) NOT NULL auto_increment,
2608   `branchcode` varchar(10) NOT NULL,
2609   `categorycode` varchar(10) NOT NULL,
2610   `item_type` varchar(10) NOT NULL,
2611   `notification` varchar(16) NOT NULL,
2612   PRIMARY KEY  (`id`),
2613   KEY `branchcode` (`branchcode`,`categorycode`,`item_type`, `notification`)
2614 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2615
2616 --
2617 -- Table structure for table `messages`
2618 --
2619 DROP TABLE IF EXISTS `messages`;
2620 CREATE TABLE `messages` ( -- circulation messages left via the patron's check out screen
2621   `message_id` int(11) NOT NULL auto_increment, -- unique identifier assigned by Koha
2622   `borrowernumber` int(11) NOT NULL, -- foreign key linking this message to the borrowers table
2623   `branchcode` varchar(10) default NULL, -- foreign key linking the message to the branches table
2624   `message_type` varchar(1) NOT NULL, -- whether the message is for the librarians (L) or the patron (B)
2625   `message` MEDIUMTEXT NOT NULL, -- the text of the message
2626   `message_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- the date and time the message was written
2627   `manager_id` int(11) default NULL, -- creator of message
2628   PRIMARY KEY (`message_id`),
2629   CONSTRAINT `messages_ibfk_1` FOREIGN KEY (`manager_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL,
2630   CONSTRAINT `messages_borrowernumber` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
2631 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2632
2633 --
2634 -- Table structure for table `cash_registers`
2635 --
2636
2637 DROP TABLE IF EXISTS `cash_registers`;
2638 CREATE TABLE `cash_registers` (
2639   `id` int(11) NOT NULL auto_increment, -- unique identifier for each account register
2640   `name` varchar(24) NOT NULL, -- the user friendly identifier for each account register
2641   `description` longtext NOT NULL, -- the user friendly description for each account register
2642   `branch` varchar(10) NOT NULL, -- the foreign key the library this account register belongs
2643   `branch_default` tinyint(1) NOT NULL DEFAULT 0, -- boolean flag to denote that this till is the branch default
2644   `starting_float` decimal(28, 6), -- the starting float this account register should be assigned
2645   `archived` tinyint(1) NOT NULL DEFAULT 0, -- boolean flag to denote if this till is archived or not
2646   PRIMARY KEY (`id`),
2647   UNIQUE KEY `name` (`name`,`branch`),
2648   CONSTRAINT cash_registers_branch FOREIGN KEY (branch) REFERENCES branches (branchcode) ON UPDATE CASCADE ON DELETE CASCADE
2649 ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
2650
2651 --
2652 -- Table structure for table `account_credit_types`
2653 --
2654
2655 DROP TABLE IF EXISTS `account_credit_types`;
2656 CREATE TABLE `account_credit_types` (
2657   `code` varchar(80) NOT NULL,
2658   `description` varchar(200) DEFAULT NULL,
2659   `can_be_added_manually` tinyint(4) NOT NULL DEFAULT 1,
2660   `is_system` tinyint(1) NOT NULL DEFAULT 0,
2661   `archived` tinyint(1) NOT NULL DEFAULT 0, -- boolean flag to denote if this till is archived or not
2662   PRIMARY KEY (`code`)
2663 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2664
2665 --
2666 -- Table structure for table `account_credit_types_branches`
2667 --
2668
2669 DROP TABLE IF EXISTS `account_credit_types_branches`;
2670 CREATE TABLE `account_credit_types_branches` (
2671     `credit_type_code` VARCHAR(80),
2672     `branchcode` VARCHAR(10),
2673     FOREIGN KEY (`credit_type_code`) REFERENCES `account_credit_types` (`code`) ON DELETE CASCADE,
2674     FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE
2675 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2676
2677 --
2678 -- Table structure for table `account_debit_types`
2679 --
2680
2681 DROP TABLE IF EXISTS `account_debit_types`;
2682 CREATE TABLE `account_debit_types` (
2683   `code` varchar(80) NOT NULL,
2684   `description` varchar(200) DEFAULT NULL,
2685   `can_be_invoiced` tinyint(1) NOT NULL DEFAULT 1, -- boolean flag to denote if this debit type is available for manual invoicing
2686   `can_be_sold` tinyint(1) NOT NULL DEFAULT 0, -- boolean flag to denote if this debit type is available at point of sale
2687   `default_amount` decimal(28,6) DEFAULT NULL,
2688   `is_system` tinyint(1) NOT NULL DEFAULT 0,
2689   `archived` tinyint(1) NOT NULL DEFAULT 0, -- boolean flag to denote if this till is archived or not
2690   PRIMARY KEY (`code`)
2691 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2692
2693 --
2694 -- Table structure for table `account_debit_types_branches`
2695 --
2696
2697 DROP TABLE IF EXISTS `account_debit_types_branches`;
2698 CREATE TABLE `account_debit_types_branches` (
2699     `debit_type_code` VARCHAR(80),
2700     `branchcode` VARCHAR(10),
2701     FOREIGN KEY (`debit_type_code`) REFERENCES `account_debit_types` (`code`) ON DELETE CASCADE,
2702     FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE
2703 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2704
2705 --
2706 -- Table structure for table `accountlines`
2707 --
2708
2709 DROP TABLE IF EXISTS `accountlines`;
2710 CREATE TABLE `accountlines` (
2711   `accountlines_id` int(11) NOT NULL AUTO_INCREMENT,
2712   `issue_id` int(11) NULL DEFAULT NULL,
2713   `borrowernumber` int(11) DEFAULT NULL,
2714   `itemnumber` int(11) default NULL,
2715   `date` timestamp NULL,
2716   `amount` decimal(28,6) default NULL,
2717   `description` LONGTEXT,
2718   `credit_type_code` varchar(80) default NULL,
2719   `debit_type_code` varchar(80) default NULL,
2720   `status` varchar(16) default NULL,
2721   `payment_type` varchar(80) default NULL, -- optional authorised value PAYMENT_TYPE
2722   `amountoutstanding` decimal(28,6) default NULL,
2723   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
2724   `note` MEDIUMTEXT NULL default NULL,
2725   `manager_id` int(11) NULL DEFAULT NULL,
2726   `register_id` int(11) NULL DEFAULT NULL,
2727   `interface` VARCHAR(16) NOT NULL,
2728   `branchcode` VARCHAR( 10 ) NULL DEFAULT NULL, -- the branchcode of the library where a payment was made, a manual invoice created, etc.
2729   PRIMARY KEY (`accountlines_id`),
2730   KEY `acctsborridx` (`borrowernumber`),
2731   KEY `timeidx` (`timestamp`),
2732   KEY `credit_type_code` (`credit_type_code`),
2733   KEY `debit_type_code` (`debit_type_code`),
2734   KEY `itemnumber` (`itemnumber`),
2735   KEY `branchcode` (`branchcode`),
2736   KEY `manager_id` (`manager_id`),
2737   CONSTRAINT `accountlines_ibfk_borrowers` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
2738   CONSTRAINT `accountlines_ibfk_items` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE SET NULL ON UPDATE CASCADE,
2739   CONSTRAINT `accountlines_ibfk_borrowers_2` FOREIGN KEY (`manager_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
2740   CONSTRAINT `accountlines_ibfk_branches` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE,
2741   CONSTRAINT `accountlines_ibfk_registers` FOREIGN KEY (`register_id`) REFERENCES `cash_registers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
2742   CONSTRAINT `accountlines_ibfk_credit_type` FOREIGN KEY (`credit_type_code`) REFERENCES `account_credit_types` (`code`) ON DELETE RESTRICT ON UPDATE CASCADE,
2743   CONSTRAINT `accountlines_ibfk_debit_type` FOREIGN KEY (`debit_type_code`) REFERENCES `account_debit_types` (`code`) ON DELETE RESTRICT ON UPDATE CASCADE
2744 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2745
2746 --
2747 -- Table structure for table `account_offset_types`
2748 --
2749
2750 DROP TABLE IF EXISTS `account_offset_types`;
2751 CREATE TABLE `account_offset_types` (
2752   `type` varchar(16) NOT NULL, -- The type of offset this is
2753   PRIMARY KEY (`type`)
2754 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2755
2756 --
2757 -- Table structure for table `account_offsets`
2758 --
2759
2760 DROP TABLE IF EXISTS `account_offsets`;
2761 CREATE TABLE `account_offsets` (
2762   `id` int(11) NOT NULL auto_increment, -- unique identifier for each offset
2763   `credit_id` int(11) NULL DEFAULT NULL, -- The id of the accountline the increased the patron's balance
2764   `debit_id` int(11) NULL DEFAULT NULL, -- The id of the accountline that decreased the patron's balance
2765   `type` varchar(16) NOT NULL, -- The type of offset this is
2766   `amount` decimal(26,6) NOT NULL, -- The amount of the change
2767   `created_on` timestamp NOT NULL default CURRENT_TIMESTAMP,
2768   PRIMARY KEY (`id`),
2769   CONSTRAINT `account_offsets_ibfk_p` FOREIGN KEY (`credit_id`) REFERENCES `accountlines` (`accountlines_id`) ON DELETE CASCADE ON UPDATE CASCADE,
2770   CONSTRAINT `account_offsets_ibfk_f` FOREIGN KEY (`debit_id`) REFERENCES `accountlines` (`accountlines_id`) ON DELETE CASCADE ON UPDATE CASCADE,
2771   CONSTRAINT `account_offsets_ibfk_t` FOREIGN KEY (`type`) REFERENCES `account_offset_types` (`type`) ON DELETE CASCADE ON UPDATE CASCADE
2772 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2773
2774 --
2775 -- Table structure for table `cash_register_actions`
2776 --
2777
2778 DROP TABLE IF EXISTS `cash_register_actions`;
2779 CREATE TABLE `cash_register_actions` (
2780   `id` int(11) NOT NULL auto_increment, -- unique identifier for each account register action
2781   `code` varchar(24) NOT NULL, -- action code denoting the type of action recorded (enum),
2782   `register_id` int(11) NOT NULL, -- id of cash_register this action belongs to,
2783   `manager_id` int(11) NOT NULL, -- staff member performing the action
2784   `amount` decimal(28,6) DEFAULT NULL, -- amount recorded in action (signed)
2785   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
2786   PRIMARY KEY (`id`),
2787   CONSTRAINT `cash_register_actions_manager` FOREIGN KEY (`manager_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2788   CONSTRAINT `cash_register_actions_register` FOREIGN KEY (`register_id`) REFERENCES `cash_registers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
2789 ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
2790
2791 --
2792 -- Table structure for table `action_logs`
2793 --
2794
2795 DROP TABLE IF EXISTS `action_logs`;
2796 CREATE TABLE `action_logs` ( -- logs of actions taken in Koha (requires that the logs be turned on)
2797   `action_id` int(11) NOT NULL auto_increment, -- unique identifier for each action
2798   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP, -- the date and time the action took place
2799   `user` int(11) NOT NULL default 0, -- the staff member who performed the action (borrowers.borrowernumber)
2800   `module` MEDIUMTEXT, -- the module this action was taken against
2801   `action` MEDIUMTEXT, -- the action (includes things like DELETED, ADDED, MODIFY, etc)
2802   `object` int(11) default NULL, -- the object that the action was taken against (could be a borrowernumber, itemnumber, etc)
2803   `info` MEDIUMTEXT, -- information about the action (usually includes SQL statement)
2804   `interface` VARCHAR(30) DEFAULT NULL, -- the context this action was taken in
2805   PRIMARY KEY (`action_id`),
2806   KEY `timestamp_idx` (`timestamp`),
2807   KEY `user_idx` (`user`),
2808   KEY `module_idx` (`module`(255)),
2809   KEY `action_idx` (`action`(255)),
2810   KEY `object_idx` (`object`),
2811   KEY `info_idx` (`info`(255)),
2812   KEY `interface` (`interface`)
2813 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2814
2815 --
2816 -- Table structure for table `alert`
2817 --
2818
2819 DROP TABLE IF EXISTS `alert`;
2820 CREATE TABLE `alert` (
2821   `alertid` int(11) NOT NULL auto_increment,
2822   `borrowernumber` int(11) NOT NULL default 0,
2823   `type` varchar(10) NOT NULL default '',
2824   `externalid` varchar(20) NOT NULL default '',
2825   PRIMARY KEY  (`alertid`),
2826   KEY `borrowernumber` (`borrowernumber`),
2827   KEY `type` (`type`,`externalid`)
2828 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2829
2830 --
2831 -- Table structure for table `aqbooksellers`
2832 --
2833
2834 DROP TABLE IF EXISTS `aqbooksellers`;
2835 CREATE TABLE `aqbooksellers` ( -- information about the vendors listed in acquisitions
2836   `id` int(11) NOT NULL auto_increment, -- primary key and unique identifier assigned by Koha
2837   `name` LONGTEXT NOT NULL, -- vendor name
2838   `address1` LONGTEXT, -- first line of vendor physical address
2839   `address2` LONGTEXT, -- second line of vendor physical address
2840   `address3` LONGTEXT, -- third line of vendor physical address
2841   `address4` LONGTEXT, -- fourth line of vendor physical address
2842   `phone` varchar(30) default NULL, -- vendor phone number
2843   `accountnumber` LONGTEXT, -- vendor account number
2844   `notes` LONGTEXT, -- order notes
2845   `postal` LONGTEXT, -- vendor postal address (all lines)
2846   `url` varchar(255) default NULL, -- vendor web address
2847   `active` tinyint(4) default NULL, -- is this vendor active (1 for yes, 0 for no)
2848   `listprice` varchar(10) default NULL, -- currency code for list prices
2849   `invoiceprice` varchar(10) default NULL, -- currency code for invoice prices
2850   `gstreg` tinyint(4) default NULL, -- is your library charged tax (1 for yes, 0 for no)
2851   `listincgst` tinyint(4) default NULL, -- is tax included in list prices (1 for yes, 0 for no)
2852   `invoiceincgst` tinyint(4) default NULL, -- is tax included in invoice prices (1 for yes, 0 for no)
2853   `tax_rate` decimal(6,4) default NULL, -- the tax rate the library is charged
2854   `discount` float(6,4) default NULL, -- discount offered on all items ordered from this vendor
2855   `fax` varchar(50) default NULL, -- vendor fax number
2856   deliverytime int(11) default NULL, -- vendor delivery time
2857   PRIMARY KEY  (`id`),
2858   KEY `listprice` (`listprice`),
2859   KEY `invoiceprice` (`invoiceprice`),
2860   KEY `name` (`name`(255)),
2861   CONSTRAINT `aqbooksellers_ibfk_1` FOREIGN KEY (`listprice`) REFERENCES `currency` (`currency`) ON DELETE CASCADE ON UPDATE CASCADE,
2862   CONSTRAINT `aqbooksellers_ibfk_2` FOREIGN KEY (`invoiceprice`) REFERENCES `currency` (`currency`) ON DELETE CASCADE ON UPDATE CASCADE
2863 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2864
2865 --
2866 -- Table structure for table `aqbasketgroups`
2867 --
2868
2869 DROP TABLE IF EXISTS `aqbasketgroups`;
2870 CREATE TABLE `aqbasketgroups` (
2871   `id` int(11) NOT NULL auto_increment,
2872   `name` varchar(50) default NULL,
2873   `closed` tinyint(1) default NULL,
2874   `booksellerid` int(11) NOT NULL,
2875   `deliveryplace` varchar(10) default NULL,
2876   `freedeliveryplace` MEDIUMTEXT default NULL,
2877   `deliverycomment` varchar(255) default NULL,
2878   `billingplace` varchar(10) default NULL,
2879   PRIMARY KEY  (`id`),
2880   KEY `booksellerid` (`booksellerid`),
2881   CONSTRAINT `aqbasketgroups_ibfk_1` FOREIGN KEY (`booksellerid`) REFERENCES `aqbooksellers` (`id`) ON UPDATE CASCADE ON DELETE CASCADE
2882 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2883
2884 --
2885 -- Table structure for table `aqbudgets`
2886 --
2887
2888 DROP TABLE IF EXISTS `aqbudgets`;
2889 CREATE TABLE `aqbudgets` ( -- information related to Funds
2890   `budget_id` int(11) NOT NULL auto_increment, -- primary key and unique number assigned to each fund by Koha
2891   `budget_parent_id` int(11) default NULL, -- if this fund is a child of another this will include the parent id (aqbudgets.budget_id)
2892   `budget_code` varchar(30) default NULL, -- code assigned to the fund by the user
2893   `budget_name` varchar(80) default NULL, -- name assigned to the fund by the user
2894   `budget_branchcode` varchar(10) default NULL, -- branch that this fund belongs to (branches.branchcode)
2895   `budget_amount` decimal(28,6) NULL default '0.00', -- total amount for this fund
2896   `budget_encumb` decimal(28,6) NULL default '0.00', -- budget warning at percentage
2897   `budget_expend` decimal(28,6) NULL default '0.00', -- budget warning at amount
2898   `budget_notes` LONGTEXT, -- notes related to this fund
2899   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- date and time this fund was last touched (created or modified)
2900   `budget_period_id` int(11) default NULL, -- id of the budget that this fund belongs to (aqbudgetperiods.budget_period_id)
2901   `sort1_authcat` varchar(80) default NULL, -- statistical category for this fund
2902   `sort2_authcat` varchar(80) default NULL, -- second statistical category for this fund
2903   `budget_owner_id` int(11) default NULL, -- borrowernumber of the person who owns this fund (borrowers.borrowernumber)
2904   `budget_permission` int(1) default '0', -- level of permission for this fund (used only by the owner, only by the library, or anyone)
2905   PRIMARY KEY  (`budget_id`),
2906   KEY `budget_parent_id` (`budget_parent_id`),
2907   KEY `budget_code` (`budget_code`),
2908   KEY `budget_branchcode` (`budget_branchcode`),
2909   KEY `budget_period_id` (`budget_period_id`),
2910   KEY `budget_owner_id` (`budget_owner_id`)
2911 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2912
2913 --
2914 -- Table structure for table aqbudgetborrowers
2915 --
2916
2917 DROP TABLE IF EXISTS aqbudgetborrowers;
2918 CREATE TABLE aqbudgetborrowers (
2919   budget_id int(11) NOT NULL,
2920   borrowernumber int(11) NOT NULL,
2921   PRIMARY KEY (budget_id, borrowernumber),
2922   CONSTRAINT aqbudgetborrowers_ibfk_1 FOREIGN KEY (budget_id)
2923     REFERENCES aqbudgets (budget_id)
2924     ON DELETE CASCADE ON UPDATE CASCADE,
2925   CONSTRAINT aqbudgetborrowers_ibfk_2 FOREIGN KEY (borrowernumber)
2926     REFERENCES borrowers (borrowernumber)
2927     ON DELETE CASCADE ON UPDATE CASCADE
2928 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2929
2930 --
2931 -- Table structure for table `aqbudgetperiods`
2932 --
2933
2934
2935 DROP TABLE IF EXISTS `aqbudgetperiods`;
2936 CREATE TABLE `aqbudgetperiods` ( -- information related to Budgets
2937   `budget_period_id` int(11) NOT NULL auto_increment, -- primary key and unique number assigned by Koha
2938   `budget_period_startdate` date NOT NULL, -- date when the budget starts
2939   `budget_period_enddate` date NOT NULL, -- date when the budget ends
2940   `budget_period_active` tinyint(1) default '0', -- whether this budget is active or not (1 for yes, 0 for no)
2941   `budget_period_description` LONGTEXT, -- description assigned to this budget
2942   `budget_period_total` decimal(28,6), -- total amount available in this budget
2943   `budget_period_locked` tinyint(1) default NULL, -- whether this budget is locked or not (1 for yes, 0 for no)
2944   `sort1_authcat` varchar(10) default NULL, -- statistical category for this budget
2945   `sort2_authcat` varchar(10) default NULL, -- second statistical category for this budget
2946   PRIMARY KEY  (`budget_period_id`)
2947 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2948
2949 --
2950 -- Table structure for table `aqbudgets_planning`
2951 --
2952
2953 DROP TABLE IF EXISTS `aqbudgets_planning`;
2954 CREATE TABLE `aqbudgets_planning` (
2955   `plan_id` int(11) NOT NULL auto_increment,
2956   `budget_id` int(11) NOT NULL,
2957   `budget_period_id` int(11) NOT NULL,
2958   `estimated_amount` decimal(28,6) default NULL,
2959   `authcat` varchar(30) NOT NULL,
2960   `authvalue` varchar(30) NOT NULL,
2961   `display` tinyint(1) DEFAULT 1,
2962   PRIMARY KEY  (`plan_id`),
2963   KEY `budget_period_id` (`budget_period_id`),
2964   CONSTRAINT `aqbudgets_planning_ifbk_1` FOREIGN KEY (`budget_id`) REFERENCES `aqbudgets` (`budget_id`) ON DELETE CASCADE ON UPDATE CASCADE
2965 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2966
2967 --
2968 -- Table structure for table 'aqcontacts'
2969 --
2970
2971 DROP TABLE IF EXISTS aqcontacts;
2972 CREATE TABLE aqcontacts (
2973   id int(11) NOT NULL auto_increment, -- primary key and unique number assigned by Koha
2974   name varchar(100) default NULL, -- name of contact at vendor
2975   position varchar(100) default NULL, -- contact person's position
2976   phone varchar(100) default NULL, -- contact's phone number
2977   altphone varchar(100) default NULL, -- contact's alternate phone number
2978   fax varchar(100) default NULL,  -- contact's fax number
2979   email varchar(100) default NULL, -- contact's email address
2980   notes LONGTEXT, -- notes related to the contact
2981   orderacquisition tinyint(1) NOT NULL DEFAULT 0, -- should this contact receive acquisition orders
2982   claimacquisition tinyint(1) NOT NULL DEFAULT 0, -- should this contact receive acquisitions claims
2983   claimissues tinyint(1) NOT NULL DEFAULT 0, -- should this contact receive serial claims
2984   acqprimary tinyint(1) NOT NULL DEFAULT 0, -- is this the primary contact for acquisitions messages
2985   serialsprimary tinyint(1) NOT NULL DEFAULT 0, -- is this the primary contact for serials messages
2986   booksellerid int(11) not NULL,
2987   PRIMARY KEY  (id),
2988   CONSTRAINT booksellerid_aqcontacts_fk FOREIGN KEY (booksellerid)
2989        REFERENCES aqbooksellers (id) ON DELETE CASCADE ON UPDATE CASCADE
2990 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT=1;
2991
2992 --
2993 -- Table structure for table 'aqcontract'
2994 --
2995
2996 DROP TABLE IF EXISTS `aqcontract`;
2997 CREATE TABLE `aqcontract` (
2998   `contractnumber` int(11) NOT NULL auto_increment,
2999   `contractstartdate` date default NULL,
3000   `contractenddate` date default NULL,
3001   `contractname` varchar(50) default NULL,
3002   `contractdescription` LONGTEXT,
3003   `booksellerid` int(11) not NULL,
3004   PRIMARY KEY  (`contractnumber`),
3005   CONSTRAINT `booksellerid_fk1` FOREIGN KEY (`booksellerid`)
3006        REFERENCES `aqbooksellers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
3007 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT=1 ;
3008
3009 --
3010 -- Table structure for table `aqbasket`
3011 --
3012
3013 DROP TABLE IF EXISTS `aqbasket`;
3014 CREATE TABLE `aqbasket` ( -- stores data about baskets in acquisitions
3015   `basketno` int(11) NOT NULL auto_increment, -- primary key, Koha defined number
3016   `basketname` varchar(50) default NULL, -- name given to the basket at creation
3017   `note` LONGTEXT, -- the internal note added at basket creation
3018   `booksellernote` LONGTEXT, -- the vendor note added at basket creation
3019   `contractnumber` int(11), -- links this basket to the aqcontract table (aqcontract.contractnumber)
3020   `creationdate` date default NULL, -- the date the basket was created
3021   `closedate` date default NULL, -- the date the basket was closed
3022   `booksellerid` int(11) NOT NULL default 1, -- the Koha assigned ID for the vendor (aqbooksellers.id)
3023   `authorisedby` varchar(10) default NULL, -- the borrowernumber of the person who created the basket
3024   `booksellerinvoicenumber` LONGTEXT, -- appears to always be NULL
3025   `basketgroupid` int(11), -- links this basket to its group (aqbasketgroups.id)
3026   `deliveryplace` varchar(10) default NULL, -- basket delivery place
3027   `billingplace` varchar(10) default NULL, -- basket billing place
3028   branch varchar(10) default NULL, -- basket branch
3029   is_standing TINYINT(1) NOT NULL DEFAULT 0, -- orders in this basket are standing
3030   create_items ENUM('ordering', 'receiving', 'cataloguing') default NULL, -- when items should be created for orders in this basket
3031   PRIMARY KEY  (`basketno`),
3032   KEY `booksellerid` (`booksellerid`),
3033   KEY `basketgroupid` (`basketgroupid`),
3034   KEY `contractnumber` (`contractnumber`),
3035   KEY `authorisedby` (`authorisedby`),
3036   CONSTRAINT `aqbasket_ibfk_1` FOREIGN KEY (`booksellerid`) REFERENCES `aqbooksellers` (`id`) ON UPDATE CASCADE,
3037   CONSTRAINT `aqbasket_ibfk_2` FOREIGN KEY (`contractnumber`) REFERENCES `aqcontract` (`contractnumber`),
3038   CONSTRAINT `aqbasket_ibfk_3` FOREIGN KEY (`basketgroupid`) REFERENCES `aqbasketgroups` (`id`) ON UPDATE CASCADE,
3039   CONSTRAINT aqbasket_ibfk_4 FOREIGN KEY (branch) REFERENCES branches (branchcode) ON UPDATE CASCADE ON DELETE SET NULL
3040 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3041
3042 --
3043 -- Table structure for table aqbasketusers
3044 --
3045
3046 DROP TABLE IF EXISTS aqbasketusers;
3047 CREATE TABLE aqbasketusers (
3048   basketno int(11) NOT NULL,
3049   borrowernumber int(11) NOT NULL,
3050   PRIMARY KEY (basketno,borrowernumber),
3051   CONSTRAINT aqbasketusers_ibfk_1 FOREIGN KEY (basketno) REFERENCES aqbasket (basketno) ON UPDATE CASCADE ON DELETE CASCADE,
3052   CONSTRAINT aqbasketusers_ibfk_2 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON UPDATE CASCADE ON DELETE CASCADE
3053 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3054
3055 --
3056 -- Table structure for table `suggestions`
3057 --
3058
3059 DROP TABLE IF EXISTS `suggestions`;
3060 CREATE TABLE `suggestions` ( -- purchase suggestions
3061   `suggestionid` int(8) NOT NULL auto_increment, -- unique identifier assigned automatically by Koha
3062   `suggestedby` int(11) DEFAULT NULL, -- borrowernumber for the person making the suggestion, foreign key linking to the borrowers table
3063   `suggesteddate` date NOT NULL, -- date the suggestion was submitted
3064   `managedby` int(11) default NULL, -- borrowernumber for the librarian managing the suggestion, foreign key linking to the borrowers table
3065   `manageddate` date default NULL, -- date the suggestion was updated
3066    acceptedby INT(11) default NULL, -- borrowernumber for the librarian who accepted the suggestion, foreign key linking to the borrowers table
3067    accepteddate date default NULL, -- date the suggestion was marked as accepted
3068    rejectedby INT(11) default NULL, -- borrowernumber for the librarian who rejected the suggestion, foreign key linking to the borrowers table
3069    rejecteddate date default NULL, -- date the suggestion was marked as rejected
3070    lastmodificationby INT(11) default NULL, -- borrowernumber for the librarian who edit the suggestion for the last time
3071    lastmodificationdate date default NULL, -- date of the last modification
3072   `STATUS` varchar(10) NOT NULL default '', -- suggestion status (ASKED, CHECKED, ACCEPTED, REJECTED, ORDERED, AVAILABLE or a value from the SUGGEST_STATUS authorised value category)
3073   `archived` TINYINT(1) NOT NULL DEFAULT 0, -- is the suggestion archived?
3074   `note` LONGTEXT, -- note entered on the suggestion
3075   `author` varchar(80) default NULL, -- author of the suggested item
3076   `title` varchar(255) default NULL, -- title of the suggested item
3077   `copyrightdate` smallint(6) default NULL, -- copyright date of the suggested item
3078   `publishercode` varchar(255) default NULL, -- publisher of the suggested item
3079   `date` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,  -- date and time the suggestion was updated
3080   `volumedesc` varchar(255) default NULL,
3081   `publicationyear` smallint(6) default 0,
3082   `place` varchar(255) default NULL, -- publication place of the suggested item
3083   `isbn` varchar(30) default NULL, -- isbn of the suggested item
3084   `biblionumber` int(11) default NULL, -- foreign key linking the suggestion to the biblio table after the suggestion has been ordered
3085   `reason` MEDIUMTEXT, -- reason for accepting or rejecting the suggestion
3086   `patronreason` MEDIUMTEXT, -- reason for making the suggestion
3087    budgetid INT(11), -- foreign key linking the suggested budget to the aqbudgets table
3088    branchcode VARCHAR(10) default NULL, -- foreign key linking the suggested branch to the branches table
3089    collectiontitle MEDIUMTEXT default NULL, -- collection name for the suggested item
3090    itemtype VARCHAR(30) default NULL, -- suggested item type
3091    quantity SMALLINT(6) default NULL, -- suggested quantity to be purchased
3092    currency VARCHAR(10) default NULL, -- suggested currency for the suggested price
3093    price DECIMAL(28,6) default NULL, -- suggested price
3094    total DECIMAL(28,6) default NULL, -- suggested total cost (price*quantity updated for currency)
3095   PRIMARY KEY  (`suggestionid`),
3096   KEY `suggestedby` (`suggestedby`),
3097   KEY `managedby` (`managedby`),
3098   KEY `acceptedby` (`acceptedby`),
3099   KEY `rejectedby` (`rejectedby`),
3100   KEY `biblionumber` (`biblionumber`),
3101   KEY `budgetid` (`budgetid`),
3102   KEY `branchcode` (`branchcode`),
3103   KEY `status` (`STATUS`),
3104   CONSTRAINT `suggestions_ibfk_suggestedby` FOREIGN KEY (`suggestedby`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
3105   CONSTRAINT `suggestions_ibfk_managedby` FOREIGN KEY (`managedby`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
3106   CONSTRAINT `suggestions_ibfk_acceptedby` FOREIGN KEY (`acceptedby`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
3107   CONSTRAINT `suggestions_ibfk_rejectedby` FOREIGN KEY (`rejectedby`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
3108   CONSTRAINT `suggestions_ibfk_lastmodificationby` FOREIGN KEY (`lastmodificationby`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
3109   CONSTRAINT `suggestions_ibfk_biblionumber` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE,
3110   CONSTRAINT `suggestions_budget_id_fk` FOREIGN KEY (`budgetid`) REFERENCES `aqbudgets` (`budget_id`) ON DELETE SET NULL ON UPDATE CASCADE,
3111   CONSTRAINT `suggestions_ibfk_branchcode` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE
3112 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3113
3114 --
3115 -- Table structure for table vendor_edi_accounts
3116 --
3117
3118 DROP TABLE IF EXISTS vendor_edi_accounts;
3119 CREATE TABLE IF NOT EXISTS vendor_edi_accounts (
3120   id INT(11) NOT NULL auto_increment,
3121   description MEDIUMTEXT NOT NULL,
3122   host VARCHAR(40),
3123   username VARCHAR(40),
3124   password VARCHAR(40),
3125   last_activity DATE,
3126   vendor_id INT(11) REFERENCES aqbooksellers( id ),
3127   download_directory MEDIUMTEXT,
3128   upload_directory MEDIUMTEXT,
3129   san VARCHAR(20),
3130   id_code_qualifier VARCHAR(3) default '14',
3131   transport VARCHAR(6) default 'FTP',
3132   quotes_enabled TINYINT(1) not null default 0,
3133   invoices_enabled TINYINT(1) not null default 0,
3134   orders_enabled TINYINT(1) not null default 0,
3135   responses_enabled TINYINT(1) not null default 0,
3136   auto_orders TINYINT(1) not null default 0,
3137   shipment_budget INTEGER(11) REFERENCES aqbudgets( budget_id ),
3138   plugin varchar(256) NOT NULL DEFAULT "",
3139   PRIMARY KEY  (id),
3140   KEY vendorid (vendor_id),
3141   KEY shipmentbudget (shipment_budget),
3142   CONSTRAINT vfk_vendor_id FOREIGN KEY ( vendor_id ) REFERENCES aqbooksellers ( id ),
3143   CONSTRAINT vfk_shipment_budget FOREIGN KEY ( shipment_budget ) REFERENCES aqbudgets ( budget_id )
3144 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3145
3146 --
3147 -- Table structure for table edifact_messages
3148 --
3149
3150 DROP TABLE IF EXISTS edifact_messages;
3151 CREATE TABLE IF NOT EXISTS edifact_messages (
3152   id INT(11) NOT NULL auto_increment,
3153   message_type VARCHAR(10) NOT NULL,
3154   transfer_date DATE,
3155   vendor_id INT(11) REFERENCES aqbooksellers( id ),
3156   edi_acct  INTEGER REFERENCES vendor_edi_accounts( id ),
3157   status MEDIUMTEXT,
3158   basketno INT(11) REFERENCES aqbasket( basketno),
3159   raw_msg LONGTEXT,
3160   filename MEDIUMTEXT,
3161   deleted tinyint(1) NOT NULL DEFAULT 0,
3162   PRIMARY KEY  (id),
3163   KEY vendorid ( vendor_id),
3164   KEY ediacct (edi_acct),
3165   KEY basketno ( basketno),
3166   CONSTRAINT emfk_vendor FOREIGN KEY ( vendor_id ) REFERENCES aqbooksellers ( id ) ON DELETE CASCADE ON UPDATE CASCADE,
3167   CONSTRAINT emfk_edi_acct FOREIGN KEY ( edi_acct ) REFERENCES vendor_edi_accounts ( id ) ON DELETE CASCADE ON UPDATE CASCADE,
3168   CONSTRAINT emfk_basketno FOREIGN KEY ( basketno ) REFERENCES aqbasket ( basketno ) ON DELETE CASCADE ON UPDATE CASCADE
3169 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3170
3171 --
3172 -- Table structure for table aqinvoices
3173 --
3174
3175 DROP TABLE IF EXISTS aqinvoices;
3176 CREATE TABLE aqinvoices (
3177   invoiceid int(11) NOT NULL AUTO_INCREMENT,    -- ID of the invoice, primary key
3178   invoicenumber LONGTEXT NOT NULL,    -- Name of invoice
3179   booksellerid int(11) NOT NULL,    -- foreign key to aqbooksellers
3180   shipmentdate date default NULL,   -- date of shipment
3181   billingdate date default NULL,    -- date of billing
3182   closedate date default NULL,  -- invoice close date, NULL means the invoice is open
3183   shipmentcost decimal(28,6) default NULL,  -- shipment cost
3184   shipmentcost_budgetid int(11) default NULL,   -- foreign key to aqbudgets, link the shipment cost to a budget
3185   message_id int(11) default NULL, -- foreign key to edifact invoice message
3186   PRIMARY KEY (invoiceid),
3187   CONSTRAINT aqinvoices_fk_aqbooksellerid FOREIGN KEY (booksellerid) REFERENCES aqbooksellers (id) ON DELETE CASCADE ON UPDATE CASCADE,
3188   CONSTRAINT edifact_msg_fk FOREIGN KEY ( message_id ) REFERENCES edifact_messages ( id ) ON DELETE SET NULL,
3189   CONSTRAINT aqinvoices_fk_shipmentcost_budgetid FOREIGN KEY (shipmentcost_budgetid) REFERENCES aqbudgets (budget_id) ON DELETE SET NULL ON UPDATE CASCADE
3190 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3191
3192 --
3193 -- Table structure for table 'aqinvoice_adjustments'
3194 --
3195
3196 DROP TABLE IF EXISTS aqinvoice_adjustments;
3197 CREATE TABLE aqinvoice_adjustments (
3198     adjustment_id int(11) NOT NULL AUTO_INCREMENT, -- primary key for adjustments
3199     invoiceid int(11) NOT NULL, -- foreign key to link an adjustment to an invoice
3200     adjustment decimal(28,6), -- amount of adjustment
3201     reason varchar(80) default NULL, -- reason for adjustment defined by authorised values in ADJ_REASON category
3202     note mediumtext default NULL, -- text to explain adjustment
3203     budget_id int(11) default NULL, -- optional link to budget to apply adjustment to
3204     encumber_open smallint(1) NOT NULL default 1, -- whether or not to encumber the funds when invoice is still open, 1 = yes, 0 = no
3205     timestamp timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- timestamp  of last adjustment to adjustment
3206     PRIMARY KEY (adjustment_id),
3207     CONSTRAINT aqinvoice_adjustments_fk_invoiceid FOREIGN KEY (invoiceid) REFERENCES aqinvoices (invoiceid) ON DELETE CASCADE ON UPDATE CASCADE,
3208     CONSTRAINT aqinvoice_adjustments_fk_budget_id FOREIGN KEY (budget_id) REFERENCES aqbudgets (budget_id) ON DELETE SET NULL ON UPDATE CASCADE
3209 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3210
3211 --
3212 -- Table structure for table `aqorders`
3213 --
3214
3215 DROP TABLE IF EXISTS `aqorders`;
3216 CREATE TABLE `aqorders` ( -- information related to the basket line items
3217   `ordernumber` int(11) NOT NULL auto_increment, -- primary key and unique identifier assigned by Koha to each line
3218   `biblionumber` int(11) default NULL, -- links the order to the biblio being ordered (biblio.biblionumber)
3219   `entrydate` date default NULL, -- the date the bib was added to the basket
3220   `quantity` smallint(6) default NULL, -- the quantity ordered
3221   `currency` varchar(10) default NULL, -- the currency used for the purchase
3222   `listprice` decimal(28,6) default NULL, -- the vendor price for this line item
3223   `datereceived` date default NULL, -- the date this order was received
3224   invoiceid int(11) default NULL, -- id of invoice
3225   `freight` decimal(28,6) DEFAULT NULL, -- shipping costs (not used)
3226   `unitprice` decimal(28,6) DEFAULT NULL, -- the actual cost entered when receiving this line item
3227   `unitprice_tax_excluded` decimal(28,6) default NULL, -- the unit price excluding tax (on receiving)
3228   `unitprice_tax_included` decimal(28,6) default NULL, -- the unit price including tax (on receiving)
3229   `quantityreceived` smallint(6) NOT NULL default 0, -- the quantity that have been received so far
3230   `created_by` int(11) NULL DEFAULT NULL, -- the borrowernumber of order line's creator
3231   `datecancellationprinted` date default NULL, -- the date the line item was deleted
3232   `cancellationreason` MEDIUMTEXT default NULL, -- reason of cancellation
3233   `order_internalnote` LONGTEXT, -- notes related to this order line, made for staff
3234   `order_vendornote` LONGTEXT, -- notes related to this order line, made for vendor
3235   `purchaseordernumber` LONGTEXT, -- not used? always NULL
3236   `basketno` int(11) default NULL, -- links this order line to a specific basket (aqbasket.basketno)
3237   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- the date and time this order line was last modified
3238   `rrp` decimal(13,2) DEFAULT NULL, -- the retail cost for this line item
3239   `replacementprice` decimal(28,6) DEFAULT NULL, -- the replacement cost for this line item
3240   `rrp_tax_excluded` decimal(28,6) default NULL, -- the replacement cost excluding tax
3241   `rrp_tax_included` decimal(28,6) default NULL, -- the replacement cost including tax
3242   `ecost` decimal(13,2) DEFAULT NULL, -- the replacement cost for this line item
3243   `ecost_tax_excluded` decimal(28,6) default NULL, -- the estimated cost excluding tax
3244   `ecost_tax_included` decimal(28,6) default NULL, -- the estimated cost including tax
3245   `tax_rate_bak` decimal(6,4) DEFAULT NULL, -- the tax rate for this line item (%)
3246   `tax_rate_on_ordering` decimal(6,4) DEFAULT NULL, -- the tax rate on ordering for this line item (%)
3247   `tax_rate_on_receiving` decimal(6,4) DEFAULT NULL, -- the tax rate on receiving for this line item (%)
3248   `tax_value_bak` decimal(28,6) default NULL, -- the tax value for this line item
3249   `tax_value_on_ordering` decimal(28,6) DEFAULT NULL, -- the tax value on ordering for this line item
3250   `tax_value_on_receiving` decimal(28,6) DEFAULT NULL, -- the tax value on receiving for this line item
3251   `discount` float(6,4) default NULL, -- the discount for this line item (%)
3252   `budget_id` int(11) NOT NULL, -- the fund this order goes against (aqbudgets.budget_id)
3253   `budgetdate` date default NULL, -- not used? always NULL
3254   `sort1` varchar(80) default NULL, -- statistical field
3255   `sort2` varchar(80) default NULL, -- second statistical field
3256   `sort1_authcat` varchar(10) default NULL,
3257   `sort2_authcat` varchar(10) default NULL,
3258   `uncertainprice` tinyint(1), -- was this price uncertain (1 for yes, 0 for no)
3259   `subscriptionid` int(11) default NULL, -- links this order line to a subscription (subscription.subscriptionid)
3260   parent_ordernumber int(11) default NULL, -- ordernumber of parent order line, or same as ordernumber if no parent
3261   `orderstatus` varchar(16) default 'new', -- the current status for this line item. Can be 'new', 'ordered', 'partial', 'complete' or 'cancelled'
3262   line_item_id varchar(35) default NULL, -- Supplier's article id for Edifact orderline
3263   suppliers_reference_number varchar(35) default NULL, -- Suppliers unique edifact quote ref
3264   suppliers_reference_qualifier varchar(3) default NULL, -- Type of number above usually 'QLI'
3265   `suppliers_report` MEDIUMTEXT COLLATE utf8mb4_unicode_ci, -- reports received from suppliers
3266   PRIMARY KEY  (`ordernumber`),
3267   KEY `basketno` (`basketno`),
3268   KEY `biblionumber` (`biblionumber`),
3269   KEY `budget_id` (`budget_id`),
3270   KEY `parent_ordernumber` (`parent_ordernumber`),
3271   KEY `orderstatus` (`orderstatus`),
3272   CONSTRAINT aqorders_created_by FOREIGN KEY (created_by) REFERENCES borrowers (borrowernumber) ON DELETE SET NULL ON UPDATE CASCADE,
3273   CONSTRAINT `aqorders_budget_id_fk` FOREIGN KEY (`budget_id`) REFERENCES `aqbudgets` (`budget_id`) ON DELETE CASCADE ON UPDATE CASCADE,
3274   CONSTRAINT `aqorders_ibfk_1` FOREIGN KEY (`basketno`) REFERENCES `aqbasket` (`basketno`) ON DELETE CASCADE ON UPDATE CASCADE,
3275   CONSTRAINT `aqorders_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE,
3276   CONSTRAINT aqorders_ibfk_3 FOREIGN KEY (invoiceid) REFERENCES aqinvoices (invoiceid) ON DELETE SET NULL ON UPDATE CASCADE,
3277   CONSTRAINT `aqorders_subscriptionid` FOREIGN KEY (`subscriptionid`) REFERENCES `subscription` (`subscriptionid`) ON DELETE CASCADE ON UPDATE CASCADE,
3278   CONSTRAINT `aqorders_currency` FOREIGN KEY (`currency`) REFERENCES `currency` (`currency`) ON DELETE SET NULL ON UPDATE SET NULL
3279 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3280
3281 --
3282 -- Table structure for table `aqorder_users`
3283 --
3284
3285 DROP TABLE IF EXISTS `aqorder_users`;
3286 CREATE TABLE aqorder_users ( -- Mapping orders to patrons for notification sending
3287     ordernumber int(11) NOT NULL, -- the order this patrons receive notifications from (aqorders.ordernumber)
3288     borrowernumber int(11) NOT NULL, -- the borrowernumber for the patron receiving notifications for this order (borrowers.borrowernumber)
3289     PRIMARY KEY (ordernumber, borrowernumber),
3290     CONSTRAINT aqorder_users_ibfk_1 FOREIGN KEY (ordernumber) REFERENCES aqorders (ordernumber) ON DELETE CASCADE ON UPDATE CASCADE,
3291     CONSTRAINT aqorder_users_ibfk_2 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE
3292 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3293
3294 --
3295 -- Table structure for table `aqorders_items`
3296 --
3297
3298 DROP TABLE IF EXISTS `aqorders_items`;
3299 CREATE TABLE `aqorders_items` ( -- information on items entered in the acquisitions process
3300   `ordernumber` int(11) NOT NULL, -- the order this item is attached to (aqorders.ordernumber)
3301   `itemnumber` int(11) NOT NULL, -- the item number for this item (items.itemnumber)
3302   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- the date and time this order item was last touched
3303   PRIMARY KEY  (`itemnumber`),
3304   KEY `ordernumber` (`ordernumber`),
3305   CONSTRAINT aqorders_items_ibfk_1 FOREIGN KEY (ordernumber) REFERENCES aqorders (ordernumber) ON DELETE CASCADE ON UPDATE CASCADE
3306 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3307
3308 --
3309 -- Table structure for table aqorders_transfers
3310 --
3311
3312 DROP TABLE IF EXISTS aqorders_transfers;
3313 CREATE TABLE aqorders_transfers (
3314   ordernumber_from int(11) NULL,
3315   ordernumber_to int(11) NULL,
3316   timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
3317   UNIQUE KEY ordernumber_from (ordernumber_from),
3318   UNIQUE KEY ordernumber_to (ordernumber_to),
3319   CONSTRAINT aqorders_transfers_ordernumber_from FOREIGN KEY (ordernumber_from) REFERENCES aqorders (ordernumber) ON DELETE SET NULL ON UPDATE CASCADE,
3320   CONSTRAINT aqorders_transfers_ordernumber_to FOREIGN KEY (ordernumber_to) REFERENCES aqorders (ordernumber) ON DELETE SET NULL ON UPDATE CASCADE
3321 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3322
3323 --
3324 -- Table structure for table aqorders_claims
3325 --
3326
3327 DROP TABLE IF EXISTS aqorders_claims;
3328 CREATE TABLE aqorders_claims (
3329     id int(11) AUTO_INCREMENT, -- ID of the claims
3330     ordernumber INT(11) NOT NULL, -- order linked to this claim
3331     claimed_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Date of the claims
3332     PRIMARY KEY (id),
3333     CONSTRAINT aqorders_claims_ibfk_1 FOREIGN KEY (ordernumber) REFERENCES aqorders (ordernumber) ON DELETE CASCADE ON UPDATE CASCADE
3334 ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
3335
3336 --
3337 -- Table structure for table `transport_cost`
3338 --
3339
3340 DROP TABLE IF EXISTS transport_cost;
3341 CREATE TABLE transport_cost (
3342       frombranch varchar(10) NOT NULL,
3343       tobranch varchar(10) NOT NULL,
3344       cost decimal(6,2) NOT NULL,
3345       disable_transfer tinyint(1) NOT NULL DEFAULT 0,
3346       PRIMARY KEY (frombranch, tobranch),
3347       CONSTRAINT transport_cost_ibfk_1 FOREIGN KEY (frombranch) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE,
3348       CONSTRAINT transport_cost_ibfk_2 FOREIGN KEY (tobranch) REFERENCES branches (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
3349 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3350
3351 --
3352 -- Table structure for table `biblioimages`
3353 --
3354
3355 DROP TABLE IF EXISTS `biblioimages`;
3356
3357 CREATE TABLE `biblioimages` ( -- local cover images
3358  `imagenumber` int(11) NOT NULL AUTO_INCREMENT, -- unique identifier for the image
3359  `biblionumber` int(11) NOT NULL, -- foreign key from biblio table to link to biblionumber
3360  `mimetype` varchar(15) NOT NULL, -- image type
3361  `imagefile` mediumblob NOT NULL, -- image file contents
3362  `thumbnail` mediumblob NOT NULL, -- thumbnail file contents
3363  `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- image creation/update time
3364  PRIMARY KEY (`imagenumber`),
3365  CONSTRAINT `bibliocoverimage_fk1` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
3366 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3367
3368 --
3369 -- Table structure for table `social_data`
3370 --
3371
3372 DROP TABLE IF EXISTS `social_data`;
3373 CREATE TABLE IF NOT EXISTS `social_data` (
3374   `isbn` VARCHAR(30) NOT NULL DEFAULT '',
3375   `num_critics` INT,
3376   `num_critics_pro` INT,
3377   `num_quotations` INT,
3378   `num_videos` INT,
3379   `score_avg` DECIMAL(5,2),
3380   `num_scores` INT,
3381   PRIMARY KEY  (`isbn`)
3382 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3383
3384 --
3385 -- 'Ratings' table. This tracks the star ratings set by borrowers.
3386 --
3387
3388 DROP TABLE IF EXISTS ratings;
3389 CREATE TABLE ratings ( -- information related to the star ratings in the OPAC
3390     borrowernumber int(11) NOT NULL, -- the borrowernumber of the patron who left this rating (borrowers.borrowernumber)
3391     biblionumber int(11) NOT NULL, -- the biblio this rating is for (biblio.biblionumber)
3392     rating_value tinyint(1) NOT NULL, -- the rating, from 1 to 5
3393     timestamp timestamp NOT NULL default CURRENT_TIMESTAMP,
3394     PRIMARY KEY  (borrowernumber,biblionumber),
3395     CONSTRAINT ratings_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE,
3396     CONSTRAINT ratings_ibfk_2 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE CASCADE
3397 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3398
3399 --
3400 -- Table structure for table `quotes`
3401 --
3402
3403 DROP TABLE IF EXISTS quotes;
3404 CREATE TABLE `quotes` ( -- data for the quote of the day feature
3405   `id` int(11) NOT NULL AUTO_INCREMENT, -- unique id for the quote
3406   `source` MEDIUMTEXT DEFAULT NULL, -- source/credit for the quote
3407   `text` LONGTEXT NOT NULL, -- text of the quote
3408   `timestamp` datetime NULL, -- date and time that the quote last appeared in the opac
3409   PRIMARY KEY (`id`)
3410 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3411
3412 --
3413 -- Table structure for table categories_branches
3414 --
3415
3416 DROP TABLE IF EXISTS categories_branches;
3417 CREATE TABLE categories_branches( -- association table between categories and branches
3418     categorycode VARCHAR(10),
3419     branchcode VARCHAR(10),
3420     FOREIGN KEY (categorycode) REFERENCES categories(categorycode) ON DELETE CASCADE,
3421     FOREIGN KEY (branchcode) REFERENCES branches(branchcode) ON DELETE CASCADE
3422 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3423
3424 --
3425 -- Table structure for table authorised_values_branches
3426 --
3427
3428 DROP TABLE IF EXISTS authorised_values_branches;
3429 CREATE TABLE authorised_values_branches( -- association table between authorised_values and branches
3430     av_id INT(11) NOT NULL,
3431     branchcode VARCHAR(10) NOT NULL,
3432     FOREIGN KEY (av_id) REFERENCES authorised_values(id) ON DELETE CASCADE,
3433     FOREIGN KEY (branchcode) REFERENCES branches(branchcode) ON DELETE CASCADE
3434 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3435
3436
3437 --
3438 -- Table structure for table borrower_attribute_types_branches
3439 --
3440
3441 DROP TABLE IF EXISTS borrower_attribute_types_branches;
3442 CREATE TABLE borrower_attribute_types_branches( -- association table between borrower_attribute_types and branches
3443     bat_code VARCHAR(10),
3444     b_branchcode VARCHAR(10),
3445     FOREIGN KEY (bat_code) REFERENCES borrower_attribute_types(code) ON DELETE CASCADE,
3446     FOREIGN KEY (b_branchcode) REFERENCES branches(branchcode) ON DELETE CASCADE
3447 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3448
3449 --
3450 -- Table structure for table `borrower_modifications`
3451 --
3452
3453 CREATE TABLE IF NOT EXISTS `borrower_modifications` (
3454   `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
3455   `verification_token` varchar(255) NOT NULL DEFAULT '',
3456   `changed_fields` MEDIUMTEXT DEFAULT NULL,
3457   `borrowernumber` int(11) NOT NULL DEFAULT '0',
3458   `cardnumber` varchar(32) DEFAULT NULL,
3459   `surname` LONGTEXT,
3460   `firstname` MEDIUMTEXT,
3461   `title` LONGTEXT,
3462   `othernames` LONGTEXT,
3463   `initials` MEDIUMTEXT,
3464   `streetnumber` varchar(10) DEFAULT NULL,
3465   `streettype` varchar(50) DEFAULT NULL,
3466   `address` LONGTEXT,
3467   `address2` MEDIUMTEXT,
3468   `city` LONGTEXT,
3469   `state` MEDIUMTEXT,
3470   `zipcode` varchar(25) DEFAULT NULL,
3471   `country` MEDIUMTEXT,
3472   `email` LONGTEXT,
3473   `phone` MEDIUMTEXT,
3474   `mobile` varchar(50) DEFAULT NULL,
3475   `fax` LONGTEXT,
3476   `emailpro` MEDIUMTEXT,
3477   `phonepro` MEDIUMTEXT,
3478   `B_streetnumber` varchar(10) DEFAULT NULL,
3479   `B_streettype` varchar(50) DEFAULT NULL,
3480   `B_address` varchar(100) DEFAULT NULL,
3481   `B_address2` MEDIUMTEXT,
3482   `B_city` LONGTEXT,
3483   `B_state` MEDIUMTEXT,
3484   `B_zipcode` varchar(25) DEFAULT NULL,
3485   `B_country` MEDIUMTEXT,
3486   `B_email` MEDIUMTEXT,
3487   `B_phone` LONGTEXT,
3488   `dateofbirth` date DEFAULT NULL,
3489   `branchcode` varchar(10) DEFAULT NULL,
3490   `categorycode` varchar(10) DEFAULT NULL,
3491   `dateenrolled` date DEFAULT NULL,
3492   `dateexpiry` date DEFAULT NULL,
3493   `date_renewed` date default NULL,
3494   `gonenoaddress` tinyint(1) DEFAULT NULL,
3495   `lost` tinyint(1) DEFAULT NULL,
3496   `debarred` date DEFAULT NULL,
3497   `debarredcomment` varchar(255) DEFAULT NULL,
3498   `contactname` LONGTEXT,
3499   `contactfirstname` MEDIUMTEXT,
3500   `contacttitle` MEDIUMTEXT,
3501   `borrowernotes` LONGTEXT,
3502   `relationship` varchar(100) DEFAULT NULL,
3503   `sex` varchar(1) DEFAULT NULL,
3504   `password` varchar(30) DEFAULT NULL,
3505   `flags` int(11) DEFAULT NULL,
3506   `userid` varchar(75) DEFAULT NULL,
3507   `opacnote` LONGTEXT,
3508   `contactnote` varchar(255) DEFAULT NULL,
3509   `sort1` varchar(80) DEFAULT NULL,
3510   `sort2` varchar(80) DEFAULT NULL,
3511   `altcontactfirstname` varchar(255) DEFAULT NULL,
3512   `altcontactsurname` varchar(255) DEFAULT NULL,
3513   `altcontactaddress1` varchar(255) DEFAULT NULL,
3514   `altcontactaddress2` varchar(255) DEFAULT NULL,
3515   `altcontactaddress3` varchar(255) DEFAULT NULL,
3516   `altcontactstate` MEDIUMTEXT,
3517   `altcontactzipcode` varchar(50) DEFAULT NULL,
3518   `altcontactcountry` MEDIUMTEXT,
3519   `altcontactphone` varchar(50) DEFAULT NULL,
3520   `smsalertnumber` varchar(50) DEFAULT NULL,
3521   `privacy` int(11) DEFAULT NULL,
3522   `extended_attributes` MEDIUMTEXT DEFAULT NULL,
3523   `gdpr_proc_consent` datetime, -- data processing consent
3524   PRIMARY KEY (`verification_token` (191),`borrowernumber`),
3525   KEY `verification_token` (`verification_token` (191)),
3526   KEY `borrowernumber` (`borrowernumber`)
3527 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3528
3529 --
3530 -- Table structure for table uploaded_files
3531 --
3532
3533 DROP TABLE IF EXISTS uploaded_files;
3534 CREATE TABLE uploaded_files (
3535     id int(11) NOT NULL AUTO_INCREMENT,
3536     hashvalue CHAR(40) NOT NULL,
3537     filename MEDIUMTEXT NOT NULL,
3538     dir MEDIUMTEXT NOT NULL,
3539     filesize int(11),
3540     dtcreated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
3541     uploadcategorycode TEXT,
3542     owner int(11),
3543     public tinyint,
3544     permanent tinyint,
3545     PRIMARY KEY (id)
3546 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3547
3548 --
3549 -- Table structure for table linktracker
3550 -- This stores clicks to external links
3551 --
3552
3553 DROP TABLE IF EXISTS linktracker;
3554 CREATE TABLE linktracker (
3555    id int(11) NOT NULL AUTO_INCREMENT, -- primary key identifier
3556    biblionumber int(11) DEFAULT NULL, -- biblionumber of the record the link is from
3557    itemnumber int(11) DEFAULT NULL, -- itemnumber if applicable that the link was from
3558    borrowernumber int(11) DEFAULT NULL, -- borrowernumber who clicked the link
3559    url MEDIUMTEXT, -- the link itself
3560    timeclicked datetime DEFAULT NULL, -- the date and time the link was clicked
3561    PRIMARY KEY (id),
3562    KEY bibidx (biblionumber),
3563    KEY itemidx (itemnumber),
3564    KEY borridx (borrowernumber),
3565    KEY dateidx (timeclicked)
3566 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3567
3568 --
3569 -- Table structure for table 'plugin_data'
3570 --
3571
3572 CREATE TABLE IF NOT EXISTS plugin_data (
3573   plugin_class varchar(255) NOT NULL,
3574   plugin_key varchar(255) NOT NULL,
3575   plugin_value MEDIUMTEXT,
3576   PRIMARY KEY ( `plugin_class` (191), `plugin_key` (191) )
3577 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3578
3579 --
3580 -- Table structure for table patron_consent
3581 --
3582
3583 DROP TABLE IF EXISTS patron_consent;
3584 CREATE TABLE patron_consent (
3585   id int AUTO_INCREMENT,
3586   borrowernumber int NOT NULL,
3587   type enum('GDPR_PROCESSING' ), -- allows for future extension
3588   given_on datetime,
3589   refused_on datetime,
3590   PRIMARY KEY (id),
3591   FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE
3592 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3593
3594 --
3595 -- Table structure for table 'plugin_methods'
3596 --
3597
3598 DROP TABLE IF EXISTS plugin_methods;
3599 CREATE TABLE plugin_methods (
3600   plugin_class varchar(255) NOT NULL,
3601   plugin_method varchar(255) NOT NULL,
3602   PRIMARY KEY ( `plugin_class` (191), `plugin_method` (191) )
3603 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3604
3605 --
3606 -- Table structure for table `patron_lists`
3607 --
3608
3609 DROP TABLE IF EXISTS patron_lists;
3610 CREATE TABLE patron_lists (
3611   patron_list_id int(11) NOT NULL AUTO_INCREMENT, -- unique identifier
3612   name varchar(255) CHARACTER SET utf8mb4 NOT NULL,  -- the list's name
3613   owner int(11) NOT NULL,                         -- borrowernumber of the list creator
3614   shared tinyint(1) default 0,
3615   PRIMARY KEY (patron_list_id),
3616   KEY owner (owner)
3617 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3618
3619 --
3620 -- Constraints for table `patron_lists`
3621 --
3622 ALTER TABLE `patron_lists`
3623   ADD CONSTRAINT patron_lists_ibfk_1 FOREIGN KEY (`owner`) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE;
3624
3625 --
3626 -- Table structure for table 'patron_list_patrons'
3627 --
3628
3629 DROP TABLE IF EXISTS patron_list_patrons;
3630 CREATE TABLE patron_list_patrons (
3631   patron_list_patron_id int(11) NOT NULL AUTO_INCREMENT, -- unique identifier
3632   patron_list_id int(11) NOT NULL,                       -- the list this entry is part of
3633   borrowernumber int(11) NOT NULL,                       -- the borrower that is part of this list
3634   PRIMARY KEY (patron_list_patron_id),
3635   KEY patron_list_id (patron_list_id),
3636   KEY borrowernumber (borrowernumber)
3637 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3638
3639 --
3640 -- Constraints for table `patron_list_patrons`
3641 --
3642 ALTER TABLE `patron_list_patrons`
3643   ADD CONSTRAINT patron_list_patrons_ibfk_1 FOREIGN KEY (patron_list_id) REFERENCES patron_lists (patron_list_id) ON DELETE CASCADE ON UPDATE CASCADE,
3644   ADD CONSTRAINT patron_list_patrons_ibfk_2 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE;
3645
3646 --
3647 -- Table structure for table 'marc_modification_templates'
3648 --
3649
3650 CREATE TABLE IF NOT EXISTS marc_modification_templates (
3651     template_id int(11) NOT NULL AUTO_INCREMENT,
3652     name MEDIUMTEXT NOT NULL,
3653     PRIMARY KEY (template_id)
3654 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3655
3656 --
3657 -- Table structure for table 'marc_modification_template_actions'
3658 --
3659
3660 CREATE TABLE IF NOT EXISTS marc_modification_template_actions (
3661   mmta_id int(11) NOT NULL AUTO_INCREMENT,
3662   template_id int(11) NOT NULL,
3663   ordering int(3) NOT NULL,
3664   action ENUM('delete_field','add_field','update_field','move_field','copy_field','copy_and_replace_field') NOT NULL,
3665   field_number smallint(6) NOT NULL DEFAULT '0',
3666   from_field varchar(3) NOT NULL,
3667   from_subfield varchar(1) DEFAULT NULL,
3668   field_value varchar(100) DEFAULT NULL,
3669   to_field varchar(3) DEFAULT NULL,
3670   to_subfield varchar(1) DEFAULT NULL,
3671   to_regex_search MEDIUMTEXT,
3672   to_regex_replace MEDIUMTEXT,
3673   to_regex_modifiers varchar(8) DEFAULT '',
3674   conditional enum('if','unless') DEFAULT NULL,
3675   conditional_field varchar(3) DEFAULT NULL,
3676   conditional_subfield varchar(1) DEFAULT NULL,
3677   conditional_comparison enum('exists','not_exists','equals','not_equals') DEFAULT NULL,
3678   conditional_value MEDIUMTEXT,
3679   conditional_regex tinyint(1) NOT NULL DEFAULT '0',
3680   description MEDIUMTEXT,
3681   PRIMARY KEY (mmta_id),
3682   CONSTRAINT `mmta_ibfk_1` FOREIGN KEY (`template_id`) REFERENCES `marc_modification_templates` (`template_id`) ON DELETE CASCADE ON UPDATE CASCADE
3683 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3684
3685 --
3686 -- Table structure for table `misc_files`
3687 --
3688
3689 CREATE TABLE IF NOT EXISTS `misc_files` ( -- miscellaneous files attached to records from various tables
3690   `file_id` int(11) NOT NULL AUTO_INCREMENT, -- unique id for the file record
3691   `table_tag` varchar(255) NOT NULL, -- usually table name, or arbitrary unique tag
3692   `record_id` int(11) NOT NULL, -- record id from the table this file is associated to
3693   `file_name` varchar(255) NOT NULL, -- file name
3694   `file_type` varchar(255) NOT NULL, -- MIME type of the file
3695   `file_description` varchar(255) DEFAULT NULL, -- description given to the file
3696   `file_content` longblob NOT NULL, -- file content
3697   `date_uploaded` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- date and time the file was added
3698   PRIMARY KEY (`file_id`),
3699   KEY `table_tag` (`table_tag`),
3700   KEY `record_id` (`record_id`)
3701 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3702
3703 --
3704 -- Table structure for table `columns_settings`
3705 --
3706
3707 CREATE TABLE IF NOT EXISTS columns_settings (
3708     module varchar(255) NOT NULL,
3709     page varchar(255) NOT NULL,
3710     tablename varchar(255) NOT NULL,
3711     columnname varchar(255) NOT NULL,
3712     cannot_be_toggled int(1) NOT NULL DEFAULT 0,
3713     is_hidden int(1) NOT NULL DEFAULT 0,
3714     PRIMARY KEY(module (191), page (191), tablename (191), columnname (191))
3715 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3716
3717 --
3718 -- Table structure for table `tables_settings`
3719 --
3720
3721 CREATE TABLE IF NOT EXISTS tables_settings (
3722     module varchar(255) NOT NULL,
3723     page varchar(255) NOT NULL,
3724     tablename varchar(255) NOT NULL,
3725     default_display_length smallint(6) NOT NULL DEFAULT 20 ,
3726     default_sort_order varchar(255),
3727     PRIMARY KEY(module (191), page (191), tablename (191) )
3728 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3729
3730 --
3731 -- Table structure for table 'items_search_fields'
3732 --
3733
3734 DROP TABLE IF EXISTS items_search_fields;
3735 CREATE TABLE items_search_fields (
3736   name VARCHAR(255) NOT NULL,
3737   label VARCHAR(255) NOT NULL,
3738   tagfield CHAR(3) NOT NULL,
3739   tagsubfield CHAR(1) NULL DEFAULT NULL,
3740   authorised_values_category VARCHAR(32) NULL DEFAULT NULL,
3741   PRIMARY KEY(name (191)),
3742   CONSTRAINT items_search_fields_authorised_values_category
3743     FOREIGN KEY (authorised_values_category) REFERENCES authorised_value_categories (category_name)
3744     ON DELETE SET NULL ON UPDATE CASCADE
3745 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3746
3747 --
3748 -- Table structure for table 'discharges'
3749 --
3750
3751 DROP TABLE IF EXISTS discharges;
3752 CREATE TABLE discharges (
3753   discharge_id int(11) NOT NULL AUTO_INCREMENT,
3754   borrower int(11) DEFAULT NULL,
3755   needed timestamp NULL DEFAULT NULL,
3756   validated timestamp NULL DEFAULT NULL,
3757   PRIMARY KEY (discharge_id),
3758   KEY borrower_discharges_ibfk1 (borrower),
3759   CONSTRAINT borrower_discharges_ibfk1 FOREIGN KEY (borrower) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE
3760 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3761
3762 --
3763 -- Table structure for table additional_fields
3764 -- This table add the ability to add new fields for a record
3765 --
3766
3767 DROP TABLE IF EXISTS additional_fields;
3768 CREATE TABLE `additional_fields` (
3769   `id` int(11) NOT NULL AUTO_INCREMENT, -- primary key identifier
3770   `tablename` varchar(255) NOT NULL DEFAULT '', -- tablename of the new field
3771   `name` varchar(255) NOT NULL DEFAULT '', -- name of the field
3772   `authorised_value_category` varchar(16) NOT NULL DEFAULT '', -- is an authorised value category
3773   `marcfield` varchar(16) NOT NULL DEFAULT '', -- contains the marc field to copied into the record
3774   `searchable` tinyint(1) NOT NULL DEFAULT '0', -- is the field searchable?
3775   PRIMARY KEY (`id`),
3776   UNIQUE KEY `fields_uniq` (`tablename` (191),`name` (191))
3777 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3778
3779 --
3780 -- Table structure for table additional_field_values
3781 -- This table store values for additional fields
3782 --
3783
3784 DROP TABLE IF EXISTS additional_field_values;
3785 CREATE TABLE `additional_field_values` (
3786   `id` int(11) NOT NULL AUTO_INCREMENT, -- primary key identifier
3787   `field_id` int(11) NOT NULL, -- foreign key references additional_fields(id)
3788   `record_id` int(11) NOT NULL, -- record_id
3789   `value` varchar(255) NOT NULL DEFAULT '', -- value for this field
3790   PRIMARY KEY (`id`),
3791   UNIQUE KEY `field_record` (`field_id`,`record_id`),
3792   CONSTRAINT `afv_fk` FOREIGN KEY (`field_id`) REFERENCES `additional_fields` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
3793 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3794
3795 --
3796 -- Table structure for table 'localization'
3797 --
3798
3799 DROP TABLE IF EXISTS localization;
3800 CREATE TABLE `localization` (
3801       localization_id int(11) NOT NULL AUTO_INCREMENT,
3802       entity varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL,
3803       code varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
3804       lang varchar(25) COLLATE utf8mb4_unicode_ci NOT NULL, -- could be a foreign key
3805       translation MEDIUMTEXT COLLATE utf8mb4_unicode_ci,
3806       PRIMARY KEY (localization_id),
3807       UNIQUE KEY `entity_code_lang` (`entity`,`code`,`lang`)
3808 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3809
3810 --
3811 -- Table structure for table 'audio_alerts'
3812 --
3813
3814 DROP TABLE IF EXISTS audio_alerts;
3815 CREATE TABLE audio_alerts (
3816   id int(11) NOT NULL AUTO_INCREMENT,
3817   precedence smallint(5) unsigned NOT NULL,
3818   selector varchar(255) NOT NULL,
3819   sound varchar(255) NOT NULL,
3820   PRIMARY KEY (id),
3821   KEY precedence (precedence)
3822 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3823
3824 --
3825 -- Table structure for table 'edifact_ean'
3826 --
3827
3828 DROP TABLE IF EXISTS edifact_ean;
3829 CREATE TABLE IF NOT EXISTS edifact_ean (
3830   ee_id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
3831   description VARCHAR(128) NULL DEFAULT NULL,
3832   branchcode VARCHAR(10) NULL DEFAULT NULL REFERENCES branches (branchcode),
3833   ean VARCHAR(15) NOT NULL,
3834   id_code_qualifier VARCHAR(3) NOT NULL DEFAULT '14',
3835   CONSTRAINT efk_branchcode FOREIGN KEY ( branchcode ) REFERENCES branches ( branchcode )
3836 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3837
3838 --
3839 -- Table structure for table `courses`
3840 --
3841
3842 -- The courses table stores the courses created for the
3843 -- course reserves feature.
3844
3845 DROP TABLE IF EXISTS courses;
3846 CREATE TABLE `courses` (
3847   `course_id` int(11) NOT NULL AUTO_INCREMENT, -- unique id for the course
3848   `department` varchar(80) DEFAULT NULL, -- the authorised value for the DEPARTMENT
3849   `course_number` varchar(255) DEFAULT NULL, -- the "course number" assigned to a course
3850   `section` varchar(255) DEFAULT NULL, -- the 'section' of a course
3851   `course_name` varchar(255) DEFAULT NULL, -- the name of the course
3852   `term` varchar(80) DEFAULT NULL, -- the authorised value for the TERM
3853   `staff_note` LONGTEXT, -- the text of the staff only note
3854   `public_note` LONGTEXT, -- the text of the public / opac note
3855   `students_count` varchar(20) DEFAULT NULL, -- how many students will be taking this course/section
3856   `enabled` enum('yes','no') NOT NULL DEFAULT 'yes', -- determines whether the course is active
3857   `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
3858    PRIMARY KEY (`course_id`)
3859 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3860
3861 --
3862 -- Table structure for table `course_instructors`
3863 --
3864
3865 -- The course instructors table links Koha borrowers to the
3866 -- courses they are teaching. Many instructors can teach many
3867 -- courses. course_instructors is just a many-to-many join table.
3868
3869 DROP TABLE IF EXISTS course_instructors;
3870 CREATE TABLE `course_instructors` (
3871   `course_id` int(11) NOT NULL, -- foreign key to link to courses.course_id
3872   `borrowernumber` int(11) NOT NULL, -- foreign key to link to borrowers.borrowernumber for instructor information
3873   PRIMARY KEY (`course_id`,`borrowernumber`),
3874   KEY `borrowernumber` (`borrowernumber`)
3875 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3876
3877 --
3878 -- Constraints for table `course_instructors`
3879 --
3880 ALTER TABLE `course_instructors`
3881   ADD CONSTRAINT `course_instructors_ibfk_2` FOREIGN KEY (`course_id`) REFERENCES `courses` (`course_id`),
3882   ADD CONSTRAINT `course_instructors_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE;
3883
3884 --
3885 -- Table structure for table `course_items`
3886 --
3887
3888 -- If an item is placed on course reserve for one or more courses
3889 -- it will have an entry in this table. No matter how many courses an item
3890 -- is part of, it will only have one row in this table.
3891
3892 DROP TABLE IF EXISTS course_items;
3893 CREATE TABLE `course_items` (
3894   `ci_id` int(11) NOT NULL AUTO_INCREMENT, -- course item id
3895   `itemnumber` int(11) NOT NULL, -- items.itemnumber for the item on reserve
3896   `itype` varchar(10) DEFAULT NULL, -- new itemtype for the item to have while on reserve (optional)
3897   `itype_enabled` tinyint(1) NOT NULL DEFAULT 0, -- indicates if itype should be changed while on course reserve
3898   `itype_storage` varchar(10) DEFAULT NULL, -- a place to store the itype when item is on course reserve
3899   `ccode` varchar(80) DEFAULT NULL, -- new category code for the item to have while on reserve (optional)
3900   `ccode_enabled` tinyint(1) NOT NULL DEFAULT 0, -- indicates if ccode should be changed while on course reserve
3901   `ccode_storage` varchar(80) DEFAULT NULL, -- a place to store the ccode when item is on course reserve
3902   `homebranch` varchar(10) DEFAULT NULL, -- new home branch for the item to have while on reserve (optional)
3903   `homebranch_enabled` tinyint(1) NOT NULL DEFAULT 0, -- indicates if homebranch should be changed while on course reserve
3904   `homebranch_storage` varchar(10) DEFAULT NULL, -- a place to store the homebranch when item is on course reserve
3905   `holdingbranch` varchar(10) DEFAULT NULL, -- new holding branch for the item to have while on reserve (optional)
3906   `holdingbranch_enabled` tinyint(1) NOT NULL DEFAULT 0, -- indicates if itype should be changed while on course reserve
3907   `holdingbranch_storage` varchar(10) DEFAULT NULL, -- a place to store the holdingbranch when item is on course reserve
3908   `location` varchar(80) DEFAULT NULL, -- new shelving location for the item to have while on reseve (optional)
3909   `location_enabled` tinyint(1) NOT NULL DEFAULT 0, -- indicates if itype should be changed while on course reserve
3910   `location_storage` varchar(80) DEFAULT NULL, -- a place to store the location when the item is on course reserve
3911   `enabled` enum('yes','no') NOT NULL DEFAULT 'no', -- if at least one enabled course has this item on reseve, this field will be 'yes', otherwise it will be 'no'
3912   `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
3913    PRIMARY KEY (`ci_id`),
3914    UNIQUE KEY `itemnumber` (`itemnumber`),
3915    KEY `holdingbranch` (`holdingbranch`)
3916 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3917
3918 --
3919 -- Constraints for table `course_items`
3920 --
3921 ALTER TABLE `course_items`
3922   ADD CONSTRAINT `course_items_ibfk_2` FOREIGN KEY (`holdingbranch`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE,
3923   ADD CONSTRAINT `course_items_ibfk_1` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
3924   ADD CONSTRAINT fk_course_items_homebranch FOREIGN KEY (homebranch) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE,
3925   ADD CONSTRAINT fk_course_items_homebranch_storage FOREIGN KEY (homebranch_storage) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE;
3926
3927 --
3928 -- Table structure for table `course_reserves`
3929 --
3930
3931 -- This table connects an item placed on course reserve to a course it is on reserve for.
3932 -- There will be a row in this table for each course an item is on reserve for.
3933
3934 DROP TABLE IF EXISTS course_reserves;
3935 CREATE TABLE `course_reserves` (
3936   `cr_id` int(11) NOT NULL AUTO_INCREMENT,
3937   `course_id` int(11) NOT NULL, -- foreign key to link to courses.course_id
3938   `ci_id` int(11) NOT NULL, -- foreign key to link to courses_items.ci_id
3939   `staff_note` LONGTEXT, -- staff only note
3940   `public_note` LONGTEXT, -- public, OPAC visible note
3941   `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
3942    PRIMARY KEY (`cr_id`),
3943    UNIQUE KEY `pseudo_key` (`course_id`,`ci_id`),
3944    KEY `course_id` (`course_id`)
3945 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3946
3947 --
3948 -- Constraints for table `course_reserves`
3949 --
3950 ALTER TABLE `course_reserves`
3951   ADD CONSTRAINT `course_reserves_ibfk_1` FOREIGN KEY (`course_id`) REFERENCES `courses` (`course_id`),
3952   ADD CONSTRAINT `course_reserves_ibfk_2` FOREIGN KEY (`ci_id`) REFERENCES `course_items` (`ci_id`) ON DELETE CASCADE ON UPDATE CASCADE;
3953
3954 --
3955 -- Table structure for table `hold_fill_targets`
3956 --
3957
3958 DROP TABLE IF EXISTS `hold_fill_targets`;
3959 CREATE TABLE `hold_fill_targets` (
3960   `borrowernumber` int(11) NOT NULL,
3961   `biblionumber` int(11) NOT NULL,
3962   `itemnumber` int(11) NOT NULL,
3963   `source_branchcode`  varchar(10) default NULL,
3964   `item_level_request` tinyint(4) NOT NULL default 0,
3965   PRIMARY KEY `itemnumber` (`itemnumber`),
3966   KEY `bib_branch` (`biblionumber`, `source_branchcode`),
3967   CONSTRAINT `hold_fill_targets_ibfk_1` FOREIGN KEY (`borrowernumber`)
3968     REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
3969   CONSTRAINT `hold_fill_targets_ibfk_2` FOREIGN KEY (`biblionumber`)
3970     REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE,
3971   CONSTRAINT `hold_fill_targets_ibfk_3` FOREIGN KEY (`itemnumber`)
3972     REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
3973   CONSTRAINT `hold_fill_targets_ibfk_4` FOREIGN KEY (`source_branchcode`)
3974     REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
3975 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3976
3977 --
3978 -- Table structure for table `housebound_profile`
3979 --
3980
3981 DROP TABLE IF EXISTS `housebound_profile`;
3982 CREATE TABLE `housebound_profile` (
3983   `borrowernumber` int(11) NOT NULL, -- Number of the borrower associated with this profile.
3984   `day` MEDIUMTEXT NOT NULL,  -- The preferred day of the week for delivery.
3985   `frequency` MEDIUMTEXT NOT NULL, -- The Authorised_Value definining the pattern for delivery.
3986   `fav_itemtypes` MEDIUMTEXT default NULL, -- Free text describing preferred itemtypes.
3987   `fav_subjects` MEDIUMTEXT default NULL, -- Free text describing preferred subjects.
3988   `fav_authors` MEDIUMTEXT default NULL, -- Free text describing preferred authors.
3989   `referral` MEDIUMTEXT default NULL, -- Free text indicating how the borrower was added to the service.
3990   `notes` MEDIUMTEXT default NULL, -- Free text for additional notes.
3991   PRIMARY KEY  (`borrowernumber`),
3992   CONSTRAINT `housebound_profile_bnfk`
3993     FOREIGN KEY (`borrowernumber`)
3994     REFERENCES `borrowers` (`borrowernumber`)
3995     ON UPDATE CASCADE ON DELETE CASCADE
3996 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3997
3998 --
3999 -- Table structure for table `housebound_visit`
4000 --
4001
4002 DROP TABLE IF EXISTS `housebound_visit`;
4003 CREATE TABLE `housebound_visit` (
4004   `id` int(11) NOT NULL auto_increment, -- ID of the visit.
4005   `borrowernumber` int(11) NOT NULL, -- Number of the borrower, & the profile, linked to this visit.
4006   `appointment_date` date default NULL, -- Date of visit.
4007   `day_segment` varchar(10),  -- Rough time frame: 'morning', 'afternoon' 'evening'
4008   `chooser_brwnumber` int(11) default NULL, -- Number of the borrower to choose items  for delivery.
4009   `deliverer_brwnumber` int(11) default NULL, -- Number of the borrower to deliver items.
4010   PRIMARY KEY  (`id`),
4011   CONSTRAINT `houseboundvisit_bnfk`
4012     FOREIGN KEY (`borrowernumber`)
4013     REFERENCES `housebound_profile` (`borrowernumber`)
4014     ON UPDATE CASCADE ON DELETE CASCADE,
4015   CONSTRAINT `houseboundvisit_bnfk_1`
4016     FOREIGN KEY (`chooser_brwnumber`)
4017     REFERENCES `borrowers` (`borrowernumber`)
4018     ON UPDATE CASCADE ON DELETE CASCADE,
4019   CONSTRAINT `houseboundvisit_bnfk_2`
4020     FOREIGN KEY (`deliverer_brwnumber`)
4021     REFERENCES `borrowers` (`borrowernumber`)
4022     ON UPDATE CASCADE ON DELETE CASCADE
4023 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4024
4025 --
4026 -- Table structure for table `housebound_role`
4027 --
4028
4029 DROP TABLE IF EXISTS `housebound_role`;
4030 CREATE TABLE IF NOT EXISTS `housebound_role` (
4031   `borrowernumber_id` int(11) NOT NULL, -- borrowernumber link
4032   `housebound_chooser` tinyint(1) NOT NULL DEFAULT 0, -- set to 1 to indicate this patron is a housebound chooser volunteer
4033   `housebound_deliverer` tinyint(1) NOT NULL DEFAULT 0, -- set to 1 to indicate this patron is a housebound deliverer volunteer
4034   PRIMARY KEY (`borrowernumber_id`),
4035   CONSTRAINT `houseboundrole_bnfk`
4036     FOREIGN KEY (`borrowernumber_id`)
4037     REFERENCES `borrowers` (`borrowernumber`)
4038     ON UPDATE CASCADE ON DELETE CASCADE
4039 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4040
4041 --
4042 -- Table structure for table 'article_requests'
4043 --
4044
4045 DROP TABLE IF EXISTS `article_requests`;
4046 CREATE TABLE `article_requests` (
4047   `id` int(11) NOT NULL AUTO_INCREMENT,
4048   `borrowernumber` int(11) NOT NULL,
4049   `biblionumber` int(11) NOT NULL,
4050   `itemnumber` int(11) DEFAULT NULL,
4051   `branchcode` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
4052   `title` MEDIUMTEXT,
4053   `author` MEDIUMTEXT,
4054   `volume` MEDIUMTEXT,
4055   `issue` MEDIUMTEXT,
4056   `date` MEDIUMTEXT,
4057   `pages` MEDIUMTEXT,
4058   `chapters` MEDIUMTEXT,
4059   `patron_notes` MEDIUMTEXT,
4060   `status` enum('PENDING','PROCESSING','COMPLETED','CANCELED') NOT NULL DEFAULT 'PENDING',
4061   `notes` MEDIUMTEXT,
4062   `created_on` timestamp NULL DEFAULT NULL, -- Be careful with two timestamps in one table not allowing NULL
4063   `updated_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
4064   PRIMARY KEY (`id`),
4065   KEY `borrowernumber` (`borrowernumber`),
4066   KEY `biblionumber` (`biblionumber`),
4067   KEY `itemnumber` (`itemnumber`),
4068   KEY `branchcode` (`branchcode`),
4069   CONSTRAINT `article_requests_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
4070   CONSTRAINT `article_requests_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE,
4071   CONSTRAINT `article_requests_ibfk_3` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE SET NULL ON UPDATE CASCADE,
4072   CONSTRAINT `article_requests_ibfk_4` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE
4073 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4074
4075 --
4076 -- Table structure for table `biblio_metadata`
4077 --
4078
4079 DROP TABLE IF EXISTS `biblio_metadata`;
4080 CREATE TABLE biblio_metadata (
4081     `id` INT(11) NOT NULL AUTO_INCREMENT,
4082     `biblionumber` INT(11) NOT NULL,
4083     `format` VARCHAR(16) NOT NULL,
4084     `schema` VARCHAR(16) NOT NULL,
4085     `metadata` LONGTEXT NOT NULL,
4086     `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
4087     PRIMARY KEY(id),
4088     UNIQUE KEY `biblio_metadata_uniq_key` (`biblionumber`,`format`,`schema`),
4089     CONSTRAINT `record_metadata_fk_1` FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE CASCADE,
4090     KEY `timestamp` (`timestamp`)
4091 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4092
4093 --
4094 -- Table structure for table `deletedbiblio_metadata`
4095 --
4096
4097 DROP TABLE IF EXISTS `deletedbiblio_metadata`;
4098 CREATE TABLE deletedbiblio_metadata (
4099     `id` INT(11) NOT NULL AUTO_INCREMENT,
4100     `biblionumber` INT(11) NOT NULL,
4101     `format` VARCHAR(16) NOT NULL,
4102     `schema` VARCHAR(16) NOT NULL,
4103     `metadata` LONGTEXT NOT NULL,
4104     `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
4105     PRIMARY KEY(id),
4106     UNIQUE KEY `deletedbiblio_metadata_uniq_key` (`biblionumber`,`format`,`schema`),
4107     CONSTRAINT `deletedrecord_metadata_fk_1` FOREIGN KEY (biblionumber) REFERENCES deletedbiblio (biblionumber) ON DELETE CASCADE ON UPDATE CASCADE,
4108     KEY `timestamp` (`timestamp`)
4109 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4110
4111 --
4112 -- Table structure for table 'club_templates'
4113 --
4114
4115 CREATE TABLE IF NOT EXISTS club_templates (
4116   id int(11) NOT NULL AUTO_INCREMENT,
4117   `name` TEXT NOT NULL,
4118   description MEDIUMTEXT,
4119   is_enrollable_from_opac tinyint(1) NOT NULL DEFAULT '0',
4120   is_email_required tinyint(1) NOT NULL DEFAULT '0',
4121   branchcode varchar(10) NULL DEFAULT NULL,
4122   date_created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
4123   date_updated timestamp NULL DEFAULT NULL,
4124   is_deletable tinyint(1) NOT NULL DEFAULT '1',
4125   PRIMARY KEY (id),
4126   KEY ct_branchcode (branchcode),
4127   CONSTRAINT `club_templates_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
4128 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4129
4130 --
4131 -- Table structure for table 'clubs'
4132 --
4133
4134 CREATE TABLE IF NOT EXISTS clubs (
4135   id int(11) NOT NULL AUTO_INCREMENT,
4136   club_template_id int(11) NOT NULL,
4137   `name` TEXT NOT NULL,
4138   description MEDIUMTEXT,
4139   date_start date DEFAULT NULL,
4140   date_end date DEFAULT NULL,
4141   branchcode varchar(10) NULL DEFAULT NULL,
4142   date_created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
4143   date_updated timestamp NULL DEFAULT NULL,
4144   PRIMARY KEY (id),
4145   KEY club_template_id (club_template_id),
4146   KEY branchcode (branchcode),
4147   CONSTRAINT clubs_ibfk_1 FOREIGN KEY (club_template_id) REFERENCES club_templates (id) ON DELETE CASCADE ON UPDATE CASCADE,
4148   CONSTRAINT clubs_ibfk_2 FOREIGN KEY (branchcode) REFERENCES branches (branchcode)
4149 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4150
4151 --
4152 -- Table structure for table 'club_holds'
4153 --
4154
4155 CREATE TABLE IF NOT EXISTS club_holds (
4156     id        INT(11) NOT NULL AUTO_INCREMENT,
4157     club_id   INT(11) NOT NULL, -- id for the club the hold was generated for
4158     biblio_id INT(11) NOT NULL, -- id for the bibliographic record the hold has been placed against
4159     item_id   INT(11) NULL DEFAULT NULL, -- If item-level, the id for the item the hold has been placed agains
4160     date_created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Timestamp for the placed hold
4161     PRIMARY KEY (id),
4162     -- KEY club_id (club_id),
4163     CONSTRAINT clubs_holds_ibfk_1 FOREIGN KEY (club_id)   REFERENCES clubs  (id) ON DELETE CASCADE ON UPDATE CASCADE,
4164     CONSTRAINT clubs_holds_ibfk_2 FOREIGN KEY (biblio_id) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE CASCADE,
4165     CONSTRAINT clubs_holds_ibfk_3 FOREIGN KEY (item_id)   REFERENCES items  (itemnumber) ON DELETE CASCADE ON UPDATE CASCADE
4166 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4167
4168 --
4169 -- Table structure for table 'club_holds_to_patron_holds'
4170 --
4171
4172 CREATE TABLE IF NOT EXISTS club_holds_to_patron_holds (
4173     id              INT(11) NOT NULL AUTO_INCREMENT,
4174     club_hold_id    INT(11) NOT NULL,
4175     patron_id       INT(11) NOT NULL,
4176     hold_id         INT(11),
4177     error_code      ENUM ( 'damaged', 'ageRestricted', 'itemAlreadyOnHold',
4178                         'tooManyHoldsForThisRecord', 'tooManyReservesToday',
4179                         'tooManyReserves', 'notReservable', 'cannotReserveFromOtherBranches',
4180                         'libraryNotFound', 'libraryNotPickupLocation', 'cannotBeTransferred'
4181                     ) NULL DEFAULT NULL,
4182     error_message   varchar(100) NULL DEFAULT NULL,
4183     PRIMARY KEY (id),
4184     -- KEY club_hold_id (club_hold_id),
4185     CONSTRAINT clubs_holds_paton_holds_ibfk_1 FOREIGN KEY (club_hold_id) REFERENCES club_holds (id) ON DELETE CASCADE ON UPDATE CASCADE,
4186     CONSTRAINT clubs_holds_paton_holds_ibfk_2 FOREIGN KEY (patron_id) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE,
4187     CONSTRAINT clubs_holds_paton_holds_ibfk_3 FOREIGN KEY (hold_id) REFERENCES reserves (reserve_id) ON DELETE CASCADE ON UPDATE CASCADE
4188 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4189
4190 --
4191 -- Table structure for table 'club_enrollments'
4192 --
4193
4194 CREATE TABLE IF NOT EXISTS club_enrollments (
4195   id int(11) NOT NULL AUTO_INCREMENT,
4196   club_id int(11) NOT NULL,
4197   borrowernumber int(11) NOT NULL,
4198   date_enrolled timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
4199   date_canceled timestamp NULL DEFAULT NULL,
4200   date_created timestamp NULL DEFAULT NULL,
4201   date_updated timestamp NULL DEFAULT NULL,
4202   branchcode varchar(10) NULL DEFAULT NULL,
4203   PRIMARY KEY (id),
4204   KEY club_id (club_id),
4205   KEY borrowernumber (borrowernumber),
4206   KEY branchcode (branchcode),
4207   CONSTRAINT club_enrollments_ibfk_1 FOREIGN KEY (club_id) REFERENCES clubs (id) ON DELETE CASCADE ON UPDATE CASCADE,
4208   CONSTRAINT club_enrollments_ibfk_2 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE,
4209   CONSTRAINT club_enrollments_ibfk_3 FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE SET NULL ON UPDATE CASCADE
4210 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4211
4212 --
4213 -- Table structure for table 'club_template_enrollment_fields'
4214 --
4215
4216 CREATE TABLE IF NOT EXISTS club_template_enrollment_fields (
4217   id int(11) NOT NULL AUTO_INCREMENT,
4218   club_template_id int(11) NOT NULL,
4219   `name` TEXT NOT NULL,
4220   description MEDIUMTEXT,
4221   authorised_value_category varchar(16) DEFAULT NULL,
4222   PRIMARY KEY (id),
4223   KEY club_template_id (club_template_id),
4224   CONSTRAINT club_template_enrollment_fields_ibfk_1 FOREIGN KEY (club_template_id) REFERENCES club_templates (id) ON DELETE CASCADE ON UPDATE CASCADE
4225 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4226
4227 --
4228 -- Table structure for table 'club_enrollment_fields'
4229 --
4230
4231 CREATE TABLE IF NOT EXISTS club_enrollment_fields (
4232   id int(11) NOT NULL AUTO_INCREMENT,
4233   club_enrollment_id int(11) NOT NULL,
4234   club_template_enrollment_field_id int(11) NOT NULL,
4235   `value` MEDIUMTEXT NOT NULL,
4236   PRIMARY KEY (id),
4237   KEY club_enrollment_id (club_enrollment_id),
4238   KEY club_template_enrollment_field_id (club_template_enrollment_field_id),
4239   CONSTRAINT club_enrollment_fields_ibfk_1 FOREIGN KEY (club_enrollment_id) REFERENCES club_enrollments (id) ON DELETE CASCADE ON UPDATE CASCADE,
4240   CONSTRAINT club_enrollment_fields_ibfk_2 FOREIGN KEY (club_template_enrollment_field_id) REFERENCES club_template_enrollment_fields (id) ON DELETE CASCADE ON UPDATE CASCADE
4241 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4242
4243 --
4244 -- Table structure for table 'club_template_fields'
4245 --
4246
4247 CREATE TABLE IF NOT EXISTS club_template_fields (
4248   id int(11) NOT NULL AUTO_INCREMENT,
4249   club_template_id int(11) NOT NULL,
4250   `name` TEXT NOT NULL,
4251   description MEDIUMTEXT,
4252   authorised_value_category varchar(16) DEFAULT NULL,
4253   PRIMARY KEY (id),
4254   KEY club_template_id (club_template_id),
4255   CONSTRAINT club_template_fields_ibfk_1 FOREIGN KEY (club_template_id) REFERENCES club_templates (id) ON DELETE CASCADE ON UPDATE CASCADE
4256 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4257
4258 --
4259 -- Table structure for table 'club_fields'
4260 --
4261
4262 CREATE TABLE IF NOT EXISTS club_fields (
4263   id int(11) NOT NULL AUTO_INCREMENT,
4264   club_template_field_id int(11) NOT NULL,
4265   club_id int(11) NOT NULL,
4266   `value` MEDIUMTEXT,
4267   PRIMARY KEY (id),
4268   KEY club_template_field_id (club_template_field_id),
4269   KEY club_id (club_id),
4270   CONSTRAINT club_fields_ibfk_3 FOREIGN KEY (club_template_field_id) REFERENCES club_template_fields (id) ON DELETE CASCADE ON UPDATE CASCADE,
4271   CONSTRAINT club_fields_ibfk_4 FOREIGN KEY (club_id) REFERENCES clubs (id) ON DELETE CASCADE ON UPDATE CASCADE
4272 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4273
4274 --
4275 -- Table structure for table 'guarantors_guarantees'
4276 --
4277
4278 DROP TABLE IF EXISTS borrower_relationships;
4279 CREATE TABLE `borrower_relationships` (
4280       id INT(11) NOT NULL AUTO_INCREMENT,
4281       guarantor_id INT(11) NULL DEFAULT NULL,
4282       guarantee_id INT(11) NOT NULL,
4283       relationship VARCHAR(100) NOT NULL,
4284       PRIMARY KEY (id),
4285       UNIQUE KEY `guarantor_guarantee_idx` ( `guarantor_id`, `guarantee_id` ),
4286       CONSTRAINT r_guarantor FOREIGN KEY ( guarantor_id ) REFERENCES borrowers ( borrowernumber ) ON UPDATE CASCADE ON DELETE CASCADE,
4287       CONSTRAINT r_guarantee FOREIGN KEY ( guarantee_id ) REFERENCES borrowers ( borrowernumber ) ON UPDATE CASCADE ON DELETE CASCADE
4288 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4289
4290 --
4291 -- Table structure for table `illrequests`
4292 --
4293
4294 DROP TABLE IF EXISTS `illrequests`;
4295 CREATE TABLE illrequests (
4296     illrequest_id serial PRIMARY KEY,           -- ILL request number
4297     borrowernumber integer DEFAULT NULL,        -- Patron associated with request
4298     biblio_id integer DEFAULT NULL,             -- Potential bib linked to request
4299     branchcode varchar(50) NOT NULL,            -- The branch associated with the request
4300     status varchar(50) DEFAULT NULL,            -- Current Koha status of request
4301     status_alias varchar(80) DEFAULT NULL,      -- Foreign key to relevant authorised_values.authorised_value
4302     placed date DEFAULT NULL,                   -- Date the request was placed
4303     replied date DEFAULT NULL,                  -- Last API response
4304     updated timestamp DEFAULT CURRENT_TIMESTAMP -- Last modification to request
4305       ON UPDATE CURRENT_TIMESTAMP,
4306     completed date DEFAULT NULL,                -- Date the request was completed
4307     medium varchar(30) DEFAULT NULL,            -- The Koha request type
4308     accessurl varchar(500) DEFAULT NULL,        -- Potential URL for accessing item
4309     cost varchar(20) DEFAULT NULL,              -- Quotes cost of request
4310     price_paid varchar(20) DEFAULT NULL,              -- Final cost of request
4311     notesopac MEDIUMTEXT DEFAULT NULL,                -- Patron notes attached to request
4312     notesstaff MEDIUMTEXT DEFAULT NULL,               -- Staff notes attached to request
4313     orderid varchar(50) DEFAULT NULL,           -- Backend id attached to request
4314     backend varchar(20) DEFAULT NULL,           -- The backend used to create request
4315     CONSTRAINT `illrequests_bnfk`
4316       FOREIGN KEY (`borrowernumber`)
4317       REFERENCES `borrowers` (`borrowernumber`)
4318       ON UPDATE CASCADE ON DELETE CASCADE,
4319     CONSTRAINT `illrequests_bcfk_2`
4320       FOREIGN KEY (`branchcode`)
4321       REFERENCES `branches` (`branchcode`)
4322       ON UPDATE CASCADE ON DELETE CASCADE,
4323     CONSTRAINT `illrequests_safk`
4324       FOREIGN KEY (`status_alias`)
4325       REFERENCES `authorised_values` (`authorised_value`)
4326       ON UPDATE CASCADE ON DELETE SET NULL
4327 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4328
4329 --
4330 -- Table structure for table `illrequestattributes`
4331 --
4332
4333 DROP TABLE IF EXISTS `illrequestattributes`;
4334 CREATE TABLE illrequestattributes (
4335     illrequest_id bigint(20) unsigned NOT NULL, -- ILL request number
4336     type varchar(200) NOT NULL,                 -- API ILL property name
4337     value MEDIUMTEXT NOT NULL,                  -- API ILL property value
4338     readonly tinyint(1) NOT NULL DEFAULT 1,     -- Is this attribute read only
4339     PRIMARY KEY  (`illrequest_id`, `type` (191)),
4340     CONSTRAINT `illrequestattributes_ifk`
4341       FOREIGN KEY (illrequest_id)
4342       REFERENCES `illrequests` (`illrequest_id`)
4343       ON UPDATE CASCADE ON DELETE CASCADE
4344 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4345
4346 --
4347 -- Table structure for table 'library_groups'
4348 --
4349
4350 DROP TABLE IF EXISTS `library_groups`;
4351 CREATE TABLE library_groups (
4352     id INT(11) NOT NULL auto_increment,    -- unique id for each group
4353     parent_id INT(11) NULL DEFAULT NULL,   -- if this is a child group, the id of the parent group
4354     branchcode VARCHAR(10) NULL DEFAULT NULL, -- The branchcode of a branch belonging to the parent group
4355     title VARCHAR(100) NULL DEFAULT NULL,     -- Short description of the goup
4356     description MEDIUMTEXT NULL DEFAULT NULL,    -- Longer explanation of the group, if necessary
4357     ft_hide_patron_info tinyint(1) NOT NULL DEFAULT 0, -- Turn on the feature "Hide patron's info" for this group
4358     ft_search_groups_opac tinyint(1) NOT NULL DEFAULT 0, -- Use this group for staff side search groups
4359     ft_search_groups_staff tinyint(1) NOT NULL DEFAULT 0, -- Use this group for opac side search groups
4360     ft_local_hold_group tinyint(1) NOT NULL DEFAULT 0, -- Use this group to identify libraries as pick up location for holds
4361     created_on TIMESTAMP NULL,             -- Date and time of creation
4362     updated_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, -- Date and time of last
4363     PRIMARY KEY id ( id ),
4364     FOREIGN KEY (parent_id) REFERENCES library_groups(id) ON UPDATE CASCADE ON DELETE CASCADE,
4365     FOREIGN KEY (branchcode) REFERENCES branches(branchcode) ON UPDATE CASCADE ON DELETE CASCADE,
4366     UNIQUE KEY title ( title ),
4367     UNIQUE KEY library_groups_uniq_2 ( parent_id, branchcode )
4368 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4369
4370 --
4371 -- Table structure for table 'oauth_access_tokens'
4372 --
4373
4374 DROP TABLE IF EXISTS `oauth_access_tokens`;
4375 CREATE TABLE `oauth_access_tokens` (
4376     `access_token` VARCHAR(191) NOT NULL, -- generarated access token
4377     `client_id`    VARCHAR(191) NOT NULL, -- the client id the access token belongs to
4378     `expires`      INT NOT NULL,          -- expiration time in seconds
4379     PRIMARY KEY (`access_token`)
4380 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4381
4382 --
4383 -- Table structure for table illcomments
4384 --
4385
4386 DROP TABLE IF EXISTS `illcomments`;
4387 CREATE TABLE illcomments (
4388     illcomment_id int(11) NOT NULL AUTO_INCREMENT, -- Unique ID of the comment
4389     illrequest_id bigint(20) unsigned NOT NULL,    -- ILL request number
4390     borrowernumber integer DEFAULT NULL,           -- Link to the user who made the comment (could be librarian, patron or ILL partner library)
4391     comment text DEFAULT NULL,                     -- The text of the comment
4392     timestamp timestamp DEFAULT CURRENT_TIMESTAMP, -- Date and time when the comment was made
4393     PRIMARY KEY  ( illcomment_id ),
4394     CONSTRAINT illcomments_bnfk
4395       FOREIGN KEY ( borrowernumber )
4396       REFERENCES  borrowers  ( borrowernumber )
4397       ON UPDATE CASCADE ON DELETE CASCADE,
4398     CONSTRAINT illcomments_ifk
4399       FOREIGN KEY (illrequest_id)
4400       REFERENCES illrequests ( illrequest_id )
4401       ON UPDATE CASCADE ON DELETE CASCADE
4402 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4403
4404 --
4405 -- Table structure for table `circulation_rules`
4406 --
4407
4408 DROP TABLE IF EXISTS `circulation_rules`;
4409 CREATE TABLE `circulation_rules` (
4410   `id` int(11) NOT NULL auto_increment,
4411   `branchcode` varchar(10) NULL default NULL,
4412   `categorycode` varchar(10) NULL default NULL,
4413   `itemtype` varchar(10) NULL default NULL,
4414   `rule_name` varchar(32) NOT NULL,
4415   `rule_value` varchar(32) NOT NULL,
4416   PRIMARY KEY (`id`),
4417   CONSTRAINT `circ_rules_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE,
4418   CONSTRAINT `circ_rules_ibfk_2` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) ON DELETE CASCADE ON UPDATE CASCADE,
4419   CONSTRAINT `circ_rules_ibfk_3` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE CASCADE ON UPDATE CASCADE,
4420   KEY `rule_name` (`rule_name`),
4421   UNIQUE (`branchcode`,`categorycode`,`itemtype`,`rule_name`)
4422 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4423
4424 --
4425 -- Table structure for table `stockrotationrotas`
4426 --
4427
4428 DROP TABLE IF EXISTS stockrotationrotas;
4429 CREATE TABLE stockrotationrotas (
4430     rota_id int(11) auto_increment,         -- Stockrotation rota ID
4431     title varchar(100) NOT NULL,            -- Title for this rota
4432     description text NOT NULL,              -- Description for this rota
4433     cyclical tinyint(1) NOT NULL default 0, -- Should items on this rota keep cycling?
4434     active tinyint(1) NOT NULL default 0,   -- Is this rota currently active?
4435     PRIMARY KEY (`rota_id`)
4436 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4437
4438 --
4439 -- Table structure for table `stockrotationstages`
4440 --
4441
4442 DROP TABLE IF EXISTS stockrotationstages;
4443 CREATE TABLE stockrotationstages (
4444     stage_id int(11) auto_increment,     -- Unique stage ID
4445     position int(11) NOT NULL,           -- The position of this stage within its rota
4446     rota_id int(11) NOT NULL,            -- The rota this stage belongs to
4447     branchcode_id varchar(10) NOT NULL,  -- Branch this stage relates to
4448     duration int(11) NOT NULL default 4, -- The number of days items shoud occupy this stage
4449     PRIMARY KEY (`stage_id`),
4450     CONSTRAINT `stockrotationstages_rifk`
4451       FOREIGN KEY (`rota_id`)
4452       REFERENCES `stockrotationrotas` (`rota_id`)
4453       ON UPDATE CASCADE ON DELETE CASCADE,
4454     CONSTRAINT `stockrotationstages_bifk`
4455       FOREIGN KEY (`branchcode_id`)
4456       REFERENCES `branches` (`branchcode`)
4457       ON UPDATE CASCADE ON DELETE CASCADE
4458 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4459
4460 --
4461 -- Table structure for table `stockrotationitems`
4462 --
4463
4464 DROP TABLE IF EXISTS stockrotationitems;
4465 CREATE TABLE stockrotationitems (
4466     itemnumber_id int(11) NOT NULL,         -- Itemnumber to link to a stage & rota
4467     stage_id int(11) NOT NULL,              -- stage ID to link the item to
4468     indemand tinyint(1) NOT NULL default 0, -- Should this item be skipped for rotation?
4469     fresh tinyint(1) NOT NULL default 0,    -- Flag showing item is only just added to rota
4470     PRIMARY KEY (itemnumber_id),
4471     CONSTRAINT `stockrotationitems_iifk`
4472       FOREIGN KEY (`itemnumber_id`)
4473       REFERENCES `items` (`itemnumber`)
4474       ON UPDATE CASCADE ON DELETE CASCADE,
4475     CONSTRAINT `stockrotationitems_sifk`
4476       FOREIGN KEY (`stage_id`)
4477       REFERENCES `stockrotationstages` (`stage_id`)
4478       ON UPDATE CASCADE ON DELETE CASCADE
4479 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4480
4481 --
4482 -- Table structure for table `keyboardshortcuts`
4483 --
4484
4485 DROP TABLE IF EXISTS `keyboard_shortcuts`;
4486 CREATE TABLE keyboard_shortcuts (
4487 shortcut_name varchar(80) NOT NULL,
4488 shortcut_keys varchar(80) NOT NULL,
4489 PRIMARY KEY (shortcut_name)
4490 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4491
4492 --
4493 -- Table structure for table itemtypes_branches
4494 --
4495
4496 DROP TABLE IF EXISTS itemtypes_branches;
4497 CREATE TABLE itemtypes_branches( -- association table between authorised_values and branches
4498     itemtype VARCHAR(10) NOT NULL,
4499     branchcode VARCHAR(10) NOT NULL,
4500     FOREIGN KEY (itemtype) REFERENCES itemtypes(itemtype) ON DELETE CASCADE,
4501     FOREIGN KEY (branchcode) REFERENCES branches(branchcode) ON DELETE CASCADE
4502 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4503
4504 --
4505 -- Table structure for table `return_claims`
4506 --
4507
4508 DROP TABLE IF EXISTS `return_claims`;
4509 CREATE TABLE return_claims (
4510     id int(11) auto_increment,                             -- Unique ID of the return claim
4511     itemnumber int(11) NOT NULL,                           -- ID of the item
4512     issue_id int(11) NULL DEFAULT NULL,                    -- ID of the checkout that triggered the claim
4513     borrowernumber int(11) NOT NULL,                       -- ID of the patron
4514     notes MEDIUMTEXT DEFAULT NULL,                         -- Notes about the claim
4515     created_on TIMESTAMP NULL,                             -- Time and date the claim was created
4516     created_by int(11) NULL DEFAULT NULL,                  -- ID of the staff member that registered the claim
4517     updated_on TIMESTAMP NULL ON UPDATE CURRENT_TIMESTAMP, -- Time and date of the latest change on the claim (notes)
4518     updated_by int(11) NULL DEFAULT NULL,                  -- ID of the staff member that updated the claim
4519     resolution  varchar(80) NULL DEFAULT NULL,             -- Resolution code (RETURN_CLAIM_RESOLUTION AVs)
4520     resolved_on TIMESTAMP NULL DEFAULT NULL,               -- Time and date the claim was resolved
4521     resolved_by int(11) NULL DEFAULT NULL,                 -- ID of the staff member that resolved the claim
4522     PRIMARY KEY (`id`),
4523     KEY `itemnumber` (`itemnumber`),
4524     CONSTRAINT UNIQUE `issue_id` ( issue_id ),
4525     CONSTRAINT `issue_id` FOREIGN KEY (`issue_id`) REFERENCES `issues` (`issue_id`) ON DELETE SET NULL ON UPDATE CASCADE,
4526     CONSTRAINT `rc_items_ibfk` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
4527     CONSTRAINT `rc_borrowers_ibfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
4528     CONSTRAINT `rc_created_by_ibfk` FOREIGN KEY (`created_by`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
4529     CONSTRAINT `rc_updated_by_ibfk` FOREIGN KEY (`updated_by`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
4530     CONSTRAINT `rc_resolved_by_ibfk` FOREIGN KEY (`resolved_by`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE
4531 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4532
4533 --
4534 -- Table structure for table `problem_reports`
4535 --
4536
4537 DROP TABLE IF EXISTS `problem_reports`;
4538 CREATE TABLE `problem_reports` (
4539     `reportid` int(11) NOT NULL auto_increment, -- unique identifier assigned by Koha
4540     `title` varchar(40) NOT NULL default '', -- report subject line
4541     `content` varchar(255) NOT NULL default '', -- report message content
4542     `borrowernumber` int(11) NOT NULL default 0, -- the user who created the problem report
4543     `branchcode` varchar(10) NOT NULL default '', -- borrower's branch
4544     `username` varchar(75) default NULL, -- OPAC username
4545     `problempage` TEXT default NULL, -- page the user triggered the problem report form from
4546     `recipient` enum('admin','library') NOT NULL default 'library', -- the 'to-address' of the problem report
4547     `created_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of report submission
4548     `status` varchar(6) NOT NULL default 'New', -- status of the report. New, Viewed, Closed
4549     PRIMARY KEY (`reportid`),
4550     CONSTRAINT `problem_reports_ibfk1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
4551     CONSTRAINT `problem_reports_ibfk2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
4552 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4553
4554 --
4555 -- Table structure for table advanced_editor_macros
4556 --
4557
4558 DROP TABLE IF EXISTS advanced_editor_macros;
4559 CREATE TABLE advanced_editor_macros (
4560     id INT(11) NOT NULL AUTO_INCREMENT,     -- Unique ID of the macro
4561     name varchar(80) NOT NULL,              -- Name of the macro
4562     macro longtext NULL,                    -- The macro code itself
4563     borrowernumber INT(11) default NULL,    -- ID of the borrower who created this macro
4564     shared TINYINT(1) default 0,            -- Bit to define if shared or private macro
4565     PRIMARY KEY (id),
4566     CONSTRAINT borrower_macro_fk FOREIGN KEY ( borrowernumber ) REFERENCES borrowers ( borrowernumber ) ON UPDATE CASCADE ON DELETE CASCADE
4567 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4568
4569 /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
4570 /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
4571 /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
4572 /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
4573 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
4574 /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
4575 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
4576 /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;