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