From eb73c935109d067645f824047200228a6f51a74b Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Wed, 1 Feb 2017 15:53:06 +0100
Subject: [PATCH] Bug 14224: Check if the columns do not exist before creating
 them
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Marc VĂ©ron <veron@veron.ch>
---
 .../atomicupdate/bug_14224-add_new_issue_columns.perl  | 18 ++++++++++++++++++
 .../atomicupdate/bug_14224-add_new_issue_columns.sql   |  4 ----
 2 files changed, 18 insertions(+), 4 deletions(-)
 create mode 100644 installer/data/mysql/atomicupdate/bug_14224-add_new_issue_columns.perl
 delete mode 100644 installer/data/mysql/atomicupdate/bug_14224-add_new_issue_columns.sql

diff --git a/installer/data/mysql/atomicupdate/bug_14224-add_new_issue_columns.perl b/installer/data/mysql/atomicupdate/bug_14224-add_new_issue_columns.perl
new file mode 100644
index 0000000..eaf8a98
--- /dev/null
+++ b/installer/data/mysql/atomicupdate/bug_14224-add_new_issue_columns.perl
@@ -0,0 +1,18 @@
+$DBversion = 'XXX';
+if( CheckVersion( $DBversion ) ) {
+    unless( column_exists( 'issues', 'note' ) ) {
+        $dbh->do(q|ALTER TABLE issues ADD note mediumtext default NULL AFTER onsite_checkout|);
+    }
+    unless( column_exists( 'issues', 'notedate' ) ) {
+        $dbh->do(q|ALTER TABLE issues ADD notedate datetime default NULL AFTER note|);
+    }
+    unless( column_exists( 'old_issues', 'note' ) ) {
+        $dbh->do(q|ALTER TABLE old_issues ADD note mediumtext default NULL AFTER onsite_checkout|);
+    }
+    unless( column_exists( 'old_issues', 'notedate' ) ) {
+        $dbh->do(q|ALTER TABLE old_issues ADD notedate datetime default NULL AFTER note|);
+    }
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 14224: Add column issues.note and issues.notedate)\n";
+}
diff --git a/installer/data/mysql/atomicupdate/bug_14224-add_new_issue_columns.sql b/installer/data/mysql/atomicupdate/bug_14224-add_new_issue_columns.sql
deleted file mode 100644
index 6ed41dc..0000000
--- a/installer/data/mysql/atomicupdate/bug_14224-add_new_issue_columns.sql
+++ /dev/null
@@ -1,4 +0,0 @@
-ALTER IGNORE TABLE issues ADD `note` mediumtext default NULL AFTER `onsite_checkout`;
-ALTER IGNORE TABLE issues ADD `notedate` datetime default NULL AFTER `note`;
-ALTER IGNORE TABLE old_issues ADD `note` mediumtext default NULL AFTER `onsite_checkout`;
-ALTER IGNORE TABLE old_issues ADD `notedate` datetime default NULL AFTER `note`;
-- 
2.1.4