From aebf7f2756c585512576ea5dc3ff03f17ba1610a Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 10 Nov 2020 08:46:18 -0300 Subject: [PATCH] Bug 23916: (QA follow-up) Rename issuer => issuer_id [DB] Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart --- Koha/Schema/Result/Borrower.pm | 34 +++++++++++++++++-- Koha/Schema/Result/Issue.pm | 32 +++++++++++++++-- Koha/Schema/Result/OldIssue.pm | 32 +++++++++++++++-- .../bug_23916_add_issues_issuer.perl | 11 +++--- installer/data/mysql/kohastructure.sql | 8 ++--- 5 files changed, 101 insertions(+), 16 deletions(-) diff --git a/Koha/Schema/Result/Borrower.pm b/Koha/Schema/Result/Borrower.pm index 8c2dcc20c6..08f974d0ff 100644 --- a/Koha/Schema/Result/Borrower.pm +++ b/Koha/Schema/Result/Borrower.pm @@ -1157,6 +1157,21 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +=head2 issues_issuers + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "issues_issuers", + "Koha::Schema::Result::Issue", + { "foreign.issuer_id" => "self.borrowernumber" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 items_last_borrowers Type: has_many @@ -1232,6 +1247,21 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +=head2 old_issues_issuers + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "old_issues_issuers", + "Koha::Schema::Result::OldIssue", + { "foreign.issuer_id" => "self.borrowernumber" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 old_reserves Type: has_many @@ -1683,8 +1713,8 @@ Composing rels: L -> ordernumber __PACKAGE__->many_to_many("ordernumbers", "aqorder_users", "ordernumber"); -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2020-10-08 14:17:29 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:kzx7ildKCEFF6YDr6MRCrw +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2020-11-09 19:12:25 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Kp53XFs7tFIpzNSqm/WY8w __PACKAGE__->add_columns( '+anonymized' => { is_boolean => 1 }, diff --git a/Koha/Schema/Result/Issue.pm b/Koha/Schema/Result/Issue.pm index 5ffba8af90..0c960144ae 100644 --- a/Koha/Schema/Result/Issue.pm +++ b/Koha/Schema/Result/Issue.pm @@ -35,6 +35,12 @@ __PACKAGE__->table("issues"); is_foreign_key: 1 is_nullable: 1 +=head2 issuer_id + + data_type: 'integer' + is_foreign_key: 1 + is_nullable: 1 + =head2 itemnumber data_type: 'integer' @@ -125,6 +131,8 @@ __PACKAGE__->add_columns( { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, "borrowernumber", { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, + "issuer_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "itemnumber", { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "date_due", @@ -228,6 +236,26 @@ __PACKAGE__->belongs_to( }, ); +=head2 issuer + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "issuer", + "Koha::Schema::Result::Borrower", + { borrowernumber => "issuer_id" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "SET NULL", + on_update => "CASCADE", + }, +); + =head2 itemnumber Type: belongs_to @@ -264,8 +292,8 @@ __PACKAGE__->might_have( ); -# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-10-31 12:18:38 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:QVmFa5b0Pe5OhUI92n9kzQ +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2020-11-09 19:12:26 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Z0qpsT632VLwejUFjIO/ag __PACKAGE__->add_columns( '+auto_renew' => { is_boolean => 1 }, diff --git a/Koha/Schema/Result/OldIssue.pm b/Koha/Schema/Result/OldIssue.pm index 6e5b6e81b3..c0271b3529 100644 --- a/Koha/Schema/Result/OldIssue.pm +++ b/Koha/Schema/Result/OldIssue.pm @@ -34,6 +34,12 @@ __PACKAGE__->table("old_issues"); is_foreign_key: 1 is_nullable: 1 +=head2 issuer_id + + data_type: 'integer' + is_foreign_key: 1 + is_nullable: 1 + =head2 itemnumber data_type: 'integer' @@ -124,6 +130,8 @@ __PACKAGE__->add_columns( { data_type => "integer", is_nullable => 0 }, "borrowernumber", { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, + "issuer_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "itemnumber", { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "date_due", @@ -213,6 +221,26 @@ __PACKAGE__->belongs_to( }, ); +=head2 issuer + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "issuer", + "Koha::Schema::Result::Borrower", + { borrowernumber => "issuer_id" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "SET NULL", + on_update => "CASCADE", + }, +); + =head2 itemnumber Type: belongs_to @@ -234,8 +262,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-04-10 19:55:44 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:E2N2paWcCHg916100ry+2A +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2020-11-09 19:12:26 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:jlgsHwZKoVn/HJD1NP1gqg __PACKAGE__->add_columns( '+auto_renew' => { is_boolean => 1 }, diff --git a/installer/data/mysql/atomicupdate/bug_23916_add_issues_issuer.perl b/installer/data/mysql/atomicupdate/bug_23916_add_issues_issuer.perl index 08ede0aa74..d3d2095f53 100644 --- a/installer/data/mysql/atomicupdate/bug_23916_add_issues_issuer.perl +++ b/installer/data/mysql/atomicupdate/bug_23916_add_issues_issuer.perl @@ -1,18 +1,17 @@ $DBversion = 'XXX'; # will be replaced by the RM if( CheckVersion( $DBversion ) ) { if( !column_exists( 'issues', 'issuer' ) ) { - $dbh->do( q| ALTER TABLE issues ADD issuer INT(11) DEFAULT NULL AFTER borrowernumber | ); + $dbh->do( q| ALTER TABLE issues ADD issuer_id INT(11) DEFAULT NULL AFTER borrowernumber | ); } if (!foreign_key_exists( 'issues', 'issues_ibfk_borrowers_borrowernumber' )) { - $dbh->do( q| ALTER TABLE issues ADD CONSTRAINT `issues_ibfk_borrowers_borrowernumber` FOREIGN KEY (`issuer`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE | ); + $dbh->do( q| ALTER TABLE issues ADD CONSTRAINT `issues_ibfk_borrowers_borrowernumber` FOREIGN KEY (`issuer_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE | ); } if( !column_exists( 'old_issues', 'issuer' ) ) { - $dbh->do( q| ALTER TABLE old_issues ADD issuer INT(11) DEFAULT NULL AFTER borrowernumber | ); + $dbh->do( q| ALTER TABLE old_issues ADD issuer_id INT(11) DEFAULT NULL AFTER borrowernumber | ); } if (!foreign_key_exists( 'old_issues', 'old_issues_ibfk_borrowers_borrowernumber' )) { - $dbh->do( q| ALTER TABLE old_issues ADD CONSTRAINT `old_issues_ibfk_borrowers_borrowernumber` FOREIGN KEY (`issuer`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE | ); + $dbh->do( q| ALTER TABLE old_issues ADD CONSTRAINT `old_issues_ibfk_borrowers_borrowernumber` FOREIGN KEY (`issuer_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE | ); } - SetVersion( $DBversion ); - print "Upgrade to $DBversion done (Bug 23916 - Add issues.issuer)\n"; + NewVersion( $DBversion, 23916, "Add issues.issuer"; } diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 6087b42159..fbf442ad76 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1618,7 +1618,7 @@ DROP TABLE IF EXISTS `issues`; CREATE TABLE `issues` ( -- information related to check outs or issues `issue_id` int(11) NOT NULL AUTO_INCREMENT, -- primary key for issues table `borrowernumber` int(11), -- foreign key, linking this to the borrowers table for the patron this item was checked out to - `issuer` int(11) default NULL, -- foreign key, linking this to the borrowers table for the user who checked out this item + `issuer_id` INT(11) NULL DEFAULT NULL, -- foreign key, linking this to the borrowers table for the user who checked out this item `itemnumber` int(11), -- foreign key, linking this to the items table for the item that was checked out `date_due` datetime default NULL, -- datetime the item is due (yyyy-mm-dd hh:mm::ss) `branchcode` varchar(10) default NULL, -- foreign key, linking to the branches table for the location the item was checked out @@ -1641,7 +1641,7 @@ CREATE TABLE `issues` ( -- information related to check outs or issues KEY `bordate` (`borrowernumber`,`timestamp`), CONSTRAINT `issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE RESTRICT ON UPDATE CASCADE, CONSTRAINT `issues_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT `issues_ibfk_borrowers_borrowernumber` FOREIGN KEY (`issuer`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE + CONSTRAINT `issues_ibfk_borrowers_borrowernumber` FOREIGN KEY (`issuer_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- @@ -1652,7 +1652,7 @@ DROP TABLE IF EXISTS `old_issues`; CREATE TABLE `old_issues` ( -- lists items that were checked out and have been returned `issue_id` int(11) NOT NULL, -- primary key for issues table `borrowernumber` int(11) default NULL, -- foreign key, linking this to the borrowers table for the patron this item was checked out to - `issuer` int(11) default NULL, -- foreign key, linking this to the borrowers table for the user who checked out this item + `issuer_id` INT(11) NULL DEFAULT NULL, -- foreign key, linking this to the borrowers table for the user who checked out this item `itemnumber` int(11) default NULL, -- foreign key, linking this to the items table for the item that was checked out `date_due` datetime default NULL, -- date the item is due (yyyy-mm-dd) `branchcode` varchar(10) default NULL, -- foreign key, linking to the branches table for the location the item was checked out @@ -1676,7 +1676,7 @@ CREATE TABLE `old_issues` ( -- lists items that were checked out and have been r ON DELETE SET NULL ON UPDATE SET NULL, CONSTRAINT `old_issues_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE SET NULL ON UPDATE SET NULL, - CONSTRAINT `old_issues_ibfk_borrowers_borrowernumber` FOREIGN KEY (`issuer`) REFERENCES `borrowers` (`borrowernumber`) + CONSTRAINT `old_issues_ibfk_borrowers_borrowernumber` FOREIGN KEY (`issuer_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- 2.39.5