From e88457a9fab442979a7422ce33970b60753cfc06 Mon Sep 17 00:00:00 2001 From: Brendan A Gallagher Date: Thu, 3 Mar 2016 21:15:14 +0000 Subject: [PATCH] DBRev Bug 15084 - Move the currency related code to Koha::Acquisition::Currenc[y|ies] --- Koha.pm | 2 +- .../bug_15084-add_fk_for_currency.sql | 8 ------- installer/data/mysql/updatedatabase.pl | 23 +++++++++++++++++++ 3 files changed, 24 insertions(+), 9 deletions(-) delete mode 100644 installer/data/mysql/atomicupdate/bug_15084-add_fk_for_currency.sql diff --git a/Koha.pm b/Koha.pm index 97856b80d7..9dcb9a0174 100644 --- a/Koha.pm +++ b/Koha.pm @@ -29,7 +29,7 @@ use vars qw{ $VERSION }; # - #4 : the developer version. The 4th number is the database subversion. # used by developers when the database changes. updatedatabase take care of the changes itself # and is automatically called by Auth.pm when needed. -$VERSION = "3.23.00.036"; +$VERSION = "3.23.00.037"; sub version { return $VERSION; diff --git a/installer/data/mysql/atomicupdate/bug_15084-add_fk_for_currency.sql b/installer/data/mysql/atomicupdate/bug_15084-add_fk_for_currency.sql deleted file mode 100644 index d3e00c106e..0000000000 --- a/installer/data/mysql/atomicupdate/bug_15084-add_fk_for_currency.sql +++ /dev/null @@ -1,8 +0,0 @@ --- Add the new currency.archived column -alter table currency add column archived tinyint(1) default 0; --- Set currency=NULL if empty (just in case) -update aqorders set currency=NULL where currency=""; --- Insert the missing currency and mark them as archived before adding the FK -insert into currency(currency, archived) select distinct currency, 1 from aqorders where currency not in (select currency from currency); --- And finally add the FK -alter table aqorders add foreign key (currency) references currency(currency) on delete set null on update set null; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 76e5791277..f8b5b32ae6 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -11973,6 +11973,29 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.23.00.037"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { +## Add the new currency.archived column + $dbh->do(q{ + ALTER TABLE currency ADD column archived tinyint(1) DEFAULT 0; + }); +## Set currency=NULL if empty (just in case) + $dbh->do(q{ + UPDATE aqorders SET currency=NULL WHERE currency=""; + }); +## Insert the missing currency and mark them as archived before adding the FK + $dbh->do(q{ + INSERT INTO currency(currency, archived) SELECT distinct currency, 1 FROM aqorders WHERE currency NOT IN (SELECT currency FROM currency); + }); +## And finally add the FK + $dbh->do(q{ + ALTER TABLE aqorders ADD FOREIGN KEY (currency) REFERENCES currency(currency) ON DELETE SET NULL ON UPDATE SET null; + }); + + print "Upgrade to $DBversion done (Bug 15084 - Move the currency related code to Koha::Acquisition::Currenc[y|ies])\n"; + SetVersion($DBversion); + } + # DEVELOPER PROCESS, search for anything to execute in the db_update directory # SEE bug 13068 # if there is anything in the atomicupdate, read and execute it. -- 2.39.5