From 368670cda7c7456d6701c3602846a6b5d4c605ec Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 28 Apr 2017 08:46:59 -0400 Subject: [PATCH] Bug 12461 - DBRev 16.12.00.027 Signed-off-by: Kyle M Hall --- Koha.pm | 2 +- Koha/Schema/Result/Club.pm | 19 ++- Koha/Schema/Result/ClubTemplateField.pm | 19 ++- .../data/mysql/atomicupdate/bug_12461.sql | 131 ------------------ installer/data/mysql/updatedatabase.pl | 129 +++++++++++++++++ 5 files changed, 164 insertions(+), 136 deletions(-) delete mode 100644 installer/data/mysql/atomicupdate/bug_12461.sql diff --git a/Koha.pm b/Koha.pm index efcd4feea2..5078edcfcf 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 = "16.12.00.026"; +$VERSION = "16.12.00.027"; sub version { return $VERSION; diff --git a/Koha/Schema/Result/Club.pm b/Koha/Schema/Result/Club.pm index f1b249818e..ae2368d41a 100644 --- a/Koha/Schema/Result/Club.pm +++ b/Koha/Schema/Result/Club.pm @@ -158,6 +158,21 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +=head2 club_fields + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "club_fields", + "Koha::Schema::Result::ClubField", + { "foreign.club_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 club_template Type: belongs_to @@ -174,8 +189,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2017-04-26 16:17:25 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:H7MVPMvbDxo++sKrggmUyA +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2017-04-27 18:47:08 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:RKvHFP2y+c5hjpjzKsEQXA # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/Koha/Schema/Result/ClubTemplateField.pm b/Koha/Schema/Result/ClubTemplateField.pm index 8892eb8177..3485ef371b 100644 --- a/Koha/Schema/Result/ClubTemplateField.pm +++ b/Koha/Schema/Result/ClubTemplateField.pm @@ -80,6 +80,21 @@ __PACKAGE__->set_primary_key("id"); =head1 RELATIONS +=head2 club_fields + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "club_fields", + "Koha::Schema::Result::ClubField", + { "foreign.club_template_field_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 club_template Type: belongs_to @@ -96,8 +111,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2017-04-26 16:17:25 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:xhCyOHUrXuU+UoHeGk1ZKw +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2017-04-27 18:47:08 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:pZ/iYdUn2LUeDNI2I+h+hQ # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/installer/data/mysql/atomicupdate/bug_12461.sql b/installer/data/mysql/atomicupdate/bug_12461.sql deleted file mode 100644 index f038ba5ccb..0000000000 --- a/installer/data/mysql/atomicupdate/bug_12461.sql +++ /dev/null @@ -1,131 +0,0 @@ --- --- Table structure for table 'club_templates' --- - -CREATE TABLE IF NOT EXISTS club_templates ( - id int(11) NOT NULL AUTO_INCREMENT, - `name` tinytext NOT NULL, - description text, - is_enrollable_from_opac tinyint(1) NOT NULL DEFAULT '0', - is_email_required tinyint(1) NOT NULL DEFAULT '0', - branchcode varchar(10) NULL DEFAULT NULL, - date_created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - date_updated timestamp NULL DEFAULT NULL, - is_deletable tinyint(1) NOT NULL DEFAULT '1', - PRIMARY KEY (id), - KEY ct_branchcode (branchcode), - CONSTRAINT `club_templates_ibfk_1` FOREIGN KEY (branchcode) REFERENCES `branches` (branchcode) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; - --- --- Table structure for table 'clubs' --- - -CREATE TABLE IF NOT EXISTS clubs ( - id int(11) NOT NULL AUTO_INCREMENT, - club_template_id int(11) NOT NULL, - `name` tinytext NOT NULL, - description text, - date_start date DEFAULT NULL, - date_end date DEFAULT NULL, - branchcode varchar(10) NULL DEFAULT NULL, - date_created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - date_updated timestamp NULL DEFAULT NULL, - PRIMARY KEY (id), - KEY club_template_id (club_template_id), - KEY branchcode (branchcode), - CONSTRAINT clubs_ibfk_1 FOREIGN KEY (club_template_id) REFERENCES club_templates (id) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT clubs_ibfk_2 FOREIGN KEY (branchcode) REFERENCES branches (branchcode) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; - --- --- Table structure for table 'club_enrollments' --- - -CREATE TABLE IF NOT EXISTS club_enrollments ( - id int(11) NOT NULL AUTO_INCREMENT, - club_id int(11) NOT NULL, - borrowernumber int(11) NOT NULL, - date_enrolled timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - date_canceled timestamp NULL DEFAULT NULL, - date_created timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', - date_updated timestamp NULL DEFAULT NULL, - branchcode varchar(10) NULL DEFAULT NULL, - PRIMARY KEY (id), - KEY club_id (club_id), - KEY borrowernumber (borrowernumber), - KEY branchcode (branchcode), - CONSTRAINT club_enrollments_ibfk_1 FOREIGN KEY (club_id) REFERENCES clubs (id) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT club_enrollments_ibfk_2 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT club_enrollments_ibfk_3 FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; - --- --- Table structure for table 'club_template_enrollment_fields' --- - -CREATE TABLE IF NOT EXISTS club_template_enrollment_fields ( - id int(11) NOT NULL AUTO_INCREMENT, - club_template_id int(11) NOT NULL, - `name` tinytext NOT NULL, - description text, - authorised_value_category varchar(16) DEFAULT NULL, - PRIMARY KEY (id), - KEY club_template_id (club_template_id), - CONSTRAINT club_template_enrollment_fields_ibfk_1 FOREIGN KEY (club_template_id) REFERENCES club_templates (id) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; - --- --- Table structure for table 'club_enrollment_fields' --- - -CREATE TABLE IF NOT EXISTS club_enrollment_fields ( - id int(11) NOT NULL AUTO_INCREMENT, - club_enrollment_id int(11) NOT NULL, - club_template_enrollment_field_id int(11) NOT NULL, - `value` text NOT NULL, - PRIMARY KEY (id), - KEY club_enrollment_id (club_enrollment_id), - KEY club_template_enrollment_field_id (club_template_enrollment_field_id), - CONSTRAINT club_enrollment_fields_ibfk_1 FOREIGN KEY (club_enrollment_id) REFERENCES club_enrollments (id) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT club_enrollment_fields_ibfk_2 FOREIGN KEY (club_template_enrollment_field_id) REFERENCES club_template_enrollment_fields (id) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; - --- --- Table structure for table 'club_template_fields' --- - -CREATE TABLE IF NOT EXISTS club_template_fields ( - id int(11) NOT NULL AUTO_INCREMENT, - club_template_id int(11) NOT NULL, - `name` tinytext NOT NULL, - description text, - authorised_value_category varchar(16) DEFAULT NULL, - PRIMARY KEY (id), - KEY club_template_id (club_template_id), - CONSTRAINT club_template_fields_ibfk_1 FOREIGN KEY (club_template_id) REFERENCES club_templates (id) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; - --- --- Table structure for table 'club_fields' --- - -CREATE TABLE IF NOT EXISTS club_fields ( - id int(11) NOT NULL AUTO_INCREMENT, - club_template_field_id int(11) NOT NULL, - club_id int(11) NOT NULL, - `value` text, - PRIMARY KEY (id), - KEY club_template_field_id (club_template_field_id), - KEY club_id (club_id), - CONSTRAINT club_fields_ibfk_3 FOREIGN KEY (club_template_field_id) REFERENCES club_template_fields (id) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT club_fields_ibfk_4 FOREIGN KEY (club_id) REFERENCES clubs (id) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; - -INSERT IGNORE INTO userflags (bit, flag, flagdesc, defaulton) VALUES (21, 'clubs', 'Patron clubs', '0'); - -INSERT IGNORE INTO permissions (module_bit, code, description) VALUES - (21, 'edit_templates', 'Create and update club templates'), - (21, 'edit_clubs', 'Create and update clubs'), - (21, 'enroll', 'Enroll patrons in clubs') -; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index a1ea65d3e2..3c2ccc1c1f 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -14152,6 +14152,135 @@ if( CheckVersion( $DBversion ) ) { print "Upgrade to $DBversion done (Bug 18427 - Add a primary key to serialitems)\n"; } +$DBversion = '16.12.00.027'; +if( CheckVersion( $DBversion ) ) { + + $dbh->do(q{ + CREATE TABLE IF NOT EXISTS club_templates ( + id int(11) NOT NULL AUTO_INCREMENT, + `name` tinytext NOT NULL, + description text, + is_enrollable_from_opac tinyint(1) NOT NULL DEFAULT '0', + is_email_required tinyint(1) NOT NULL DEFAULT '0', + branchcode varchar(10) NULL DEFAULT NULL, + date_created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + date_updated timestamp NULL DEFAULT NULL, + is_deletable tinyint(1) NOT NULL DEFAULT '1', + PRIMARY KEY (id), + KEY ct_branchcode (branchcode), + CONSTRAINT `club_templates_ibfk_1` FOREIGN KEY (branchcode) REFERENCES `branches` (branchcode) ON DELETE CASCADE ON UPDATE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + }); + + $dbh->do(q{ + CREATE TABLE IF NOT EXISTS clubs ( + id int(11) NOT NULL AUTO_INCREMENT, + club_template_id int(11) NOT NULL, + `name` tinytext NOT NULL, + description text, + date_start date DEFAULT NULL, + date_end date DEFAULT NULL, + branchcode varchar(10) NULL DEFAULT NULL, + date_created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + date_updated timestamp NULL DEFAULT NULL, + PRIMARY KEY (id), + KEY club_template_id (club_template_id), + KEY branchcode (branchcode), + CONSTRAINT clubs_ibfk_1 FOREIGN KEY (club_template_id) REFERENCES club_templates (id) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT clubs_ibfk_2 FOREIGN KEY (branchcode) REFERENCES branches (branchcode) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + }); + + $dbh->do(q{ + CREATE TABLE IF NOT EXISTS club_enrollments ( + id int(11) NOT NULL AUTO_INCREMENT, + club_id int(11) NOT NULL, + borrowernumber int(11) NOT NULL, + date_enrolled timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + date_canceled timestamp NULL DEFAULT NULL, + date_created timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + date_updated timestamp NULL DEFAULT NULL, + branchcode varchar(10) NULL DEFAULT NULL, + PRIMARY KEY (id), + KEY club_id (club_id), + KEY borrowernumber (borrowernumber), + KEY branchcode (branchcode), + CONSTRAINT club_enrollments_ibfk_1 FOREIGN KEY (club_id) REFERENCES clubs (id) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT club_enrollments_ibfk_2 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT club_enrollments_ibfk_3 FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE SET NULL ON UPDATE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + }); + + $dbh->do(q{ + CREATE TABLE IF NOT EXISTS club_template_enrollment_fields ( + id int(11) NOT NULL AUTO_INCREMENT, + club_template_id int(11) NOT NULL, + `name` tinytext NOT NULL, + description text, + authorised_value_category varchar(16) DEFAULT NULL, + PRIMARY KEY (id), + KEY club_template_id (club_template_id), + CONSTRAINT club_template_enrollment_fields_ibfk_1 FOREIGN KEY (club_template_id) REFERENCES club_templates (id) ON DELETE CASCADE ON UPDATE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + }); + + $dbh->do(q{ + CREATE TABLE IF NOT EXISTS club_enrollment_fields ( + id int(11) NOT NULL AUTO_INCREMENT, + club_enrollment_id int(11) NOT NULL, + club_template_enrollment_field_id int(11) NOT NULL, + `value` text NOT NULL, + PRIMARY KEY (id), + KEY club_enrollment_id (club_enrollment_id), + KEY club_template_enrollment_field_id (club_template_enrollment_field_id), + CONSTRAINT club_enrollment_fields_ibfk_1 FOREIGN KEY (club_enrollment_id) REFERENCES club_enrollments (id) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT club_enrollment_fields_ibfk_2 FOREIGN KEY (club_template_enrollment_field_id) REFERENCES club_template_enrollment_fields (id) ON DELETE CASCADE ON UPDATE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + }); + + $dbh->do(q{ + CREATE TABLE IF NOT EXISTS club_template_fields ( + id int(11) NOT NULL AUTO_INCREMENT, + club_template_id int(11) NOT NULL, + `name` tinytext NOT NULL, + description text, + authorised_value_category varchar(16) DEFAULT NULL, + PRIMARY KEY (id), + KEY club_template_id (club_template_id), + CONSTRAINT club_template_fields_ibfk_1 FOREIGN KEY (club_template_id) REFERENCES club_templates (id) ON DELETE CASCADE ON UPDATE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + }); + + $dbh->do(q{ + CREATE TABLE IF NOT EXISTS club_fields ( + id int(11) NOT NULL AUTO_INCREMENT, + club_template_field_id int(11) NOT NULL, + club_id int(11) NOT NULL, + `value` text, + PRIMARY KEY (id), + KEY club_template_field_id (club_template_field_id), + KEY club_id (club_id), + CONSTRAINT club_fields_ibfk_3 FOREIGN KEY (club_template_field_id) REFERENCES club_template_fields (id) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT club_fields_ibfk_4 FOREIGN KEY (club_id) REFERENCES clubs (id) ON DELETE CASCADE ON UPDATE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + }); + + $dbh->do(q{ + INSERT IGNORE INTO userflags (bit, flag, flagdesc, defaulton) VALUES (21, 'clubs', 'Patron clubs', '0'); + }); + + $dbh->do(q{ + INSERT IGNORE INTO permissions (module_bit, code, description) VALUES + (21, 'edit_templates', 'Create and update club templates'), + (21, 'edit_clubs', 'Create and update clubs'), + (21, 'enroll', 'Enroll patrons in clubs') + ; + }); + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 12461 - Add patron clubs feature)\n"; +} + # 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