From e6605d51cd5d0ef691c3a186c9128bc1a19599c9 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Tue, 30 Aug 2016 11:55:52 +0100
Subject: [PATCH] [SIGNED-OFF] Bug 17216: Add FK on authorised_values.category
Content-Type: text/plain; charset="utf-8"

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
---
 installer/data/mysql/atomicupdate/bug_17216_1_add_table.sql | 2 ++
 installer/data/mysql/kohastructure.sql                      | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/installer/data/mysql/atomicupdate/bug_17216_1_add_table.sql b/installer/data/mysql/atomicupdate/bug_17216_1_add_table.sql
index cc5ac6e..07dcb83 100644
--- a/installer/data/mysql/atomicupdate/bug_17216_1_add_table.sql
+++ b/installer/data/mysql/atomicupdate/bug_17216_1_add_table.sql
@@ -45,3 +45,5 @@ ALTER TABLE items_search_fields
     DROP FOREIGN KEY items_search_fields_authorised_values_category;
 ALTER TABLE items_search_fields
     ADD CONSTRAINT `items_search_fields_authorised_values_category` FOREIGN KEY (`authorised_values_category`) REFERENCES `authorised_value_categories` (`category_name`) ON DELETE SET NULL ON UPDATE CASCADE;
+ALTER TABLE authorised_values
+    ADD CONSTRAINT `authorised_values_authorised_values_category` FOREIGN KEY (`category`) REFERENCES `authorised_value_categories` (`category_name`) ON DELETE CASCADE ON UPDATE CASCADE;
diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index 46f0828..13fb6dc 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -118,7 +118,8 @@ CREATE TABLE `authorised_values` ( -- stores values for authorized values catego
   PRIMARY KEY  (`id`),
   KEY `name` (`category`),
   KEY `lib` (`lib`),
-  KEY `auth_value_idx` (`authorised_value`)
+  KEY `auth_value_idx` (`authorised_value`),
+  CONSTRAINT `authorised_values_authorised_values_category` FOREIGN KEY (`category`) REFERENCES `authorised_value_categories` (`category_name`) ON DELETE CASCADE ON UPDATE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
 
 --
-- 
2.1.4