Bug 17216: Add FK on mss.authorised_value
[koha.git] / installer / data / mysql / kohastructure.sql
index c5a3f4a..b97773f 100644 (file)
@@ -69,7 +69,7 @@ CREATE TABLE `auth_subfield_structure` (
   `linkid` tinyint(1) NOT NULL default 0,
   `kohafield` varchar(45) NULL default '',
   `frameworkcode` varchar(10) NOT NULL default '',
-  `defaultvalue` TEXT DEFAULT '',
+  `defaultvalue` TEXT,
   PRIMARY KEY  (`authtypecode`,`tagfield`,`tagsubfield`),
   KEY `tab` (`authtypecode`,`tab`),
   CONSTRAINT `auth_subfield_structure_ibfk_1` FOREIGN KEY (`authtypecode`) REFERENCES `auth_types` (`authtypecode`) ON DELETE CASCADE ON UPDATE CASCADE
@@ -92,6 +92,17 @@ CREATE TABLE `auth_tag_structure` (
   CONSTRAINT `auth_tag_structure_ibfk_1` FOREIGN KEY (`authtypecode`) REFERENCES `auth_types` (`authtypecode`) ON DELETE CASCADE ON UPDATE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
 
+
+--
+-- Table structure for table `authorised_value_categories`
+--
+
+DROP TABLE IF EXISTS `authorised_value_categories`;
+CREATE TABLE `authorised_value_categories` (
+  `category_name` varchar(32) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
+  PRIMARY KEY (`category_name`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+
 --
 -- Table structure for table `authorised_values`
 --
@@ -319,6 +330,7 @@ CREATE TABLE `categories` ( -- this table shows information related to Koha patr
   `category_type` varchar(1) NOT NULL default 'A', -- type of Koha patron (Adult, Child, Professional, Organizational, Statistical, Staff)
   `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
   `default_privacy` ENUM( 'default', 'never', 'forever' ) NOT NULL DEFAULT 'default', -- Default privacy setting for this patron category
+  `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'.
   PRIMARY KEY  (`categorycode`),
   UNIQUE KEY `categorycode` (`categorycode`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
@@ -618,6 +630,9 @@ CREATE TABLE `deletedborrowers` ( -- stores data related to the patrons/borrower
   `sms_provider_id` int(11) DEFAULT NULL, -- the provider of the mobile phone number defined in smsalertnumber
   `privacy` integer(11) DEFAULT '1' NOT NULL, -- patron/borrower's privacy settings related to their reading history  KEY `borrowernumber` (`borrowernumber`),
   `privacy_guarantor_checkouts` tinyint(1) NOT NULL DEFAULT '0', -- controls if relatives can see this patron's checkouts
+  `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'.
+  `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)
+  `lastseen` datetime default NULL, -- last time a patron has been seed (connected at the OPAC or staff interface)
   KEY borrowernumber (borrowernumber),
   KEY `cardnumber` (`cardnumber`),
   KEY `sms_provider_id` (`sms_provider_id`)
@@ -856,6 +871,7 @@ CREATE TABLE `issuingrules` ( -- circulation and fine rules
   `norenewalbefore` int(4) default NULL, -- no renewal allowed until X days or hours before due date.
   `auto_renew` BOOLEAN default FALSE, -- automatic renewal
   `reservesallowed` smallint(6) NOT NULL default "0", -- how many holds are allowed
+  `holds_per_record` SMALLINT(6) NOT NULL DEFAULT 1, -- How many holds a patron can have on a given bib
   `branchcode` varchar(10) NOT NULL default '', -- the branch this rule is for (branches.branchcode)
   overduefinescap decimal(28,6) default NULL, -- the maximum amount of an overdue fine
   cap_fine_to_replacement_price BOOLEAN NOT NULL DEFAULT  '0', -- cap the fine based on item's replacement price
@@ -866,6 +882,17 @@ CREATE TABLE `issuingrules` ( -- circulation and fine rules
   KEY `itemtype` (`itemtype`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
 
+--
+-- Table structure for table `refund_lost_item_fee_rules`
+--
+
+DROP TABLE IF EXISTS `refund_lost_item_fee_rules`;
+CREATE TABLE `refund_lost_item_fee_rules` ( -- refund lost item fee rules tbale
+  `branchcode` varchar(10) NOT NULL default '', -- the branch this rule is for (branches.branchcode)
+  `refund` tinyint(1) NOT NULL default 0, -- control wether to refund lost item fees on return
+  PRIMARY KEY  (`branchcode`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+
 --
 -- Table structure for table `items`
 --
@@ -1093,7 +1120,7 @@ CREATE TABLE `marc_subfield_structure` (
   `mandatory` tinyint(4) NOT NULL default 0,
   `kohafield` varchar(40) default NULL,
   `tab` tinyint(1) default NULL,
-  `authorised_value` varchar(20) default NULL,
+  `authorised_value` varchar(32) default NULL,
   `authtypecode` varchar(20) default NULL,
   `value_builder` varchar(80) default NULL,
   `isurl` tinyint(1) default NULL,
@@ -1106,7 +1133,8 @@ CREATE TABLE `marc_subfield_structure` (
   PRIMARY KEY  (`frameworkcode`,`tagfield`,`tagsubfield`),
   KEY `kohafield_2` (`kohafield`),
   KEY `tab` (`frameworkcode`,`tab`),
-  KEY `kohafield` (`frameworkcode`,`kohafield`)
+  KEY `kohafield` (`frameworkcode`,`kohafield`),
+  CONSTRAINT `marc_subfield_structure_ibfk_1` FOREIGN KEY (`authorised_value`) REFERENCES `authorised_value_categories` (`category_name`) ON DELETE SET NULL ON UPDATE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
 
 --
@@ -1623,6 +1651,9 @@ CREATE TABLE `borrowers` ( -- this table includes information about your patrons
   `sms_provider_id` int(11) DEFAULT NULL, -- the provider of the mobile phone number defined in smsalertnumber
   `privacy` integer(11) DEFAULT '1' NOT NULL, -- patron/borrower's privacy settings related to their reading history
   `privacy_guarantor_checkouts` tinyint(1) NOT NULL DEFAULT '0', -- controls if relatives can see this patron's checkouts
+  `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'.
+  `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)
+  `lastseen` datetime default NULL, -- last time a patron has been seed (connected at the OPAC or staff interface)
   UNIQUE KEY `cardnumber` (`cardnumber`),
   PRIMARY KEY `borrowernumber` (`borrowernumber`),
   KEY `categorycode` (`categorycode`),
@@ -1916,7 +1947,7 @@ CREATE TABLE `reviews` ( -- patron opac comments
   `borrowernumber` int(11) default NULL, -- foreign key from the borrowers table defining which patron left this comment
   `biblionumber` int(11) default NULL, -- foreign key from the biblio table defining which bibliographic record this comment is for
   `review` text, -- the body of the comment
-  `approved` tinyint(4) default NULL, -- whether this comment has been approved by a librarian (1 for yes, 0 for no)
+  `approved` tinyint(4) default 0, -- whether this comment has been approved by a librarian (1 for yes, 0 for no)
   `datereviewed` datetime default NULL, -- the date the comment was left
   PRIMARY KEY  (`reviewid`),
   CONSTRAINT `reviews_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
@@ -2063,6 +2094,8 @@ CREATE TABLE `subscription` ( -- information related to the subscription
   `enddate` date default NULL, -- subscription end date
   `closed` INT(1) NOT NULL DEFAULT 0, -- yes / no if the subscription is closed
   `reneweddate` date default NULL, -- date of last renewal for the subscription
+  `itemtype` VARCHAR( 10 ) NULL,
+  `previousitemtype` VARCHAR( 10 ) NULL,
   PRIMARY KEY  (`subscriptionid`),
   CONSTRAINT subscription_ibfk_1 FOREIGN KEY (periodicity) REFERENCES subscription_frequencies (id) ON DELETE SET NULL ON UPDATE CASCADE,
   CONSTRAINT subscription_ibfk_2 FOREIGN KEY (numberpattern) REFERENCES subscription_numberpatterns (id) ON DELETE SET NULL ON UPDATE CASCADE
@@ -2209,7 +2242,7 @@ CREATE TABLE `virtualshelves` ( -- information about lists (or virtual shelves)
   `category` varchar(1) default NULL, -- type of list (private [1], public [2])
   `sortfield` varchar(16) default 'title', -- the field this list is sorted on
   `lastmodified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- date and time the list was last modified
-  `created_on` TIMESTAMP NOT NULL, -- creation time
+  `created_on` datetime NOT NULL, -- creation time
   `allow_add` tinyint(1) default 0, -- permission for adding entries to list
   `allow_delete_own` tinyint(1) default 1, -- permission for deleting entries frm list that you added yourself
   `allow_delete_other` tinyint(1) default 0, -- permission for deleting entries from list that another person added
@@ -2699,13 +2732,15 @@ CREATE TABLE `action_logs` ( -- logs of actions taken in Koha (requires that the
   `action` text, -- the action (includes things like DELETED, ADDED, MODIFY, etc)
   `object` int(11) default NULL, -- the object that the action was taken against (could be a borrowernumber, itemnumber, etc)
   `info` text, -- information about the action (usually includes SQL statement)
+  `interface` VARCHAR(30) DEFAULT NULL, -- the context this action was taken in
   PRIMARY KEY (`action_id`),
   KEY `timestamp_idx` (`timestamp`),
   KEY `user_idx` (`user`),
   KEY `module_idx` (`module`(255)),
   KEY `action_idx` (`action`(255)),
   KEY `object_idx` (`object`),
-  KEY `info_idx` (`info`(255))
+  KEY `info_idx` (`info`(255)),
+  KEY `interface` (`interface`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
 
 --
@@ -3553,7 +3588,7 @@ CREATE TABLE items_search_fields (
   authorised_values_category VARCHAR(32) NULL DEFAULT NULL,
   PRIMARY KEY(name),
   CONSTRAINT items_search_fields_authorised_values_category
-    FOREIGN KEY (authorised_values_category) REFERENCES authorised_values (category)
+    FOREIGN KEY (authorised_values_category) REFERENCES authorised_value_categories (category_name)
     ON DELETE SET NULL ON UPDATE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;