From 4b9598d4042e07cd4be5c03f3cd40d21136caa57 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 29 Aug 2013 13:28:44 +0200 Subject: [PATCH] Bug 10855: Update database entry Add 2 tables: additional_fields and additional_field_values --- installer/data/mysql/kohastructure.sql | 30 ++++++++++++++++++++++++ installer/data/mysql/updatedatabase.pl | 39 +++++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index e1e3e96..c881f13 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -3275,6 +3275,36 @@ ALTER TABLE `patron_list_patrons` ADD CONSTRAINT patron_list_patrons_ibfk_1 FOREIGN KEY (patron_list_id) REFERENCES patron_lists (patron_list_id) ON DELETE CASCADE ON UPDATE CASCADE, ADD CONSTRAINT patron_list_patrons_ibfk_2 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE; +-- +-- Table structure for table addition_fields +-- This table add the ability to add new fields for a record +-- + +CREATE TABLE `additional_fields` ( + `id` int(11) NOT NULL AUTO_INCREMENT, -- primary key identifier + `tablename` varchar(255) NOT NULL DEFAULT '', -- tablename of the new field + `name` varchar(255) NOT NULL DEFAULT '', -- name of the field + `authorised_value_category` varchar(16) NOT NULL DEFAULT '', -- is an authorised value category + `marcfield` varchar(16) NOT NULL DEFAULT '', -- contains the marc field to copied into the record + `searchable` tinyint(1) NOT NULL DEFAULT '0', -- is the field searchable? + PRIMARY KEY (`id`), + UNIQUE KEY `fields_uniq` (`tablename`,`name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 | + +-- +-- Table structure for table addition_field_values +-- This table store values for additional fields +-- + +CREATE TABLE `additional_field_values` ( + `id` int(11) NOT NULL AUTO_INCREMENT, -- primary key identifier + `field_id` int(11) NOT NULL, -- foreign key references addition_fields(id) + `record_id` int(11) NOT NULL, -- record_id + `value` varchar(255) NOT NULL DEFAULT '', -- value for this field + PRIMARY KEY (`id`), + UNIQUE KEY `field_record` (`field_id`,`record_id`), + CONSTRAINT `afv_fk` FOREIGN KEY (`field_id`) REFERENCES `additional_fields` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 | /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 9f57eff..a172da8 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -7130,7 +7130,6 @@ 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')"); @@ -7306,6 +7305,44 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } + + + + + + + + + +$DBversion = "3.13.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do(q| + CREATE TABLE `additional_fields` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `tablename` varchar(255) NOT NULL DEFAULT '', + `name` varchar(255) NOT NULL DEFAULT '', + `authorised_value_category` varchar(16) NOT NULL DEFAULT '', + `marcfield` varchar(16) NOT NULL DEFAULT '', + `searchable` tinyint(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`), + UNIQUE KEY `fields_uniq` (`tablename`,`name`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 + |); + $dbh->do(q| + CREATE TABLE `additional_field_values` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `field_id` int(11) NOT NULL, + `record_id` int(11) NOT NULL, + `value` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', + PRIMARY KEY (`id`), + UNIQUE KEY `field_record` (`field_id`,`record_id`), + CONSTRAINT `afv_fk` FOREIGN KEY (`field_id`) REFERENCES `additional_fields` (`id`) ON DELETE CASCADE ON UPDATE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 + |); + print "Upgrade to $DBversion done (Bug 10855: Add tables additional_fields and additional_field_values)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) -- 1.7.10.4