Bug 12395: DBRev 18.06.00.005
authorNick Clemens <nick@bywatersolutions.com>
Fri, 6 Jul 2018 14:19:22 +0000 (14:19 +0000)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 6 Jul 2018 14:19:22 +0000 (14:19 +0000)
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Koha.pm
Koha/Schema/Result/Aqorder.pm
Koha/Schema/Result/Borrower.pm
installer/data/mysql/atomicupdate/Bug-12395-add-column-aqorders.created_by.sql [deleted file]
installer/data/mysql/updatedatabase.pl

diff --git a/Koha.pm b/Koha.pm
index e92189f..0c7e91d 100644 (file)
--- 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;
index bafbe91..174f3a6 100644 (file)
@@ -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<Koha::Schema::Result::Borrower>
+
+=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</aqorder_users> -> 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
index b739284..8663b86 100644 (file)
@@ -770,6 +770,21 @@ __PACKAGE__->has_many(
   { cascade_copy => 0, cascade_delete => 0 },
 );
 
+=head2 aqorders
+
+Type: has_many
+
+Related object: L<Koha::Schema::Result::Aqorder>
+
+=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</aqorder_users> -> 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 (file)
index 84a0f5d..0000000
+++ /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;
index cb6c225..20ae89d 100755 (executable)
@@ -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.