Bug 11703: (qa-followup) fix update database entry
[koha_fer] / installer / data / mysql / updatedatabase.pl
index 78ba6ca..6cda25d 100755 (executable)
@@ -7130,13 +7130,12 @@ if ( CheckVersion($DBversion) ) {
     SetVersion($DBversion);
 }
 
-
 $DBversion = "3.13.00.020";
 if ( CheckVersion($DBversion) ) {
     $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES('WhenLostForgiveFine','0',NULL,'If ON, Forgives the fines on an item when it is lost.','YesNo')");
     $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES('WhenLostChargeReplacementFee','1',NULL,'If ON, Charge the replacement price when a patron loses an item.','YesNo')");
     print "Upgrade to $DBversion done (Bug 7639: system preferences to forgive fines on lost items)\n";
-    SetVersion ($DBversion);
+    SetVersion($DBversion);
 }
 
 $DBversion ="3.13.00.021";
@@ -7165,7 +7164,6 @@ $DBversion = "3.13.00.024";
 if ( CheckVersion($DBversion) ) {
     $dbh->do(q{ALTER TABLE z3950servers ADD COLUMN recordtype VARCHAR(45) NOT NULL DEFAULT 'biblio' AFTER description;});
     print "Upgrade to $DBversion done (Bug 10096 - Add a Z39.50 interface for authority searching)\n";
-    SetVersion ($DBversion);
 }
 
 $DBversion = "3.13.00.025";
@@ -7472,11 +7470,13 @@ if ( CheckVersion($DBversion) ) {
     |);
     my $check_numberpatterns_sth = $dbh->prepare(qq|
         SELECT * FROM subscription_numberpatterns
-        WHERE add1 = ? AND add2 = ? AND add3 = ?
-          AND every1 = ? AND every2 = ? AND every3 = ?
-          AND whenmorethan1 = ? AND whenmorethan2 = ? AND whenmorethan3 = ?
-          AND setto1 = ? AND setto2 = ? AND setto3 = ?
-          AND numberingmethod = ?
+        WHERE (add1 = ? OR (add1 IS NULL AND ? IS NULL)) AND (add2 = ? OR (add2 IS NULL AND ? IS NULL))
+        AND (add3 = ? OR (add3 IS NULL AND ? IS NULL)) AND (every1 = ? OR (every1 IS NULL AND ? IS NULL))
+        AND (every2 = ? OR (every2 IS NULL AND ? IS NULL)) AND (every3 = ? OR (every3 IS NULL AND ? IS NULL))
+        AND (whenmorethan1 = ? OR (whenmorethan1 IS NULL AND ? IS NULL)) AND (whenmorethan2 = ? OR (whenmorethan2 IS NULL AND ? IS NULL))
+        AND (whenmorethan3 = ? OR (whenmorethan3 IS NULL AND ? IS NULL)) AND (setto1 = ? OR (setto1 IS NULL AND ? IS NULL))
+        AND (setto2 = ? OR (setto2 IS NULL AND ? IS NULL)) AND (setto3 = ? OR (setto3 IS NULL AND ? IS NULL))
+        AND (numberingmethod = ? OR (numberingmethod IS NULL AND ? IS NULL))
         LIMIT 1
     |);
     my $update_subscription_sth = $dbh->prepare(qq|
@@ -7489,11 +7489,11 @@ if ( CheckVersion($DBversion) ) {
     my $i = 1;
     while(my $sub = $sth->fetchrow_hashref) {
         $check_numberpatterns_sth->execute(
-            $sub->{add1}, $sub->{add2}, $sub->{add3},
-            $sub->{every1}, $sub->{every2}, $sub->{every3},
-            $sub->{whenmorethan1}, $sub->{whenmorethan2}, $sub->{whenmorethan3},
-            $sub->{setto1}, $sub->{setto2}, $sub->{setto3},
-            $sub->{numberingmethod}
+            $sub->{add1}, $sub->{add1}, $sub->{add2}, $sub->{add2}, $sub->{add3}, $sub->{add3},
+            $sub->{every1}, $sub->{every1}, $sub->{every2}, $sub->{every2}, $sub->{every3}, $sub->{every3},
+            $sub->{whenmorethan1}, $sub->{whenmorethan1}, $sub->{whenmorethan2}, $sub->{whenmorethan2},
+            $sub->{whenmorethan3}, $sub->{whenmorethan3}, $sub->{setto1}, $sub->{setto1}, $sub->{setto2},
+            $sub->{setto2}, $sub->{setto3}, $sub->{setto3}, $sub->{numberingmethod}, $sub->{numberingmethod}
         );
         my $p = $check_numberpatterns_sth->fetchrow_hashref;
         if (defined $p) {
@@ -7613,8 +7613,13 @@ CREATE TABLE borrower_debarments (
 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
     });
 
+    # debarments with end date
     $dbh->do(q{
-INSERT INTO borrower_debarments ( borrowernumber, expiration, comment ) SELECT borrowernumber, debarred, debarredcomment FROM borrowers WHERE debarred IS NOT NULL
+INSERT INTO borrower_debarments ( borrowernumber, expiration, comment ) SELECT borrowernumber, debarred, debarredcomment FROM borrowers WHERE debarred IS NOT NULL AND debarred <> '9999-12-31'
+    });
+    # debarments with no end date
+    $dbh->do(q{
+INSERT INTO borrower_debarments ( borrowernumber, comment ) SELECT borrowernumber, debarredcomment FROM borrowers WHERE debarred = '9999-12-31'
     });
 
     $dbh->do(q{
@@ -7733,7 +7738,7 @@ if(CheckVersion($DBversion)) {
     $dbh->do(q{
         INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AcqItemSetSubfieldsWhenReceived','','Set subfields for item when items are created when receiving (e.g. o=5|a="foo bar")','','Free');
     });
-    print "Upgrade to $DBversion done (Added AcqItemSetSubfieldsWhenReceived syspref)\n";
+    print "Upgrade to $DBversion done (Bug 10986: Added AcqItemSetSubfieldsWhenReceived syspref)\n";
     SetVersion($DBversion);
 }
 
@@ -7946,7 +7951,7 @@ if (CheckVersion($DBversion)) {
 }
 
 $DBversion = "3.15.00.016";
-if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+if (CheckVersion($DBversion)) {
     $dbh->do("ALTER TABLE biblioitems CHANGE url url TEXT NULL DEFAULT NULL");
     $dbh->do("ALTER TABLE deletedbiblioitems CHANGE url url TEXT NULL DEFAULT NULL");
     print "Upgrade to $DBversion done (Bug 11268 - Biblioitems URL field is too small for some URLs)\n";
@@ -8006,14 +8011,14 @@ if ( CheckVersion($DBversion) ) {
 }
 
 $DBversion = "3.15.00.019";
-if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+if ( CheckVersion($DBversion) ) {
     $dbh->do("INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES('OpacMaxItemsToDisplay','50','','Max items to display at the OPAC on a biblio detail','Integer')");
     print "Upgrade to $DBversion done (Bug 11256: Add system preference OpacMaxItemsToDisplay)\n";
     SetVersion($DBversion);
 }
 
 $DBversion = "3.15.00.020";
-if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+if ( CheckVersion($DBversion) ) {
     $dbh->do(q|
         INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES('MaxItemsForBatch','1000',NULL,'Max number of items record to process in a batch (modification or deletion)','Integer')
     |);
@@ -8065,6 +8070,506 @@ if ( CheckVersion($DBversion) ) {
     SetVersion($DBversion);
 }
 
+$DBversion = "3.15.00.025";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q{
+        DROP TABLE aqorderdelivery;
+    });
+    print "Upgrade to $DBversion done (Bug 11928 - remove unused table)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.026";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q{
+        UPDATE language_descriptions SET description = 'Հայերեն' WHERE subtag = 'hy' AND lang = 'hy';
+    });
+    print "Upgrade to $DBversion done (Bug 11973 - Fix Armenian language description)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.027";
+if (CheckVersion($DBversion)) {
+    $dbh->do(q{
+        ALTER TABLE opac_news ADD branchcode varchar(10) DEFAULT NULL
+                                  AFTER idnew,
+                              ADD CONSTRAINT opac_news_branchcode_ibfk
+                                  FOREIGN KEY (branchcode)
+                                  REFERENCES branches (branchcode)
+                                  ON DELETE CASCADE ON UPDATE CASCADE;
+    });
+    print "Upgrade to $DBversion done (Bug 7567: Add branchcode to opac_news)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.028";
+if(CheckVersion($DBversion)) {
+    $dbh->do(q{
+        ALTER TABLE issuingrules ADD norenewalbefore int(4) default NULL AFTER renewalperiod
+    });
+    print "Upgrade to $DBversion done (Bug 7413: Allow OPAC renewal x days before due date)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.029";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q{
+        UPDATE borrower_debarments SET expiration = NULL WHERE expiration = '9999-12-31'
+    });
+    print "Upgrade to $DBversion done (Bug 11846 - correct borrower_debarments with expiration 9999-12-31)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.030";
+if(CheckVersion($DBversion)) {
+    $dbh->do(q|
+        INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('OPACMySummaryNote','','','Note to display on the patron summary page. This note only appears if the patron is connected.','Free')
+    |);
+    print "Upgrade to $DBversion done (Bug 12052: Add OPACMySummaryNote syspref)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.031";
+if ( CheckVersion($DBversion) ) {
+   $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ('10', 'writeoff', 'Write off fines and fees')");
+   $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ('10', 'remaining_permissions', 'Remaining permissions for managing fines and fees')");
+   print "Upgrade to $DBversion done (Bug 9448 - Add separate permission for writing off fees)\n";
+   SetVersion ($DBversion);
+}
+
+$DBversion = "3.15.00.032";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("ALTER TABLE aqorders CHANGE notes order_internalnote MEDIUMTEXT;");
+    $dbh->do("ALTER TABLE aqorders ADD COLUMN order_vendornote MEDIUMTEXT AFTER order_internalnote;");
+    print "Upgrade to $DBversion done (Bug 9416 - In each order, add a new note made for the vendor)\n";
+   SetVersion ($DBversion);
+}
+
+$DBversion = "3.15.00.033";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('NoLoginInstructions', '', '60|10', 'Instructions to display on the OPAC login form when a patron is not logged in', 'Textarea')");
+    print "Upgrade to $DBversion done (Bug 10951: Add NoLoginInstructions pref)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.034";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES('AdvancedSearchLanguages','','','ISO 639-2 codes of languages you wish to see appear as an advanced search option.  Example: eng|fra|ita','Textarea')");
+    print "Upgrade to $DBversion done (Bug 10986: system preferences to limit languages in advanced search )\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.15.00.035";
+if ( CheckVersion($DBversion) ) {
+    #insert a notice for sharing a list and accepting a share
+    $dbh->do("
+INSERT INTO letter (module, code, branchcode, name, is_html, title, content)
+VALUES ( 'members', 'SHARE_INVITE', '', 'Invitation for sharing a list', '0', 'Share list <<listname>>', 'Dear patron,
+
+One of our patrons, <<borrowers.firstname>> <<borrowers.surname>>, invites you to share a list <<listname>> in our library catalog.
+
+To access this shared list, please click on the following URL or copy-and-paste it into your browser address bar.
+
+<<shareurl>>
+
+In case you are not a patron in our library or do not want to accept this invitation, please ignore this mail. Note also that this invitation expires within two weeks.
+
+Thank you.
+
+Your library.'
+    )");
+    $dbh->do("
+INSERT INTO letter (module, code, branchcode, name, is_html, title, content)
+VALUES ( 'members', 'SHARE_ACCEPT', '', 'Notification about an accepted share', '0', 'Share on list <<listname>> accepted', 'Dear patron,
+
+We want to inform you that <<borrowers.firstname>> <<borrowers.surname>> accepted your invitation to share your list <<listname>> in our library catalog.
+
+Thank you.
+
+Your library.'
+    )");
+    print "Upgrade to $DBversion done (Bug 9032: Share a list)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.036";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q{
+        INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type)
+        VALUES('AllowMultipleIssuesOnABiblio',1,'Allow/Don\'t allow patrons to check out multiple items from one biblio','','YesNo')
+    });
+
+    print "Upgrade to $DBversion done (Bug 10859 - Add system preference AllowMultipleIssuesOnABiblio)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.037";
+if(CheckVersion($DBversion)) {
+    $dbh->do(q{
+        ALTER TABLE itemtypes ADD sip_media_type VARCHAR( 3 ) DEFAULT NULL AFTER checkinmsgtype
+    });
+    $dbh->do(q{
+        INSERT INTO authorised_values (category, authorised_value, lib) VALUES
+         ('SIP_MEDIA_TYPE', '000', 'Other'),
+         ('SIP_MEDIA_TYPE', '001', 'Book'),
+         ('SIP_MEDIA_TYPE', '002', 'Magazine'),
+         ('SIP_MEDIA_TYPE', '003', 'Bound journal'),
+         ('SIP_MEDIA_TYPE', '004', 'Audio tape'),
+         ('SIP_MEDIA_TYPE', '005', 'Video tape'),
+         ('SIP_MEDIA_TYPE', '006', 'CD/CDROM'),
+         ('SIP_MEDIA_TYPE', '007', 'Diskette'),
+         ('SIP_MEDIA_TYPE', '008', 'Book with diskette'),
+         ('SIP_MEDIA_TYPE', '009', 'Book with CD'),
+         ('SIP_MEDIA_TYPE', '010', 'Book with audio tape')
+    });
+    print "Upgrade to $DBversion done (Bug 11351 - Add support for SIP2 media type)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = '3.15.00.038';
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q{
+        INSERT INTO  systempreferences (
+            variable,
+            value,
+            options,
+            explanation,
+            type
+            )
+        VALUES (
+            'DisplayLibraryFacets',  'holding',  'home|holding|both',  'Defines which library facets to display.',  'Choice'
+        );
+    });
+    print "Upgrade to $DBversion done (Bug 11334 - Add facet for home library)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.15.00.039";
+if ( CheckVersion($DBversion) ) {
+
+    $dbh->do( q{
+        ALTER TABLE letter ADD COLUMN message_transport_type VARCHAR(20) NOT NULL DEFAULT 'email' AFTER content
+    } );
+
+    $dbh->do( q{
+        ALTER TABLE letter ADD CONSTRAINT message_transport_type_fk FOREIGN KEY (message_transport_type) REFERENCES message_transport_types(message_transport_type);
+    } );
+
+    $dbh->do( q{
+        ALTER TABLE letter DROP PRIMARY KEY, ADD PRIMARY KEY (`module`,`code`,`branchcode`, message_transport_type);
+    } );
+
+    $dbh->do( q{
+        CREATE TABLE overduerules_transport_types(
+            id INT(11) NOT NULL AUTO_INCREMENT,
+            branchcode varchar(10) NOT NULL DEFAULT '',
+            categorycode VARCHAR(10) NOT NULL DEFAULT '',
+            letternumber INT(1) NOT NULL DEFAULT 1,
+            message_transport_type VARCHAR(20) NOT NULL DEFAULT 'email',
+            PRIMARY KEY (id),
+            CONSTRAINT overduerules_fk FOREIGN KEY (branchcode, categorycode) REFERENCES overduerules (branchcode, categorycode) ON DELETE CASCADE ON UPDATE CASCADE,
+            CONSTRAINT mtt_fk FOREIGN KEY (message_transport_type) REFERENCES message_transport_types (message_transport_type) ON DELETE CASCADE ON UPDATE CASCADE
+        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+    } );
+
+    my $sth = $dbh->prepare( q{
+        SELECT * FROM overduerules;
+    } );
+
+    $sth->execute;
+    my $sth_insert_mtt = $dbh->prepare( q{
+        INSERT INTO overduerules_transport_types (branchcode, categorycode, letternumber, message_transport_type) VALUES ( ?, ?, ?, ? )
+    } );
+    while ( my $row = $sth->fetchrow_hashref ) {
+        my $branchcode = $row->{branchcode};
+        my $categorycode = $row->{categorycode};
+        for my $letternumber ( 1 .. 3 ) {
+            next unless $row->{"letter$letternumber"};
+            $sth_insert_mtt->execute(
+                $branchcode, $categorycode, $letternumber, 'email'
+            );
+        }
+    }
+
+    print "Upgrade done (Bug 9016: Adds multi transport types management for notices)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.040";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q|
+        UPDATE message_transports SET letter_code='HOLD' WHERE letter_code='HOLD_PHONE' OR letter_code='HOLD_PRINT'
+    |);
+    $dbh->do(q|
+        UPDATE letter SET code='HOLD', message_transport_type='print' WHERE code='HOLD_PRINT'
+    |);
+    $dbh->do(q|
+        UPDATE letter SET code='HOLD', message_transport_type='phone' WHERE code='HOLD_PHONE'
+    |);
+    print "Upgrade to $DBversion done (Bug 10845: Multi transport types for holds)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.041";
+if ( CheckVersion($DBversion) ) {
+    my $name = $dbh->selectcol_arrayref(q|
+        SELECT name FROM letter WHERE code="HOLD"
+    |);
+    $name = $name->[0];
+    $dbh->do(q|
+        UPDATE letter
+        SET code="HOLD",
+            message_transport_type="phone",
+            name= ?
+        WHERE code="HOLD_PHONE"
+    |, {}, $name);
+
+    $dbh->do(q|
+        UPDATE letter
+        SET code="PREDUE",
+            message_transport_type="phone",
+            name= ?
+        WHERE code="PREDUE_PHONE"
+    |, {}, $name);
+
+    $dbh->do(q|
+        UPDATE letter
+        SET code="OVERDUE",
+            message_transport_type="phone",
+            name= ?
+        WHERE code="OVERDUE_PHONE"
+    |, {}, $name);
+
+    print "Upgrade to $DBversion done (Bug 11867: Update letters *_PHONE)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.042";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q{
+        INSERT INTO systempreferences
+            (variable,value,explanation,options,type)
+        VALUES
+            ('SpecifyReturnDate',0,'Define whether to display \"Specify Return Date\" form in Circulation','','YesNo')
+    });
+    print "Upgrade to $DBversion done (Bug 10694 - Allow arbitrary backdating of returns)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.043";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('MarcFieldsToOrder','','Set the mapping values for a new order line created from a MARC record in a staged file. In a YAML format.', NULL, 'textarea')");
+   print "Upgrade to $DBversion done (Bug 7180: Added MarcFieldsToOrder syspref)\n";
+   SetVersion ($DBversion);
+}
+
+$DBversion = "3.15.00.044";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("ALTER TABLE currency ADD isocode VARCHAR(5) default NULL AFTER symbol;");
+    print "Upgrade to $DBversion done (Added isocode to the currency table)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.045";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("
+        INSERT INTO systempreferences (variable,value,explanation,options,type)
+        VALUES (
+            'BlockExpiredPatronOpacActions',
+            '0',
+            'Set whether an expired patron can perform opac actions such as placing holds or renew books, can be overridden on a per patron-type basis',
+            NULL,
+            'YesNo'
+        )
+    ");
+    $dbh->do("ALTER TABLE `categories` ADD COLUMN `BlockExpiredPatronOpacActions` TINYINT(1) DEFAULT -1 NOT NULL AFTER category_type");
+    print "Upgraded to $DBversion done (Bug 6739 - expired patrons not blocked from opac actions)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.15.00.046";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q|
+        ALTER TABLE search_history ADD COLUMN type VARCHAR(16) NOT NULL DEFAULT 'biblio' AFTER query_cgi
+    |);
+    print "Upgrade to $DBversion done (Bug 10807 - Add db field search_history.type)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.047";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q|
+        INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('EnableSearchHistory','0','','Enable or disable search history','YesNo')
+    |);
+    print "Upgrade to $DBversion done (Bug 10862: Add EnableSearchHistory syspref)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.048";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OpacSuppressionRedirect','1','Redirect the opac detail page for suppressed records to an explanatory page (otherwise redirect to 404 error page)','','YesNo')");
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OpacSuppressionMessage', '','Display this message on the redirect page for suppressed biblios','70|10','Textarea')");
+    print "Upgrade to $DBversion done (Bug 10195: Records hidden with OpacSuppression can still be accessed)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.049";
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+    $dbh->do("ALTER TABLE biblioitems DROP INDEX isbn");
+    $dbh->do("ALTER TABLE biblioitems DROP INDEX issn");
+    $dbh->do("ALTER TABLE biblioitems
+              CHANGE isbn isbn MEDIUMTEXT NULL DEFAULT NULL,
+              CHANGE issn issn MEDIUMTEXT NULL DEFAULT NULL
+    ");
+    $dbh->do("ALTER TABLE biblioitems
+              ADD INDEX isbn ( isbn ( 255 ) ),
+              ADD INDEX issn ( issn ( 255 ) )
+    ");
+
+    $dbh->do("ALTER TABLE deletedbiblioitems DROP INDEX isbn");
+    $dbh->do("ALTER TABLE deletedbiblioitems
+              CHANGE isbn isbn MEDIUMTEXT NULL DEFAULT NULL,
+              CHANGE issn issn MEDIUMTEXT NULL DEFAULT NULL
+    ");
+    $dbh->do("ALTER TABLE deletedbiblioitems
+              ADD INDEX isbn ( isbn ( 255 ) )
+    ");
+
+    print "Upgrade to $DBversion done (Bug 11268 - Biblioitems URL field is too small for some URLs)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.050";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("
+        INSERT INTO systempreferences (
+            variable,
+            value,
+            explanation,
+            type
+        ) VALUES (
+            'AggressiveMatchOnISBN',
+            '0',
+            'If enabled, attempt to match aggressively by trying all variations of the ISBNs in the imported record as a phrase in the ISBN fields of already cataloged records when matching on ISBN with the record import tool',
+            'YesNo'
+        )
+    ");
+
+    print "Upgrade to $DBversion done (Bug 10500 - Improve isbn matching when importing records)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.051";
+if ( CheckVersion($DBversion) ) {
+    print "Upgrade to $DBversion done (Koha 3.16 beta)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.052";
+if ( CheckVersion($DBversion) ) {
+    print "Upgrade to $DBversion done (Koha 3.16 RC)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.16.00.000";
+if ( CheckVersion($DBversion) ) {
+    print "Upgrade to $DBversion done (3.16.0 release)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = '3.17.00.000';
+if ( CheckVersion($DBversion) ) {
+    print "Upgrade to $DBversion done (there is no time to rest on our laurels)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = '3.17.00.001';
+if ( CheckVersion($DBversion) ) {
+   $dbh->do("UPDATE systempreferences SET variable = 'AuthoritySeparator' WHERE variable = 'authoritysep'");
+   print "Upgrade to $DBversion done (Bug 10330 - Rename system preference authoritysep to AuthoritySeparator)\n";
+   SetVersion ($DBversion);
+}
+
+$DBversion = "3.17.00.002";
+if (CheckVersion($DBversion)) {
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,type) VALUES('AcqEnableFiles','0','If enabled, allows librarians to upload and attach arbitrary files to invoice records.','YesNo')");
+    $dbh->do("
+CREATE TABLE IF NOT EXISTS `misc_files` (
+  `file_id` int(11) NOT NULL AUTO_INCREMENT,
+  `table_tag` varchar(255) NOT NULL,
+  `record_id` int(11) NOT NULL,
+  `file_name` varchar(255) NOT NULL,
+  `file_type` varchar(255) NOT NULL,
+  `file_description` varchar(255) DEFAULT NULL,
+  `file_content` longblob NOT NULL, -- file content
+  `date_uploaded` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+  PRIMARY KEY (`file_id`),
+  KEY `table_tag` (`table_tag`),
+  KEY `record_id` (`record_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+    ");
+    print "Upgrade to $DBversion done (Bug 3050 - Add an option to upload scanned invoices)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.17.00.003";
+if (CheckVersion($DBversion)) {
+    $dbh->do("UPDATE systempreferences SET type = 'Choice', options = '0|1|force' WHERE variable = 'OPACItemHolds'");
+    print "Upgrade to $DBversion done (Bug 7825 - Changed OPACItemHolds syspref to Choice)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.17.00.004";
+if (CheckVersion($DBversion)) {
+    $dbh->do("ALTER TABLE categories ADD default_privacy ENUM( 'default', 'never', 'forever' ) NOT NULL DEFAULT 'default' AFTER category_type");
+    print "Upgrade to $DBversion done (Bug 6254 - can't set patron privacy by default)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.17.00.005";
+if (CheckVersion($DBversion)) {
+    $dbh->do(q|
+        ALTER TABLE issuingrules
+        ADD maxsuspensiondays INT(11) DEFAULT NULL AFTER finedays;
+    |);
+    print "Upgrade to $DBversion done (Bug 12230: Add new issuing rule maxsuspensiondays)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.17.00.006";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('OpacLocationBranchToDisplay',  'holding',  'holding|home|both',  'In the OPAC, under location show which branch for Location in the record details.',  'Choice')");
+    $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('OpacLocationBranchToDisplayShelving',  'holding',  'holding|home|both',  'In the OPAC, display the shelving location under which which column',  'Choice')");
+    print "Upgrade to $DBversion done (Bug 7720 - Ambiguity in OPAC Details location.)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.17.00.007";
+if (CheckVersion($DBversion)) {
+    $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES('UpdateNotForLoanStatusOnCheckin', '', 'NULL', 'This is a list of value pairs. When an item is checked in, if the not for loan value on the left matches the items not for loan value it will be updated to the right-hand value. E.g. ''-1: 0'' will cause an item that was set to ''Ordered'' to now be available for loan. Each pair of values should be on a separate line.', 'Free');");
+    print "Upgrade to $DBversion done (Bug 11629 - Add ability to update not for loan status on checkin)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.17.00.008";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q|
+        INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES('OPACAcquisitionDetails','0', '','Show the acquisition details at the OPAC','YesNo')
+    |);
+    print "Upgrade to $DBversion done (Bug 11169 - Add OPACAcquisitionDetails syspref)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.17.00.XXX";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q{
+        DELETE FROM systempreferences WHERE variable = 'UseTablesortForCirc'
+    });
+
+    print "Upgrade to $DBversion done (Bug 11703 - Remove UseTablesortForCirc syspref)\n";
+    SetVersion($DBversion);
+}
+
 =head1 FUNCTIONS
 
 =head2 TableExists($table)