From fba064838403961cffaaaa95bd7c41bd4c98c678 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 6 Jul 2018 14:19:22 +0000 Subject: [PATCH] Bug 12395: DBRev 18.06.00.005 Signed-off-by: Nick Clemens --- Koha.pm | 2 +- Koha/Schema/Result/Aqorder.pm | 32 +++++++++++++++++-- Koha/Schema/Result/Borrower.pm | 19 +++++++++-- ...g-12395-add-column-aqorders.created_by.sql | 3 -- installer/data/mysql/updatedatabase.pl | 9 ++++++ 5 files changed, 57 insertions(+), 8 deletions(-) delete mode 100644 installer/data/mysql/atomicupdate/Bug-12395-add-column-aqorders.created_by.sql diff --git a/Koha.pm b/Koha.pm index e92189f04b..0c7e91d66a 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 = "18.06.00.004"; +$VERSION = "18.06.00.005"; sub version { return $VERSION; diff --git a/Koha/Schema/Result/Aqorder.pm b/Koha/Schema/Result/Aqorder.pm index bafbe91b7f..174f3a68c8 100644 --- a/Koha/Schema/Result/Aqorder.pm +++ b/Koha/Schema/Result/Aqorder.pm @@ -101,6 +101,12 @@ __PACKAGE__->table("aqorders"); default_value: 0 is_nullable: 0 +=head2 created_by + + data_type: 'integer' + is_foreign_key: 1 + is_nullable: 1 + =head2 datecancellationprinted data_type: 'date' @@ -341,6 +347,8 @@ __PACKAGE__->add_columns( { data_type => "decimal", is_nullable => 1, size => [28, 6] }, "quantityreceived", { data_type => "smallint", default_value => 0, is_nullable => 0 }, + "created_by", + { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "datecancellationprinted", { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 }, "cancellationreason", @@ -554,6 +562,26 @@ __PACKAGE__->belongs_to( { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, ); +=head2 created_by + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "created_by", + "Koha::Schema::Result::Borrower", + { borrowernumber => "created_by" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "SET NULL", + on_update => "CASCADE", + }, +); + =head2 currency Type: belongs_to @@ -625,8 +653,8 @@ Composing rels: L -> borrowernumber __PACKAGE__->many_to_many("borrowernumbers", "aqorder_users", "borrowernumber"); -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:53 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:K0GnMGYtZUQ1WCesHKIxHw +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-07-06 14:12:40 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:/CljC8eGYHoYM3506qYavg # You can replace this text with custom code or comments, and it will be preserved on regeneration diff --git a/Koha/Schema/Result/Borrower.pm b/Koha/Schema/Result/Borrower.pm index b739284068..8663b8654b 100644 --- a/Koha/Schema/Result/Borrower.pm +++ b/Koha/Schema/Result/Borrower.pm @@ -770,6 +770,21 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +=head2 aqorders + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "aqorders", + "Koha::Schema::Result::Aqorder", + { "foreign.created_by" => "self.borrowernumber" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 article_requests Type: has_many @@ -1401,8 +1416,8 @@ Composing rels: L -> ordernumber __PACKAGE__->many_to_many("ordernumbers", "aqorder_users", "ordernumber"); -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-04-11 19:53:27 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:/vLIMxDv4RcJOqKj6Mfg6w +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-07-06 14:12:40 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:LaQWPXzF1Amzt8fgEEyHdg __PACKAGE__->belongs_to( "guarantor", diff --git a/installer/data/mysql/atomicupdate/Bug-12395-add-column-aqorders.created_by.sql b/installer/data/mysql/atomicupdate/Bug-12395-add-column-aqorders.created_by.sql deleted file mode 100644 index 84a0f5d48b..0000000000 --- a/installer/data/mysql/atomicupdate/Bug-12395-add-column-aqorders.created_by.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE aqorders ADD COLUMN created_by int(11) NULL DEFAULT NULL AFTER quantityreceived; -ALTER TABLE aqorders ADD CONSTRAINT aqorders_created_by FOREIGN KEY (created_by) REFERENCES borrowers (borrowernumber) ON DELETE SET NULL ON UPDATE CASCADE; -UPDATE aqorders, aqbasket SET aqorders.created_by = aqbasket.authorisedby WHERE aqorders.basketno = aqbasket.basketno; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index cb6c225e1d..20ae89dc80 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -16127,6 +16127,15 @@ if( CheckVersion( $DBversion ) ) { print "Upgrade to $DBversion done (Bug 20980 - Manual credit offsets are stored as debits)\n"; } +$DBversion = '18.06.00.005'; +if( CheckVersion( $DBversion ) ) { + $dbh->do( "ALTER TABLE aqorders ADD COLUMN created_by int(11) NULL DEFAULT NULL AFTER quantityreceived;" ); + $dbh->do( "ALTER TABLE aqorders ADD CONSTRAINT aqorders_created_by FOREIGN KEY (created_by) REFERENCES borrowers (borrowernumber) ON DELETE SET NULL ON UPDATE CASCADE;" ); + $dbh->do( "UPDATE aqorders, aqbasket SET aqorders.created_by = aqbasket.authorisedby WHERE aqorders.basketno = aqbasket.basketno;" ); + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 12395 - Save order line's creator)\n"; +} + # SEE bug 13068 # if there is anything in the atomicupdate, read and execute it. -- 2.39.5