Bug 32154: Missing primary key on erm_user_roles table
authorPedro Amorim <pedro.amorim@ptfs-europe.com>
Wed, 9 Nov 2022 17:55:20 +0000 (16:55 -0100)
committerTomas Cohen Arazi <tomascohen@theke.io>
Fri, 11 Nov 2022 11:54:34 +0000 (08:54 -0300)
The aforementioned TestBuilder should display "Koha::ERM::UserRole", not be empty.

This patch adds a primary key to the erm_user_roles table and fixes that.

Also includes atomicupdate file to update database schema as well as updates to
kohastructure.sql provided by Jonathan Druart.

Looked into the vue files but didn't find anywhere or a need to include the new
primary key in any of the requests as there is no request of users by role_user_id
being made.

Erm users are being created/updated as a relationship through licenceses/agreements.

Furthermore, when editing a role of an existing user, this new primary key is already
being supplied embeded in the license/agreement.

Test plan:
Add users to license and agreement
Run the cypress tests
Confirm that the change fix the test that was failing in TestBuilder.t
(another one may still fail however)

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
api/v1/swagger/definitions/erm_user_role.yaml
installer/data/mysql/atomicupdate/erm.pl [new file with mode: 0644]
installer/data/mysql/kohastructure.sql

index 7256542..1f84f65 100644 (file)
@@ -1,6 +1,9 @@
 ---
 type: object
 properties:
+  user_role_id:
+    type: integer
+    description: Internal user_role identifier
   agreement_id:
     type:
       - integer
diff --git a/installer/data/mysql/atomicupdate/erm.pl b/installer/data/mysql/atomicupdate/erm.pl
new file mode 100644 (file)
index 0000000..582a1c4
--- /dev/null
@@ -0,0 +1,18 @@
+use Modern::Perl;
+
+return {
+    bug_number => "32030",
+    description => "Add primary key to erm_user_roles",
+    up => sub {
+        my ($args) = @_;
+        my ($dbh, $out) = @$args{qw(dbh out)};
+
+        unless ( column_exists('erm_user_roles', 'user_role_id') ) {
+            $dbh->do(q{
+                ALTER TABLE `erm_user_roles`
+                ADD COLUMN `user_role_id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key' FIRST,
+                ADD PRIMARY KEY(`user_role_id`);
+            });
+        }
+    }
+};
index beb7699..6d343fd 100644 (file)
@@ -2880,13 +2880,15 @@ CREATE TABLE `erm_agreement_periods` (
 
 DROP TABLE IF EXISTS `erm_user_roles`;
 CREATE TABLE `erm_user_roles` (
+    `user_role_id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
     `agreement_id` INT(11) NULL COMMENT 'link to the agreement',
     `license_id` INT(11) NULL COMMENT 'link to the license',
     `user_id` INT(11) NOT NULL COMMENT 'link to the user',
     `role` VARCHAR(80) NOT NULL COMMENT 'role of the user',
     CONSTRAINT `erm_user_roles_ibfk_1` FOREIGN KEY (`agreement_id`) REFERENCES `erm_agreements` (`agreement_id`) ON DELETE CASCADE ON UPDATE CASCADE,
     CONSTRAINT `erm_user_roles_ibfk_2` FOREIGN KEY (`license_id`) REFERENCES `erm_licenses` (`license_id`) ON DELETE CASCADE ON UPDATE CASCADE,
-    CONSTRAINT `erm_user_roles_ibfk_3` FOREIGN KEY (`user_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
+    CONSTRAINT `erm_user_roles_ibfk_3` FOREIGN KEY (`user_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
+    PRIMARY KEY(`user_role_id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 
 --