Bug 17813: Add a primary key to borrower_attributes
authorTomas Cohen Arazi <tomascohen@theke.io>
Fri, 23 Dec 2016 18:54:02 +0000 (15:54 -0300)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 20 Jan 2017 13:59:41 +0000 (13:59 +0000)
This patch adds 'borrower_attributes' a field (if) which
will act as a primary key.

This is needed for DBIC to be used to handle rows, and also will help
when faced with the implementation of the REST api for this resource.

To test:
- Run all patron modification / attributes and verify nothing breaks
- Sign off :-D

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
installer/data/mysql/atomicupdate/bug_17813_borrower_attributes_pk.sql [new file with mode: 0644]
installer/data/mysql/kohastructure.sql

diff --git a/installer/data/mysql/atomicupdate/bug_17813_borrower_attributes_pk.sql b/installer/data/mysql/atomicupdate/bug_17813_borrower_attributes_pk.sql
new file mode 100644 (file)
index 0000000..04da55d
--- /dev/null
@@ -0,0 +1,11 @@
+ALTER TABLE `borrower_attributes` ADD `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;
+
+-- $DBversion = "16.12.00.XXX";
+-- if(CheckVersion($DBversion)) {
+--     $dbh->do(q{
+--         ALTER TABLE `borrower_attributes` ADD `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST
+--     });
+--
+--     print "Upgrade to $DBversion done (Bug 17813: Table borrower_attributes needs a primary key\n";
+--     SetVersion ($DBversion);
+-- }
index 2533e9d..cc57e3d 100644 (file)
@@ -1676,6 +1676,7 @@ CREATE TABLE `borrowers` ( -- this table includes information about your patrons
 
 DROP TABLE IF EXISTS `borrower_attributes`;
 CREATE TABLE `borrower_attributes` ( -- values of custom patron fields known as extended patron attributes linked to patrons/borrowers
+  `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, -- Row id field
   `borrowernumber` int(11) NOT NULL, -- foreign key from the borrowers table, defines which patron/borrower has this attribute
   `code` varchar(10) NOT NULL, -- foreign key from the borrower_attribute_types table, defines which custom field this value was entered for
   `attribute` varchar(255) default NULL, -- custom patron field value